-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathcoding_style.txt
184 lines (137 loc) · 4.39 KB
/
coding_style.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
1 ALLOSYSTEM CODING STYLE
=========================
1.1 File Naming
---------------
For C++:
al_[CamelCase].hpp
al_[CamelCase].cpp
For C:
al_[CamelCase].h
al_[CamelCase].c
1.2 Header Files
----------------
All header content should be contained within a preprocessor conditional block to avoid multiple include errors.
#ifndef INCLUDE_AL_[FILE_STEM]_[FILE_EXT (H or HPP)]
#define INCLUDE_AL_[FILE_STEM]_[FILE_EXT (H or HPP)]
[source code...]
#endif
Please do not use '#pragma once' as this is non-standard.
A comment at the beginning of the file should include:
a. The license in its entirety
b. A description of the file
c. The primary author(s) of the file
d. If possible, example usage code
1.3 Whitespace
--------------
Indentation should be done using tabs. Make sure your editor does not replace tabs with spaces.
Make sure your editor uses Unix-like line endings "\n". This is especially relevant on Windows where many editors use "\r\n" by default.
1.4 Macros
----------
Minimize use of macros as they always have global scope. Do not use macros to define constants or functions.
Instead of
#define MIN(x,y) (x < y : x ? y)
use
template<typename T>
inline T min(const T x, const T y) {
return (x < y : x ? y);
}
1.5 Naming conventions
----------------------
- Macros should be all uppercase with words separated by underscores, e.g. AL_NSEC_FMT.
- enum constants should be all uppercase.
C++ only:
- Variable members in classes should be prefixed by 'm'. e.g. mSize.
- Everything should be defined within the namespace al::.
C only:
- Function names should be prefixed with 'al_'.
1.7 C++isms
-----------
Use references instead of pointers in public interfaces. A reference cannot be NULL unlike a pointer and therefore catches many run-time errors. For example, instead of passing a pointer
void foo(Object * obj);
use a reference
void foo(Object& obj);
In example code, avoid dynamic memory allocation using new and delete. Instead of
Object * obj = new Object;
// code using obj
delete obj;
prefer
Object obj;
// code using obj
For more information on how to not use pointers in modern C++ see
klmr.me/slides/modern-cpp/
1.6 Class design
----------------
- Include a default constructor whenever possible.
- Avoid dynamic memory allocation or resource acquisition (opening files, etc.) in constructors.
- Place implementation code into a separate .cpp file. This make headers easier to read and speeds up compilation time for users of the library. You may, however, place the implementation in the header file for inlined functions (small, frequently-called functions) or templated functions.
1.8 Dependencies
----------------
Try to keep the amount of code dependencies at a minimum, both internally and with regards to third-party libraries.
For example:
- Only #include headers that you are actually using functionality from in a particular file. Always try to move header includes to the implementation (.cpp) file, especially those from third-party libraries.
- If you only need a small amount of functionality from another header file or library with a large code base, consider just rewriting the functionality you need and avoiding the dependency.
- Check that what you need is not already in the C++ standard.
2 LIBRARY ORGANIZATION
======================
allocore
math
complex number
quaternion
n-vector
n x n matrix
'special' and other functions
interpolation functions
random functions
interval
geometric: frustum, plane, ray, spherical
spatial
pose
hashspace
distance attenuation
Frenet frame
system
thread/mutex (*APR)
timing (*clock, *sleep)
memory mgmt.
main loop (GLUT)
types
priority queue (sorted FIFO)
tube (single RW, lock-free FIFO)
array (multidimensional, dynamic typed)
buffer (like std::vector)
color
voxels
conversion: bit twiddling, to string, etc.
io
audio driver (device, streams)
GL window, mouse, keyboard (GLUT)
sockets (**APR)
file, directory (**APR)
bluetooth
serial
graphics
render: OpenGL, texture, shader, FBO, light, lens, stereographic
mesh
isosurface
shapes
assets (assimp)
image file (freeimage)
font (freetype)
sound
audio scene
speaker
ambisonics
DBAP
VBAP
reverb
filters: biquad, crossover
protocol
OSC (oscpack)
serialize
zero conf
allocv
video capture (OpenCV)
external
sound file (libsndfile via Gamma)
* Consider porting to C++11
** Consider porting to C++17