-
Notifications
You must be signed in to change notification settings - Fork 22
Coding Standards File Structure
The following rules apply when defining file structure.
Organizing files into folder that are a logical grouping (namespace or function) makes the file system easier to navigate.
If a file is intended to be used in both the client and server in the EXACT same way that it should be placed in the common folder. If there needs to be a specialized implementation for client or server then it should be placed in that respective folder.
Source files must be explicitly added to the corresponding CMakeLists.txt file to be included in the compilation
Header files are used to forward declare concepts that are later defined in a source file. Header files use the .hpp
extension to denote a c++ header.
Header files need to have some form of include guard to prevent multiple declarations. Most compilers these days understand #pragma once
and as such this is the preferred include guard mechanism. By using this single line it removes the need to create a unique simple for an ifdef
and prevents error from forgetting to include the ending endif
, and it is less typing for an added bonus.
Unless the header is strictly used to define a class, we recommend putting a header comment block, under the #pragma once
, that in brief describes the purpose of the header. Headers that define a class have this documentation already above the class declaration.
/**
* \brief Module that handles the neutrons in the dilithium chamber
* \file Neutrons.hpp
*
*/
All c++ source uses the .cpp
extension.
Includes should be placed as close the the usage as possible. For example, don't include a class header in another header if that header only makes a reference to it via a pointer. Instead use a forward declaration and then include the corresponding header in the source file.
For included files that contains constants/data tables (Carmack's trick), we recommend using extension .inc
and add a comment explaining the contents of the included file.