-
Notifications
You must be signed in to change notification settings - Fork 283
coding style guideline
Fabien Spindler edited this page Sep 14, 2016
·
6 revisions
- Each class has its own header and implementation file
- A template class has only a header file
- C++ interface headers have
.h
extension - Implementation files have
.cpp
extension
- Class names start with a vp prefix, then each name star with a uppercase letter. Underscores are not allowed; ie
vpMyNewClass
- Macros and enumeration constants are written with all capital letters. Words are separated by underscore.
- All external functions and classes must use
VISP_EXPORT
, otherwise there will be linking errors on Windows. - Member or static functions start with a lowercase, then next words with an uppercase; ie
vpMyNewClass::myNewMethod()
.
The documentation is written in doxygen style. Use the existing documentation as example. Normally, each function/method description includes:
- a short description
- all the parameters explained; e.g. specify, which image types are accepted, what would be the recommended values for the parameter and how they affect the algorithm etc.
- the full description with short use samples, references to papers, formulas, etc
Every source file starts with GPL-v2 license. Use existing code to get the template.
Other rules for both header and implementation files include:
- Code lines should not be very long. Normally, they should be limited to 100 characters.
- No tabulation should be used. Set your editor to use spaces instead.
- Only English text is allowed. Do not put comments or string literals in other languages.
- Indentation is 2 spaces.
- Header files must use guarding macros, protecting the files from repeated inclusion:
#ifndef __vpMyNewClass_h_
#define __vpMyNewClass_h_
...
#endif
Currently used in ViSP and recommended formatting style looks as follows:
if (B <= A) {
throw (vpImageException(vpImageException::incorrectInitializationError, "Bad gray levels")) ;
}
unsigned char v;
double factor = (double)(B_star - A_star)/(double)(B - A);
for (unsigned int i=0 ; i < I.getHeight(); i++) {
for (unsigned int j=0 ; j < I.getWidth(); j++) {
v = I[i][j];
if (v <= A)
I[i][j] = A_star;
else if (v >= B)
I[i][j] = B_star;
else
I[i][j] = (unsigned char)(A_star + factor*(v-A));
}
}