Differences between revisions 1 and 4 (spanning 3 versions)
Revision 1 as of 2014-02-26 16:48:44
Size: 2383
Editor: 192
Comment:
Revision 4 as of 2014-02-26 16:58:40
Size: 2668
Editor: 192
Comment:
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
 * Use .hxx and .cxx, prefix all header files with "cl"  * Use .hxx and .cxx and prefix all header files with "cl".
    ''example:'' clTransaction.hxx, transaction.cxx
Line 5: Line 6:
    examples: ''clLogApi.hxx'', ''clCkptApi.hxx''
    '''An application only needs to include these files (they must include other required header files)!'''
    ''examples:'' ''clLogApi.hxx'', ''clCkptApi.hxx''

    '''An application only needs to include these files'''.  These files must include any other required header files.
Line 8: Line 10:
    examples: ''clTransaction.hxx''
    '''An application MAY include these files if it wants that specific functionality'''
    ''examples:'' ''clTransaction.hxx''

    '''An application MAY include these files''' if it wants that specific functionality.
Line 11: Line 14:
    examples: ''clCkptIpi.hxx''     ''examples:'' ''clCkptIpi.hxx''
Line 17: Line 21:
{{{#!highlight cpp     {{{#!highlight cpp
Line 39: Line 43:
{{{#!highlight cpp     {{{#!highlight cpp
Line 49: Line 53:
 * Do not hide implementation using Handles. Expose them via pointers or containment. This makes debugging much simpler and its easy enough just to skip over tracing through the implementation if needed.
 * Also, prefer containment; do not use pointers rather than containment just to hide implementation.
 * Do not hide implementation using handles.      Expose them via pointers or containment. This makes debugging much simpler and its easy enough just to skip over tracing through the implementation if needed.
    Also, prefer containment; do not use pointers rather than containment just to hide implementation.
Line 52: Line 57:
clSvcIpi.hxx
{{{#!highlight cpp
    clSvcIpi.hxx
    {{{#!highlight cpp
Line 65: Line 70:
clSvcApi.hxx
{{{#!highlight cpp
    clSvcApi.hxx
    {{{#!highlight cpp
Line 82: Line 87:
 
Line 84: Line 88:
 '''''With pointers, predeclarations are preferred'''''
{{{#!highlight cpp
    Note that in this case, the application will end up including the Ipi file. This is ok, it is clear by the namespace what is API and what is internal.


    '''''With pointers, predeclarations are preferred'''''
    {{{#!highlight cpp

Files

  • Use .hxx and .cxx and prefix all header files with "cl".
    • example: clTransaction.hxx, transaction.cxx

  • Name major functional blocks cl<FN>Api.hxx

    • examples: clLogApi.hxx, clCkptApi.hxx

      An application only needs to include these files. These files must include any other required header files.

  • Other files can be named based on the primary class defined inside
    • examples: clTransaction.hxx

      An application MAY include these files if it wants that specific functionality.

  • Internal APIs should be named cl<something>Ipi.hxx

    • examples: clCkptIpi.hxx

      These files may get pulled into application builds due to object containment. However, it must not be necessary for the application program to ever use symbols defined in the Ipi files.

Definitions

  • All application-level APIs must be defined under the SAFplus namespace:

    •    1 namespace SAFplus
         2   {
         3   class Checkpoint  // Class
         4     {
         5     ...
         6     }; 
         7 
         8   typedef enum  // Enum
         9     {
        10     LOG_SEV_EMERGENCY = 0x1,
        11     ...
        12     };
        13 
        14   Logger* logInitialize(void);  // A function
        15 
        16   int logSeverity;  // A Variable
        17   };
      
  • All internal APIs must be defined under the SAFplusI namespace (I for internal):

    •    1 namespace SAFplusI
         2   {
         3 
         4   };
      
  • Do not hide implementation using handles.
    • Expose them via pointers or containment. This makes debugging much simpler and its easy enough just to skip over tracing through the implementation if needed. Also, prefer containment; do not use pointers rather than containment just to hide implementation. clSvcIpi.hxx
         1   namespace SAFplusI
         2   {
         3     class InternalObject
         4       {
         5       ...
         6       };
         7   };
      
      clSvcApi.hxx
         1   #include <clSvcIpi.hxx>
         2   namespace SAFplus
         3   {
         4     class Svc
         5       {
         6       ...
         7       InternalObject& getIo(char* key);  // WRONG: InternalObject is exposed to the application so should be in the API, not IPI.
         8 
         9       protected:
        10       InternalObject array[20];
        11       };
        12   };
      
      Note that in this case, the application will end up including the Ipi file. This is ok, it is clear by the namespace what is API and what is internal.

      With pointers, predeclarations are preferred

         1 namespace SAFplusI
         2   {
         3     class InternalObject;  // Predeclaration
         4   };
         5 
         6 namespaces SAFplus
         7   {
         8     class Svc
         9       {
        10       ...
        11       protected: 
        12       InternalObject* array;
        13       };
        14   };
      

SAFplus: Programming Style Requirements (last edited 2015-04-23 16:42:04 by AndrewStone)