-
Notifications
You must be signed in to change notification settings - Fork 16
Coding Guidelines
There should be as few includes as possible in a header file (ideally none). You only need to include a header file here if you:
- Derive from a class/struct
- Use a class/struct as member (but not if you are only using a pointer, reference or smart pointer to that class!)
In all other cases (e.g. when declaring a pointer to a class member), forward-declare any referenced classes!
Example header file:
#include "BaseClass.h"
#include "Member.h"
#include "MySmartPointer.h"
// forward-declarations
class Type1;
class Type2;
class Type3;
class Type4;
class TestIncludes: public BaseClass // BaseClass.h needs to be included
{
Type1* a; // fwd-declaration of PointerType is enough!
MySmartPointer<Type2> b; // MySmartPointer needs to be included, but Type2 only fwd-declared!
Member c; // directly using class Member as member, so we also need to include
void testMethod(Type3 foo, Type4 & bar); // Type3 and Type4 only need to be fwd-declared
};
In the cpp file, includes should be sorted from application-specific to the most generic headers (typically STL), in order of dependency (http://stackoverflow.com/questions/2762568/c-c-include-file-order-best-practices). The ideal order for our application code therefore is:
- header file for this .cpp file
- header files from the same module
- header files from the core
- library headers: ** itk ** vtk ** Qt ** STL & system/platform-specific includes
Since all supported compilers (Visual C++, g++) support it, the simpler #pragma once
should be used.
Enable by marking openiA_USE_COTIRE in CMake. This will enable precompiled headers through the COmpile TIme REduction library for CMake. However, in our experiments, it only slightly decreases the build time, but significantly increases the binary directory size.
Rule of Thumb: Use ITK images whenever possible (rationale: I/O is much faster, more processing filters available). Only when you need to show an image, convert it to vtkImageData using an iAConnector.
Use helper methods in iAITKIO.h
and iATypedCallHelper.h
to make filters applicable for multiple different image types.
open_iA Documentation, licensed under CC BY-NC-SA 4.0