= Coding Standard for C++ in OpenBTS = Do not violate one of these rules unless you are sure that you understand the rationale behind the rule and are sure that you have a legitimate exception to that rationale. The "owner" of OpenBTS and its related applcations is the CTO of Range Networks, Inc. All public and private releases must ultimately be approved by this CTO. ''This document uses trac-style wiki formatting.'' == Libraries, Licenses and Portability == '''All new library dependencies must be approvaed by the Range Networks CTO before being added to the system.''' === POSIX === Ideally, OpenBTS and its related applications should compile and run on any POSIX system. At a minimum, we expect these applications to be portable to any current-release Linux or BSD system. Any portability failure for current-release Linux or BSD distribution is considered to be a bug. === Licenses === OpenBTS and its related applications are distributed publicly under AGPLv3 and privately under other licenses. Do not use any GPL library for which a non-GPL license cannot be acquired. Any LGPL libraries must be linked dynamically or licensed under other terms. If you add a new library to the system, please update the LEGAL file with with appropriate licensing information. === Libraries and Portbility === Just because you ''can'' use a library for a task does not mean you ''should''. The difficulty of porting an application to a new platform is a direct function of the number of library dependencies it has, so if you can write handful of simple functions to take the place of a new external library, please do so. OpenBTS, in the long run, is intended to be a highly portable embedded application. We cannot tollerate a "kitchen sink" dependency list, requiring developers to download the entire internet before starting a build. == Symbol Names == === Name Formats === Symbol names should be formatted so that a reader can determine the scope of a symbol from the format of the name. C++ symbol names are to use camel case (camelCase). Do not use underscores except in #define marcos. Capitalization rules: * Local scope variables and member methods start with a lower case letter. * Class names and type names start with an upper case letter. * #define marcos are all-caps and underscores are allowed. Prefixes: * Class instance variables are prefixed with "m". * Static valiables are prefixed with "s". * Global variables are prefixed with "g". * Arguments to constructors and assignment accessors, when given the same name as the assigned instance variable, are prefixed with "w". Example: {{{ bool gSomeGlobalFlag; #define DEFAULT_TAG 5 class ThisClass { private: int mValue; int mTag; static const int msDefaultTag = DEFAULT_TAG; static int msClassCounter = 0; public: ThisClass(int wTag = gsDefaultTag) :mTag(wTag) { } int value() const { return mValue; } void value(wValue) { mValue = wValue; } int tag() const { return mTag; } }; }}} === Names from the Specificaitons === When a variable name is taken from the GSM or ITU specicaitons, it sould follow the form in the specifications as closely as possible (substituting "_" for "-", for example). This rule overrides the formating guidelines given above. == Text Formatting == === Tabs and Spaces === Use tabs for indentation and for comment alignment. Set your editor to display the tab width you like. === Curly Braces === Place curly braces according to the following examples: {{{ if (test) { action(); } if (test) { action(); } else { otherAction(); } while (condition) { action(); } void function(void) { doStuff(); do moreStuff(); } /** An example class to show some formatting. */ class ThisClass : public ThatClass { protected: int mValue; ///< an example instance variable /** An initialization function called by the constructor. */ void initStuff(); public: /** Construct a ThisClass object. @param wValue The initial value for mValue */ ThisClass(wValue) :ThatClass() { initStuff(); } void bigFunction(void); ///< bigFunction defined in .cpp file /** Short one-liner can be defined right here. */ void shortFunction(void) { doItHere(); } }; }}} == Scoping == Generally speaking, anything you declare should be declared in the smallest possible scope. === Local Variables === Like anything else, local variables should be defined in the smallest possible scope. For example, this: {{{ int sum = 0; for (int i=0; i