Skip to content

File Header Structure and Includes

williamfgc edited this page May 1, 2017 · 41 revisions
  1. License header: All files start with the ADIOS2 Apache license header, file name, creation date, and author. Contact information is encouraged.
    •  /**
       * Distributed under the OSI-approved Apache License, Version 2.0.  See
       * accompanying file Copyright.txt for details.
       *
       * MyClass.h
       *
       *  Created on: Apr 21, 2017
       *      Author: John Doe  [email protected]
       */
       
  2. Header include organization: Example for file ClassName.cpp :
    1. Corresponding header: ClassName.h
    2. System C/POSIX Headers e.g. unistd.h, sys/ipc.h
    3. C++ versions of system C headers e.g. cstdlib, cstring
    4. System C++ headers e.g. vector, map
    5. Other library headers e.g. boost, zfp, bzip2, thrust
    6. Other headers from this library e.g "adiosFunctions.h"
    • Example:
      •  #include   "ClassName.h" 
        
      •  #include   <unistd.h>     // write, close  
         #include   <sys/ipc.h>     // key_t  
        
      •  #include   <vector> 
         #include   <new>     // std::bad_alloc  
        
      •  #include   <bzip2.h> 
         #include   <zfp.h> 
        
      •  #include   "adiosFunctions.h"     // IsLittleEndian  
        
  3. Include guards: all headers must have include guards to prevents name conflict. These are place right after the license and at the end of the file. The adopted format includes the relative path in ADIOS. For example, file adios2/engine/bp/BPFileWriter.h will contain the following include guards:

      • 
        #ifndef  ADIOS2_ENGINE_BP_BPFILEWRITER_H_
        #define  ADIOS2_ENGINE_BP_BPFILEWRITER_H_

        //File contents... ...

        //End of file #endif // end of ADIOS2_ENGINE_BP_BPFILEWRITER_H_

  4. Document includes: list header components used in the code if header is not self-explanatory

    • Example:
      • #include   <vector>    //self-explanatory, no comment needed
        #include   <utility>    //std::pair
        #include <stdexcept> //std::invalid_argument