Realistic Landscape Creation Tool |
What is Wing? | How do I use Wing? | Download | Join Wing | Help | Suggestions |
Your Position: Join Wing -> How to: Write source code for wing -> Coding Standard Coding Standard1. C and C++ standardWing strives for maximal compatibility between various platforms. To acchieve this, wing conforms to most widely supported C & C++ standards. For C language standard, we follow C89 (as known as C90 or ISO/IEC 9899:1990). For C++ language standard, we follow C++ 98 (as known as ISO/IEC 14882:1998). Due to the limitation of language standard and the incomplete support of standards, some compaibility issues should pay attention to:
2. Open-source project conventionsWe try to follow conventions of open-source projects. The GNU coding standard explains those conventions in detail. 3. Wing-specific standardWe also have a little bit of our own standard to make the code more readable. 3.1 File HeaderAny source file, script, bat of wing should contain the following file header: /* Copyright (C) 2008-2009 Wing Project Wing home page: <http://wing-007.sourceforge.net/> Wing is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation. History: #Month/#Day/#Year Author: #Author name */ 3.2 FunctionFunctions should be verbal phrases. The first letter of each word should be written in upper case. Eg. void SetValue(int i); bool Optimize(); int SendMessage(int parameter); 3.3 Class and StructsClasses and structs should be noun phrases. The first letter of each word should be written in upper case. Usually we don't add a 'C' before the class name, but that is not mandatory. Eg. class AsciiString; class String; class Bitfields; class Matrix44; class Vector3; 3.4 InterfaceInterface is a kind of class which is directly derived from wing::Interface. It provide pure virtual functions as a "protocol". Each interface should have a static function named IID() which returns a global unique ID for that interface. Interfaces should be noun phrases. It should starts with "I" and the first letter of each word should be written in upper case. Eg. class IBinarySeekable : public Interface { public: static inline InterfaceID IID() { return InterfaceID(0xe0d08920, 0xe0d03b7c); } }; 3.5 VariablesAll variables should be noun phrases and starts with a letter in lower case. Member variables should starts with 'm', global variables should starts with 'g', static variables should starts with 's', static member variables should starts with 'sm'. Eg. extern int gNumber; void function() { static int sNumber; int number; } class TestClass { public: static int smNumber; int mNumber; }; 3.6 NamespaceAll classes, structs, variables and functions that will be exposed to SDK should be wrapped in namespace wing. You can use WING_BEGIN at the beginning of the header file and use WING_END at the end of the header file. The definitions of WING_BEGIN and WING_END are: #define WING_BEGIN namespace wing { #define WING_END } 3.7 Header GuardWe try to avoid using visual studio directives such as #pragma once. The header guard of wing should be written in upper case. Eg. #ifndef BUILD_SYSTEM_2008_02_23_H #define BUILD_SYSTEM_2008_02_23_H #endif // #ifndef BUILD_SYSTEM_2008_02_23_H |
If you have any questions, please send a mail to renqilin at users.sourceforge.net |