-
Notifications
You must be signed in to change notification settings - Fork 18
Coding Style
bioboy edited this page Nov 4, 2012
·
8 revisions
No use of C++11 features only available in version of gcc higher than 4.6 as listed at: GCC C++11 Support
All namespaces should also have a corresponding directory under src/. The util namespace is reserved for code the is deemed reusable, and not necessarily specific to this project.
- .hpp extension for header files
- .cpp extension for source / implementation files
Use forward declarations, include headers in implementation only where possible. When including project specific headers use the full path relative to the root of the source tree and include non project specific headers first as per the example below:
#include <sstream>
#include <string>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/case_conv.hpp>
#include "cmd/site/chmod.hpp"
#include "fs/chmod.hpp"
#include "fs/dircontainer.hpp"
#include "util/string.hpp"
#include "cfg/get.hpp"
#ifndef __<NAMESPACE1>_<NAMESPACE..>_<NAME>_HPP
#define __<NAMESPACE1>_<NAMESPACE..>_<NAME>_HPP
...
#endif
#ifdef <NAMESPACE1>_<NAMESPACE..>_<NAME>_TEST
...
#endif
class MyClass
{
std::string something;
std::string somethingElse; // camelCase with first letter lower
public:
std::string Foo(int args, const std::string& here);
const std::string& Something() const { return something; }
const std::string& SomethingElse() const { return somethingElse; }
};
std::string Foo(int args, std::string here)
{
if (expr) DoSomething();
else SomethingElse();
if (expr)
{
Multiple();
Statements();
}
else
SomethingElse();
while (expr)
{
Statement();
}
// same for for, do loops
switch (var)
{
case constant:
Wow();
break;
default:
{
Uhoh();
break;
}
}
}