forked from szledan/gepard
-
Notifications
You must be signed in to change notification settings - Fork 6
Coding style
Szilard Ledan edited this page Jun 26, 2016
·
7 revisions
gepard-<spec-name>.h/cpp
The gepard-example.h
:
/* TODO: Include contents of ./LICENSE
* and update the contributors.
*/
#ifndef GEPARD_EXAMPLE_H
#define GEPARD_EXAMPLE_H
namespace gepard {
namespace example {
namespace {
...
} // anonymous
} // namespace example
} // namespace gepard
#endif // GEPARD_EXAMPLE_H
The gepard-example.cpp
:
/* TODO: Include contents of ./LICENSE
* and update the contributors.
*/
#include "config.h"
#include "gepard-example.h"
#include "other-header.h"
#include <system-header.h>
class FloatPoint {
public:
FloatPoint(Float x, Float y)
: x(x)
, y(y)
{}
double modulus() const
{
return sqrt(this->x * this->x + this->y * this->y);
}
double length() const { return _length; }
double area() const;
double x;
double y;
protected:
double _length;
private:
double _area;
};
In case of one line early return:
if (cond)
return value;
// or
if (cond) {
return value;
}
If there is an else
case, then always use brackets ({...}
):
if (cond) {
...
} else {
...
}
switch (cond) {
case 1:
case 2:
...
break;
case 3:
...
// Fall through.
case 4: {
...
break;
}
default:
...
break;
}
for (int i = 0; i < n; i++) {
...
}
for (auto& element : container) {
...
}
while (cond) {
...
}
do {
...
} while (cond);
static inline double min(double& a, double& b) const
{
...
}
double FloatPoint::area()
{
...
}
Please use GD_
(GeparD) prefix for every own defines.
#ifdef GD_CRASH
#undef GD_CRASH
#endif
#define GD_CRASH(ARG) ...