Branch data Line data Source code
1 : : /**
2 : : * MOAB, a Mesh-Oriented datABase, is a software component for creating,
3 : : * storing and accessing finite element mesh data.
4 : : *
5 : : * Copyright 2004 Sandia Corporation. Under the terms of Contract
6 : : * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
7 : : * retains certain rights in this software.
8 : : *
9 : : * This library is free software; you can redistribute it and/or
10 : : * modify it under the terms of the GNU Lesser General Public
11 : : * License as published by the Free Software Foundation; either
12 : : * version 2.1 of the License, or (at your option) any later version.
13 : : *
14 : : */
15 : :
16 : : #ifndef MB_ENTITY_TYPE_H
17 : : #define MB_ENTITY_TYPE_H
18 : :
19 : : /* This file can be used to define several different things.
20 : : *
21 : : * A) If included in C code (not C++), it defines:
22 : : * 1) An enum named MBEntityType, guarded by the MB_ENTITY_TYPE_H
23 : : * include guards and
24 : : * 2) a typedef MBEntityType guarded by MOAB_ENTITY_TYPE_C include guards.
25 : : *
26 : : * B) If included in C++ code, it defines:
27 : : * 1) An enum named EntiyType in the MOAB namespace, guarded
28 : : * by the MB_ENTITY_TYPE include guards
29 : : * 2) Increment and decrement oeprators for the moab::EntityType enum,
30 : : * also guarded by the MB_ENTITY_TYPE include guards
31 : : * 3) A typedef for moab::EntityType in the global namespace
32 : : * named MBEntityType, guarded by the MOAB_ENTITY_TYPE_NS_ONLY
33 : : * include guards
34 : : *
35 : : * The C and C++ code should be entirely independent. They are defined
36 : : * in the same file only to avoid code duplication and inconsistent enum
37 : : * values. OTOH, the C++ definitions must be in the same file because
38 : : * the compiler must treat both the namespaced and non-namespaced names
39 : : * as the same type.
40 : : *
41 : : * The C++ code must be able to provide:
42 : : * a) An enum in the moab namespace
43 : : * b) An enum in the global namespace that is the *same type*
44 : : * as a) as far as the compiler is concerned.
45 : : * c) Nothing in the global namespace unless requested
46 : : * d) No breakage if both namespaced and non-namespaced headers
47 : : * are both included.
48 : : *
49 : : * This is acheived with the somewhat complicated set of multiple
50 : : * included guards described above, where moab/EntityType.hpp will
51 : : * include this file with MOAB_ENTITY_TYPE_NS_OLNY temporarily defined
52 : : * so as to pull in only the namespaced version at that time, without
53 : : * prohibiting the non-namespaced version from being pulled in previously
54 : : * or later.
55 : : */
56 : : #ifdef __cplusplus
57 : : namespace moab {
58 : : # define MOAB_ENTITY_TYPE_NAME EntityType
59 : : # else /* __cplusplus */
60 : : # define MOAB_ENTITY_TYPE_NAME MBEntityType
61 : : #endif /* __cplusplus */
62 : :
63 : : /*! Entity types defined in MOAB and MBCN
64 : : * The ordering here must ensure that all element types are
65 : : * grouped together and all elements of similar dimension are
66 : : * grouped together.
67 : : */
68 : : enum MOAB_ENTITY_TYPE_NAME
69 : : {
70 : : MBVERTEX = 0, /**< Mesh Vertex AKA node */
71 : : MBEDGE, /**< Mesh Edge */
72 : : MBTRI, /**< Triangular element (including shells) */
73 : : MBQUAD, /**< Quadrilateral element (including shells) */
74 : : MBPOLYGON, /**< Polygon */
75 : : MBTET, /**< Tetrahedral element */
76 : : MBPYRAMID, /**< Pyramid element (where are the face ids for this defined?) */
77 : : MBPRISM, /**< Wedge element (Exodus has one, Cubit doesn't. Does Mesh need it?) */
78 : : MBKNIFE, /**< Knife element */
79 : : MBHEX, /**< Hexahedral element */
80 : : MBPOLYHEDRON, /**< Polyhedron */
81 : : MBENTITYSET, /**< MeshSet */
82 : : MBMAXTYPE /**< Just a place keeper - must be the # of entities, for array */
83 : : /**< dimensioning purposes */
84 : : };
85 : :
86 : : #ifdef __cplusplus
87 : : /** prefix increment operator for MBEntityType */
88 : 28714 : inline MOAB_ENTITY_TYPE_NAME & operator++(MOAB_ENTITY_TYPE_NAME &type)
89 : : {
90 : 28714 : return type = static_cast<MOAB_ENTITY_TYPE_NAME>(type+1);
91 : : }
92 : :
93 : : /** postfix increment operator for MBEntityType */
94 : 11031 : inline MOAB_ENTITY_TYPE_NAME operator++(MOAB_ENTITY_TYPE_NAME &type, int)
95 : : {
96 : 11031 : MOAB_ENTITY_TYPE_NAME oldval = type;
97 : 11031 : ++type;
98 : 11031 : return oldval;
99 : : }
100 : :
101 : : /** prefix increment operator for MBEntityType */
102 : 17760 : inline MOAB_ENTITY_TYPE_NAME & operator--(MOAB_ENTITY_TYPE_NAME &type)
103 : : {
104 : 17760 : return type = static_cast<MOAB_ENTITY_TYPE_NAME>(type-1);
105 : : }
106 : :
107 : : /** postfix increment operator for MBEntityType */
108 : : inline MOAB_ENTITY_TYPE_NAME operator--(MOAB_ENTITY_TYPE_NAME &type, int)
109 : : {
110 : : MOAB_ENTITY_TYPE_NAME oldval = type;
111 : : --type;
112 : : return oldval;
113 : : }
114 : :
115 : : } /* namespace moab*/
116 : : #endif /* __cplusplus */
117 : :
118 : : #undef MOAB_ENTITY_TYPE_NAME
119 : : #endif /* MB_ENTITY_TYPE_H */
120 : :
121 : : #ifdef __cplusplus
122 : : # ifndef MOAB_ENTITY_TYPE_NS_ONLY
123 : : # define MOAB_ENTITY_TYPE_NS_ONLY
124 : : typedef moab::EntityType MBEntityType;
125 : : using moab::MBVERTEX;
126 : : using moab::MBEDGE;
127 : : using moab::MBTRI;
128 : : using moab::MBQUAD;
129 : : using moab::MBPOLYGON;
130 : : using moab::MBTET;
131 : : using moab::MBPYRAMID;
132 : : using moab::MBPRISM;
133 : : using moab::MBKNIFE;
134 : : using moab::MBHEX;
135 : : using moab::MBPOLYHEDRON;
136 : : using moab::MBENTITYSET;
137 : : using moab::MBMAXTYPE;
138 : : # endif /* MOAB_ENTITY_TYPE_NS_ONLY */
139 : : #else /* __cplusplus */
140 : : # ifndef MOAB_ENTITY_TYPE_C
141 : : # define MOAB_ENTITY_TYPE_C
142 : : typedef enum MBEntityType MBEntityType;
143 : : # endif /* MOAB_ENTITY_TYPE_C */
144 : : #endif /* __cplusplus */
|