Here is an example class that uses the ORIGEN naming convention.
```cpp
```cpp
namespacescale{
namespacescale{
...
@@ -5,11 +6,11 @@ bool isSameBuffer(int* a, int* b){
...
@@ -5,11 +6,11 @@ bool isSameBuffer(int* a, int* b){
returna==b;
returna==b;
}
}
classReader_Int{
classBufferedReader_Int{
private:
private:
int*b_buffer;
int*b_buffer;
Reader():b_buffer(newint()){}
BufferedReader():b_buffer(newint()){}
~Reader(){deleteb_buffer;}
~BufferedReader(){deleteb_buffer;}
public:
public:
voidread(std::istream&is){
voidread(std::istream&is){
is>>*b_buffer;
is>>*b_buffer;
...
@@ -24,7 +25,7 @@ class Reader_Int{
...
@@ -24,7 +25,7 @@ class Reader_Int{
};
};
}//end namespace scale
}//end namespace scale
intmain(){
intmain(){
scale::Reader_Intreader;
scale::BufferedReader_Intreader;
{
{
std::ofstreamofs("file.txt");
std::ofstreamofs("file.txt");
ofs<<7;
ofs<<7;
...
@@ -34,15 +35,17 @@ int main(){
...
@@ -34,15 +35,17 @@ int main(){
std::cout<<*reader.buffer()<<std::endl;
std::cout<<*reader.buffer()<<std::endl;
return0;
return0;
}
}
//Note this could be generalized to a templated Reader.
```
A strict camel case would have this reader be named ``BufferedIntReader`` or ``IntBufferedReader``, but this has some shortcomings. First, by pushing the "variant" part of the naming to the end, we get good, automatic sorting of the classes. This helps in editors and in documentation that lexically similar implies logically similar. Now, imagine what happens when we get around to templating the BufferedReader.
```c++
template<typenameT>
template<typenameT>
classReader{
classBufferedReader{
//contents
//contents
};
};
//Then it is natural to use these typedefs.
typedefBufferedReader<int>BufferedReader_Int;
typedefReader<int>Reader_Int;
typedefBufferedReader<double>BufferedReader_Dbl;
typedefReader<double>Reader_Dbl;
```
//This is preferable to defining IntReader, DoubleReader, etc., because Reader_Dbl, Reader_Int will be automatically sorted to show their relationship.
The typedefs mirror the templating syntax and can always be made fairly straightforwardly, as opposed to trying to figure out where to put the "Int", i.e. is it "BufferedIntReader" or "IntBufferedReader". With multiple template parameters it gets even more hairy, but the _ syntax, simply leads to ``typedef std::map<std::string,int> Map_Str_Int``.
```
```
Basic ways of distinguishing word boundaries with ``<LWORD>=[a-z]+`` and ``<UWORD>=[A-Z][a-z]+``
Basic ways of distinguishing word boundaries with ``<LWORD>=[a-z]+`` and ``<UWORD>=[A-Z][a-z]+``
* Camel case
* Camel case
...
@@ -85,9 +88,9 @@ With those definitions in mind, let's define a set of word conventions. The main
...
@@ -85,9 +88,9 @@ With those definitions in mind, let's define a set of word conventions. The main
* e.g. ``scale::io``,``origen::detail``,`` origen::tst``,``origen::example``,``ornl::gtest::example``
* e.g. ``scale::io``,``origen::detail``,`` origen::tst``,``origen::example``,``ornl::gtest::example``
6. typedef or variant class name (``CLASSTYPE``)
6. typedef or variant class name (``CLASSTYPE``)
* description: "CamelCase_variant" used for classes which are logically very similar, perhaps typedefed templated classes
* description: "CamelCase_variant" used for classes which are logically very similar, perhaps typedefed templated classes
* conventions: for STL typedefs, use ``Vec`` for vector, ``Map`` for map, ``Set`` for set, ``Dbl`` for double, ``Int`` for int, ``Str`` for string, ``Long`` for long (>=64-bit), ``Sze`` for size_t, ``Bool`` for bool.
* conventions: for STL typedefs, use ``Vec`` for vector, ``Map`` for map, ``Set`` for set, ``Dbl`` for double, ``Int`` for int, ``Str`` for string, ``Long`` for long (>=64-bit), ``Sze`` for size_t, ``Bool`` for bool.
* e.g.: ``LibraryIo_bof``, ``LibraryIo_s61`` which define a variant by different file types, and ``Vec_Dbl``, ``Vec_Str``, ``Map_Str_Int``, which define "typedef-style" variants where the first class is the template class and the remaining are the template parameters.
7. general-use free functions (``LIBFUNC``)
7. general-use free functions (``LIBFUNC``)
* description: in style of the STL library, should be templated
* description: in style of the STL library, should be templated