|
| 1 | + |
| 2 | +# Guide for contributors |
| 3 | +Here's you can find some documentations and guidelines to contribute to the source code. |
| 4 | + |
| 5 | +#============================================================== |
| 6 | +# Git |
| 7 | + |
| 8 | +### GitHub commit convetion |
| 9 | +All commits need to be labeled with a tag among these: |
| 10 | +``` |
| 11 | +git commit -m "ADD:<description>" <--- for adding new elements |
| 12 | +git commit -m "FIX:<description>" <--- for fixing (errors, typos) |
| 13 | +git commit -m "FLASH:<description>" <--- quick checkpoint before refactoring |
| 14 | +git commit -m "MILESTONE:<description>" <--- for capping moment in development |
| 15 | +git commit -m "CAP:<description>" <--- for for less important milestones |
| 16 | +git commit -m "UPDATE:<description>" <--- for moddification to the same file |
| 17 | +git commit -m "MISC:<description>" <--- for any other reasons to be described |
| 18 | +git commit -m "WIP:<description>" <--- for not finished work |
| 19 | +git commit -m "REFACTOR:<description>" <--- for refactored code |
| 20 | +git commit -m "MERGE:<description>" <--- for merging operations |
| 21 | +``` |
| 22 | +You can merge few tags e.g.: |
| 23 | +``` |
| 24 | +git commit -m "WIP-CAP:<description> <--- for cap moment in not finished work |
| 25 | +``` |
| 26 | + |
| 27 | +#============================================================== |
| 28 | +# C++ |
| 29 | + |
| 30 | +### Naming & synthax convention |
| 31 | +Here's the naming convention for this project: |
| 32 | +- `localVariable`: lowerCamelCase. |
| 33 | +- `type PrivateVariable`: public member of a class |
| 34 | +- `type m_PrivateVariable`: Hungarian notation with UpperCamelCase for private class members. |
| 35 | +- `static type s_StaticVariable`: Hungarian notation with UpperCamelCase for static members of class. |
| 36 | +- `APP_SPEC`: Constants with SNAKE_UPPER_CASE. |
| 37 | +- All the other naming uses UpperCamelCase. |
| 38 | + |
| 39 | +Here's an example: |
| 40 | +```c++ |
| 41 | +// do not use using namespace std; we specify the namespace everytime |
| 42 | +std::foo() |
| 43 | + |
| 44 | +// next line graph style |
| 45 | +void Foo() |
| 46 | +{ |
| 47 | + /* content */ |
| 48 | +} |
| 49 | + |
| 50 | +// structure name uses UpperCamelCase |
| 51 | +struct AnExampleStruct |
| 52 | +{ |
| 53 | + // structure attribute uses UpperCamelCase |
| 54 | + const char* Name; |
| 55 | +}; |
| 56 | + |
| 57 | +// class name uses UpperCamelCase |
| 58 | +class AnExampleClass |
| 59 | +{ |
| 60 | +public: |
| 61 | + AnExampleClass(const int& init); |
| 62 | + virtual ~AnExampleClass(); |
| 63 | + |
| 64 | + // member functions use UpperCamelCase |
| 65 | + void PublicMemberFunction() |
| 66 | + { |
| 67 | + // local variable uses lowerCamelCase |
| 68 | + int localVariable = 0; |
| 69 | + } |
| 70 | + |
| 71 | +// A field indicator to separate the functions and attributes |
| 72 | +public: |
| 73 | + int PublicVariable; |
| 74 | + |
| 75 | +// Private member function block |
| 76 | +private: |
| 77 | + // member functions use UpperCamelCase |
| 78 | + void PrivateMemberFunction(); |
| 79 | + |
| 80 | +// Also a field indicator to separate the functions and attributes |
| 81 | +private: |
| 82 | + // private variables uses Hungarian notation with UpperCamelCase |
| 83 | + int m_PrivateVariable; // m_VariableName for normal variable |
| 84 | + static int s_Instance; // s_VariableName for static variable |
| 85 | +}; |
| 86 | + |
| 87 | +// Start headers with |
| 88 | +#pragma once |
| 89 | + |
| 90 | +// Start declarations with precompiled headers |
| 91 | +#include "aiacpch.h" |
| 92 | +``` |
| 93 | + |
| 94 | +### Doxygen |
| 95 | +For documentation we use the [*JavaDoc" convention](https://doxygen.nl/manual/docblocks.html). |
| 96 | +Follow [this guide for documenting the code](https://developer.lsst.io/cpp/api-docs.html). |
| 97 | +```c++ |
| 98 | +/** |
| 99 | + * @brief fill a vector of TSPlanes from a yaml file containing their corners data |
| 100 | + * @param filename path to the map.yaml file |
| 101 | + * @param planes vector of TSPlane objects |
| 102 | + */ |
| 103 | +``` |
| 104 | + |
| 105 | + |
| 106 | +### Pre-Compiled headers |
| 107 | +AC uses a precompile header `aiacpch.h` to the project to shorten compilation time for headers that you rarely modify such as stdb library, opencv etc.. Add to `aiacpch.h` every big header you do not use often. |
| 108 | +Include at the very top `#include "aiacpch.h"` of every `.cpp` file. |
| 109 | + |
| 110 | + |
| 111 | +### Logging |
| 112 | +To log use the following MACROS. All the code is contained in `Log.hpp` and `Log.cpp`. |
| 113 | +```c++ |
| 114 | +AIAC_INFO("test_core_info"); |
| 115 | +AIAC_WARN("test_core_warn"); |
| 116 | +AIAC_CRITICAL("test_core_critical"); |
| 117 | +AIAC_DEBUG("test_core_debug"); |
| 118 | +AIAC_ERROR("test_core_error"); |
| 119 | +``` |
| 120 | +The output is like so: |
| 121 | +```bash |
| 122 | +[source main.cpp] [function main] [line 32] [16:30:05] APP: test |
| 123 | +``` |
| 124 | +The logging can be silenced by setting OFF the option in the main `CMakeLists.txt` and do clean reconfiguration. |
| 125 | +```cmake |
| 126 | +option(SILENT_LOGGING "Do not log messages in the terminal of on." ON) |
| 127 | +``` |
| 128 | + |
| 129 | +### CTesting |
| 130 | +When necessary, c++ testing is done by using CTest. Important/critical features (e.g., correcting functioning of graphics with OpenGL and Glfw) needs testing to be written (this is usefull for e.g., GitHub Actions). Such tests can be extracted from the main source code and integrated in a seperate section: cmake testing. |
| 131 | + |
| 132 | +To add a new test do as follow. |
| 133 | + |
| 134 | +First create a new sub-folder in the folder `./test` as `./test/exampletest`. |
| 135 | +Here add a console cpp file called `tester.cpp` which returns 0 or 1 and add a new `CMakeLists.txt` as such: |
| 136 | +```cmake |
| 137 | +add_executable(example_test tester.cpp) |
| 138 | +
|
| 139 | +/* <-- |
| 140 | +Insert here linking necessary for the executable |
| 141 | +Note that if you already found packages in the head CMakeLists file |
| 142 | +you can simply use the macros here. |
| 143 | +--> */ |
| 144 | +
|
| 145 | +add_test(NAME "ExampleTest" COMMAND "example_test" <argv-here> WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") |
| 146 | +``` |
| 147 | +In the `./test`'s `CMakeLists.txt` add the created sub-directory: |
| 148 | +```cmake |
| 149 | +if (TEST_EXAMPLE) |
| 150 | + add_subdirectory(exampletest) |
| 151 | +endif() |
| 152 | +``` |
| 153 | +Finally add an option in the main `CMakeLists.txt` describing the test: |
| 154 | +```cmake |
| 155 | +include(CTest) |
| 156 | +# ... |
| 157 | +option(TEST_EXAMPLE "Test to test something important." ON) |
| 158 | +# ... |
| 159 | +if(TEST_EXAMPLE) |
| 160 | + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests/exampletest) |
| 161 | +endif() |
| 162 | +``` |
| 163 | + |
| 164 | +Next, `./configure.sh -c` and `./build.sh` and: |
| 165 | +```bash |
| 166 | +cd ./build |
| 167 | +ctest -N # <--- to see how many tests there are |
| 168 | +ctest -V # <--- run the tests |
| 169 | +``` |
0 commit comments