moab
MBEntityType.h
Go to the documentation of this file.
00001 
00016 #ifndef MB_ENTITY_TYPE_H
00017 #define MB_ENTITY_TYPE_H
00018 
00019 /* This file can be used to define several different things.
00020  *
00021  * A) If included in C code (not C++), it defines:
00022  *    1) An enum named MBEntityType, guarded by the MB_ENTITY_TYPE_H
00023  *        include guards and 
00024  *    2) a typedef MBEntityType guarded by MOAB_ENTITY_TYPE_C include guards.
00025  *
00026  * B) If included in C++ code, it defines:
00027  *    1) An enum named EntiyType in the MOAB namespace, guarded
00028  *       by the MB_ENTITY_TYPE include guards
00029  *    2) Increment and decrement oeprators for the moab::EntityType enum,
00030  *       also guarded by the MB_ENTITY_TYPE include guards
00031  *    3) A typedef for moab::EntityType in the global namespace 
00032  *        named MBEntityType, guarded by the MOAB_ENTITY_TYPE_NS_ONLY
00033  *        include guards
00034  *
00035  * The C and C++ code should be entirely independent.  They are defined
00036  * in the same file only to avoid code duplication and inconsistent enum
00037  * values.  OTOH, the C++ definitions must be in the same file because
00038  * the compiler must treat both the namespaced and non-namespaced names
00039  * as the same type.
00040  *
00041  * The C++ code must be able to provide:
00042  *  a) An enum in the moab namespace
00043  *  b) An enum in the global namespace that is the *same type*
00044  *      as a) as far as the compiler is concerned.
00045  *  c) Nothing in the global namespace unless requested
00046  *  d) No breakage if both namespaced and non-namespaced headers
00047  *      are both included.
00048  * 
00049  * This is acheived with the somewhat complicated set of multiple
00050  * included guards described above, where moab/EntityType.hpp will
00051  * include this file with MOAB_ENTITY_TYPE_NS_OLNY temporarily defined
00052  * so as to pull in only the namespaced version at that time, without
00053  * prohibiting the non-namespaced version from being pulled in previously
00054  * or later.
00055  */
00056 #ifdef __cplusplus
00057 namespace moab { 
00058 # define MOAB_ENTITY_TYPE_NAME EntityType
00059 # else /* __cplusplus */
00060 # define MOAB_ENTITY_TYPE_NAME MBEntityType
00061 #endif /* __cplusplus */
00062 
00068 enum MOAB_ENTITY_TYPE_NAME
00069 {
00070   MBVERTEX = 0, 
00071   MBEDGE,       
00072   MBTRI,        
00073   MBQUAD,       
00074   MBPOLYGON,    
00075   MBTET,        
00076   MBPYRAMID,    
00077   MBPRISM,      
00078   MBKNIFE,      
00079   MBHEX,        
00080   MBPOLYHEDRON, 
00081   MBENTITYSET,    
00082   MBMAXTYPE  
00084 };
00085 
00086 #ifdef __cplusplus
00087 
00088 inline MOAB_ENTITY_TYPE_NAME & operator++(MOAB_ENTITY_TYPE_NAME &type)
00089 {
00090   return type = static_cast<MOAB_ENTITY_TYPE_NAME>(type+1);
00091 }
00092 
00094 inline MOAB_ENTITY_TYPE_NAME operator++(MOAB_ENTITY_TYPE_NAME &type, int)
00095 {
00096   MOAB_ENTITY_TYPE_NAME oldval = type;
00097   ++type;
00098   return oldval;
00099 }
00100 
00102 inline MOAB_ENTITY_TYPE_NAME & operator--(MOAB_ENTITY_TYPE_NAME &type)
00103 {
00104   return type = static_cast<MOAB_ENTITY_TYPE_NAME>(type-1);
00105 }
00106 
00108 inline MOAB_ENTITY_TYPE_NAME operator--(MOAB_ENTITY_TYPE_NAME &type, int)
00109 {
00110   MOAB_ENTITY_TYPE_NAME oldval = type;
00111   --type;
00112   return oldval;
00113 }
00114 
00115 } /* namespace moab*/
00116 #endif /* __cplusplus */
00117 
00118 #undef MOAB_ENTITY_TYPE_NAME
00119 #endif /* MB_ENTITY_TYPE_H */
00120 
00121 #ifdef __cplusplus
00122 #  ifndef MOAB_ENTITY_TYPE_NS_ONLY
00123 #    define MOAB_ENTITY_TYPE_NS_ONLY
00124      typedef moab::EntityType MBEntityType;
00125      using moab::MBVERTEX;
00126      using moab::MBEDGE;
00127      using moab::MBTRI;
00128      using moab::MBQUAD;
00129      using moab::MBPOLYGON;
00130      using moab::MBTET;
00131      using moab::MBPYRAMID;
00132      using moab::MBPRISM;
00133      using moab::MBKNIFE;
00134      using moab::MBHEX;
00135      using moab::MBPOLYHEDRON;
00136      using moab::MBENTITYSET;
00137      using moab::MBMAXTYPE;
00138 #  endif /* MOAB_ENTITY_TYPE_NS_ONLY */
00139 #else /* __cplusplus */
00140 #  ifndef MOAB_ENTITY_TYPE_C
00141 #    define MOAB_ENTITY_TYPE_C
00142      typedef enum MBEntityType MBEntityType;
00143 #  endif /* MOAB_ENTITY_TYPE_C */
00144 #endif /* __cplusplus */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines