author | Tom Henderson <tomh@tomh.org> |
Fri, 18 May 2007 10:27:42 -0700 | |
changeset 657 | be551a3b07c6 |
permissions | -rw-r--r-- |
657
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
1 |
The Ns-3 Coding Style |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
2 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
3 |
/* |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
4 |
* Note: This file is incomplete and will be converted to non-text (html,pdf) |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
5 |
* formats at a future date |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
6 |
*/ |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
7 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
8 |
1) Code layout |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
9 |
----------- |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
10 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
11 |
The code layout follows the GNU coding standard layout for C and extends |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
12 |
it to C++. Do not use tabs for indentation. Indentation spacing is 2 |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
13 |
spaces as outlined below: |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
14 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
15 |
void |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
16 |
Foo (void) |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
17 |
{ |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
18 |
if (test) |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
19 |
{ |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
20 |
// do stuff here |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
21 |
} |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
22 |
else |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
23 |
{ |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
24 |
// do other stuff here |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
25 |
} |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
26 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
27 |
for (int i = 0; i < 100; i++) |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
28 |
{ |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
29 |
// do loop |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
30 |
} |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
31 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
32 |
while (test) |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
33 |
{ |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
34 |
// do while |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
35 |
} |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
36 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
37 |
do |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
38 |
{ |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
39 |
// do stuff |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
40 |
} while (); |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
41 |
} |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
42 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
43 |
The following is not recommended: |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
44 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
45 |
if (test) statement |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
46 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
47 |
if (test) |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
48 |
statement |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
49 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
50 |
for (...) statement |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
51 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
52 |
Each statement should be put on a separate line to increase readability. |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
53 |
Short one-line comments can use the C++ comment style, that is, '//' |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
54 |
but longer comments should use C-style comments: |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
55 |
/* |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
56 |
* |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
57 |
* |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
58 |
*/ |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
59 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
60 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
61 |
2) Naming Patterns |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
62 |
--------------- |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
63 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
64 |
2.1) Name encoding |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
65 |
------------- |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
66 |
Function, Method, and Type names should follow the CamelCase convention: |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
67 |
words are joined without spaces and are capitalized. For example, |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
68 |
"my computer" is transformed into MyComputer. Do not use all capital |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
69 |
letters such as MAC or, PHY, but choose instead Mac or Phy. Do not use |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
70 |
all capital letters, even for acronyms such as EDCA: use Edca instead. |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
71 |
The goal of the CamelCase convention is to ensure that the words which |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
72 |
make up a name can be separated by the eye: the initial Caps fills |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
73 |
that role. |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
74 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
75 |
Variable names should follow a slight variation on the base CamelCase |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
76 |
convention: camelBack. For example, the variable "user name" would be |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
77 |
named "userName". This variation on the basic naming pattern is used to |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
78 |
allow a reader to distinguish a variable name from its type. For example, |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
79 |
"UserName userName;" would be used to declare a variable named userName |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
80 |
of type UserName. |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
81 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
82 |
Global variables should be prefixed with a "g_" and member variables |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
83 |
(including static member variables) should be prefixed with a "m_". The |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
84 |
goal of that prefix is to give a reader a sense of where a variable of |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
85 |
a given name is declared to allow the reader to locate the variable |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
86 |
declaration and infer the variable type from that declaration. For example |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
87 |
you could declare in your class header my-class.h: |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
88 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
89 |
class MyClass |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
90 |
{ |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
91 |
void MyMethod (int aVar); |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
92 |
int m_aVar; |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
93 |
static int m_anotherVar; |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
94 |
}; |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
95 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
96 |
and implement in your class file my-class.cc: |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
97 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
98 |
int MyClass::m_anotherVar = 10; |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
99 |
static int g_aStaticVar = 100; |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
100 |
int g_aGlobalVar = 1000; |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
101 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
102 |
void |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
103 |
MyClass::MyMethod (int aVar) |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
104 |
{ |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
105 |
m_aVar = aVar; |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
106 |
} |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
107 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
108 |
2.2) Choosing names |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
109 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
110 |
Variable, function, method, and type names should be based on the |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
111 |
english language. Furthermore, always try to choose descriptive |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
112 |
names for them. Types are often english names such as: Packet, |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
113 |
Buffer, Mac, or Phy. Functions and Methods are often named |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
114 |
based on verbs and adjectives: GetX, DoDispose, ClearArray, etc. |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
115 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
116 |
A long descriptive name which requires a lot of typing is always |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
117 |
better than a short name which is hard to decipher. Do not use |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
118 |
abbreviations in names unless the abbreviation is really unambiguous |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
119 |
and obvious to everyone. Do not use short inapropriate names such |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
120 |
as foo, bar, or baz. The name of an item should always match its |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
121 |
purpose. As such, names such as tmp to identify a temporary |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
122 |
variable or such as 'i' to identify a loop index are ok. |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
123 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
124 |
3) File layout and code organization |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
125 |
--------------------------------- |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
126 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
127 |
A class named MyClass should be declared in a header named my-class.h |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
128 |
and implemented in a source file named my-class.cc. The goal of this |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
129 |
naming pattern is to allow a reader to quickly navigate through |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
130 |
the ns-3 codebase to locate the source file relevant to a specific |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
131 |
type. |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
132 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
133 |
Each my-class.h header should start with the following comments: the |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
134 |
first line ensures that developers who use the emacs editor will be |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
135 |
able to indent your code correctly. The following lines ensure that |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
136 |
your code is licensed under the GPL, that the copyright holders |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
137 |
are properly identified (typically, you or your employer), and |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
138 |
that the actual author of the code is identified. The latter is |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
139 |
purely informational and we use it to try to track the most |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
140 |
appropriate person to review a patch or fix a bug. |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
141 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
142 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
143 |
/* |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
144 |
* Copyright (c) YEAR COPYRIGHTHOLDER |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
145 |
* |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
146 |
* 3-paragran GPL blurb |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
147 |
* |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
148 |
* Author: MyName <myemail@foo.com> |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
149 |
*/ |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
150 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
151 |
Below these C-style comments, always include the following which |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
152 |
defines a set of header guards (MY_CLASS_H) used to avoid multiple |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
153 |
header includes, which ensures that your code is included |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
154 |
in the "ns3" namespace and which provides a set of doxygen comments |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
155 |
for the public part of your class API. Detailed information |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
156 |
on the set of tags available for doxygen documentation is described |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
157 |
in the doxygen website: http://www.doxygen.org. |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
158 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
159 |
#ifndef MY_CLASS_H |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
160 |
#define MY_CLASS_H |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
161 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
162 |
namespace n3 { |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
163 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
164 |
/** |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
165 |
* \brief short one-line description of the purpose of your class |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
166 |
* |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
167 |
* A longer description of the purpose of your class after a blank |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
168 |
* empty line. |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
169 |
*/ |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
170 |
class MyClass |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
171 |
{ |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
172 |
public: |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
173 |
MyClass (); |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
174 |
/** |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
175 |
* \param firstParam a short description of the purpose of this parameter |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
176 |
* \returns a short description of what is returned from this function. |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
177 |
* |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
178 |
* A detailed description of the purpose of the method. |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
179 |
*/ |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
180 |
int DoFoo (int firstParam); |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
181 |
private: |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
182 |
void MyPrivateMethod (void); |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
183 |
int m_myPrivateMemberVariable; |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
184 |
}; |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
185 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
186 |
} // namespace ns3 |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
187 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
188 |
#endif /* MY_CLASS_H */ |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
189 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
190 |
The my-class.cc file is structured similarly: |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
191 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
192 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
193 |
/* |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
194 |
* Copyright (c) YEAR COPYRIGHTHOLDER |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
195 |
* |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
196 |
* 3-paragran GPL blurb |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
197 |
* |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
198 |
* Author: MyName <myemail@foo.com> |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
199 |
*/ |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
200 |
#include "my-class.h" |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
201 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
202 |
namespace ns3 { |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
203 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
204 |
MyClass::MyClass () |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
205 |
{} |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
206 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
207 |
... |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
208 |
|
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
209 |
} // namespace ns3 |
be551a3b07c6
minor changes due to documentation review
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
210 |