Skip to content

Commit 48ab991

Browse files
committed
2 parents b14fb5b + 79adc48 commit 48ab991

File tree

1 file changed

+42
-57
lines changed

1 file changed

+42
-57
lines changed

README.md

+42-57
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,39 @@ Classes use upper CamelCase with a strong preference for a single word. Namespac
1212

1313
### File and Directory Names
1414

15-
File names follow the class names and namespace names with hpp appended to header files and cpp appended to C++ source files. Namespaces have their own directories which contain the header files of all the classes in the namespace. The namespaces include a header file that includes the classes uses the namespace. See this example:
16-
17-
/*! \brief Standard Calculation and Software Routines
18-
*
19-
*/
20-
namespace calc {}
21-
#include "calc/Base64.hpp"
22-
#include "calc/Ema.hpp"
23-
#include "calc/Lookup.hpp"
24-
#include "calc/Pid.hpp"
25-
#include "calc/Rle.hpp"
26-
27-
using namespace calc;
28-
29-
In an application, #include <stfy/calc.hpp> will allow you to declare Pid objects without using calc::Pid. If you don't want to use the namespace, just #include <stfy/calc/Ema.hpp> instead. All library headers (including those in Stratify Lib) should use this approach and should never include a namespace header (or use a namespace) in any header file other than the namespace's hpp file.
15+
File names follow the class names and namespace names with hpp appended to header files and cpp appended to C++ source files. Namespaces have their own directories which contain the header files of all the classes in the namespace. The namespaces include a header file named after the namespace which includes all classes and declares 'using namespace <namespace>'.
16+
17+
```c++
18+
/*! \brief Standard Calculation and Software Routines
19+
*
20+
*/
21+
namespace calc {}
22+
#include "calc/Base64.hpp"
23+
#include "calc/Ema.hpp"
24+
#include "calc/Lookup.hpp"
25+
#include "calc/Pid.hpp"
26+
#include "calc/Rle.hpp"
27+
28+
using namespace calc;
29+
```
30+
31+
In an application, #include <sapi/calc.hpp> will allow you to declare Pid objects without using calc::Pid. If you don't want to use the namespace (that is you need to avoid scope conflicts), just #include <sapi/calc/Pid.hpp> instead. All library headers (including those in Stratify API) should use this approach and should never include a namespace header (or 'using namespace') in any header file other than the namespace's hpp file. The application developer can then decide to include <sapi/calc.hpp> or the individual classes <sapi/calc/Pid.hpp>.
3032
3133
### Methods and Functions
3234
3335
Methods and functions follow traditional C and C++ naming styles with lowercase and underscores to separate words. Methods and functions should start with a verb except when directly accessing a variable.
3436
35-
Class Object {
36-
public:
37-
int amount(){ return m_amount; } //this just returns the amount
38-
int set_amount(int v){ m_amount = v; } //this sets the value of amount
39-
int calc_amount(); //this is an action that does something
40-
int get_amount(); //since this starts with a verb it needs to do something--like load amount from a file
41-
private:
42-
int m_amount; //member variables have an m_ prefix
43-
}
37+
```c++
38+
Class Object {
39+
public:
40+
int amount() const { return m_amount; } //this just returns the amount (no calculating no fetching)
41+
int set_amount(int v){ m_amount = v; } //this sets the value of amount
42+
int calc_amount() const; //this is an action that does something- "calc" is commonly used to denote a calculation
43+
int get_amount() const; //since this starts with a verb it needs to do something--like load amount from a file
44+
private:
45+
int m_amount; //member variables have an m_ prefix
46+
}
47+
```
4448

4549
The above code uses set_* and get_* but not perhaps in the traditional way. If get_ is used, it implies the value is not immediately available and must be loaded from somewhere. The convention used by the method amount() (no action word) is used if the value is immediately ready or ready with a trivial calculation such as
4650

@@ -66,39 +70,20 @@ To maintain compatibility and interoperability with C (i.e. Stratify OS), type d
6670

6771
### Enums and Macros
6872

69-
Both enums and constants are written in all caps with words separated by underscores. Enums are preferred to macros when defining constants because this allows them to auto-populate when using Eclipse (or another C++ IDE). Here is an example from the Dev class:
70-
71-
enum {
72-
RDONLY /*! Open as read-only */ = LINK_O_RDONLY,
73-
READONLY /*! Open as read-only */ = LINK_O_RDONLY,
74-
WRONLY /*! Open as write-only */ = LINK_O_WRONLY,
75-
WRITEONLY /*! Open as write-only */ = LINK_O_WRONLY,
76-
CREATE /*! Create when opening (files) */ = LINK_O_CREAT,
77-
CREAT /*! Create when opening (files) */ = LINK_O_CREAT,
78-
TRUNCATE /*! Truncate when opening (files) */ = LINK_O_TRUNC,
79-
TRUNC /*! Truncate when opening (files) */ = LINK_O_TRUNC,
80-
APPEND /*! Append when opening (files)*/ = LINK_O_APPEND,
81-
EXCLUSIVE /*! Create exclusively (files) */ = LINK_O_EXCL,
82-
EXCL /*! Create exclusively (files) */ = LINK_O_EXCL,
83-
READWRITE /*! Open as read-write */ = LINK_O_RDWR,
84-
RDWR /*! Open as read-write */ = LINK_O_RDWR,
85-
NONBLOCK /*! Open as non-blocking */ = LINK_O_NONBLOCK,
86-
NDELAY /*! Open as non-blocking */ = LINK_O_NONBLOCK,
87-
ACCMODE /*! Access mode mask */ = LINK_O_ACCMODE
88-
};
89-
90-
### Standard Abbreviations and a few Quirks
91-
92-
When dealing with pixels or single bits (like a high/low signal on a single pin), these abbreviations are used:
93-
94-
- tst_: test the value
95-
- inv_: invert the value
96-
- set_: set the value to 1
97-
- clr_: clear the value to 0
98-
99-
When not dealing with a single bit, clear_ or invert_ is used (i.e. clr_pixel() and bitmap.clear()).
100-
101-
For fonts and bitmaps, the methods width() and height() are used to access width and height respectively.
73+
Both enums and macros are written in all caps with words separated by underscores. Enums are preferred to macros when defining constants because this allows them to auto-populate when using code completion software. Here is an example from the hal::Device class:
74+
```c+
75+
enum {
76+
RDONLY /*! Open as read-only */ = LINK_O_RDONLY,
77+
READONLY /*! Open as read-only */ = LINK_O_RDONLY,
78+
WRONLY /*! Open as write-only */ = LINK_O_WRONLY,
79+
WRITEONLY /*! Open as write-only */ = LINK_O_WRONLY,
80+
CREATE /*! Create when opening (files) */ = LINK_O_CREAT,
81+
CREAT /*! Create when opening (files) */ = LINK_O_CREAT,
82+
TRUNCATE /*! Truncate when opening (files) */ = LINK_O_TRUNC
83+
};
84+
```
85+
86+
10287

10388

10489

0 commit comments

Comments
 (0)