MOAB: Mesh Oriented datABase  (version 5.5.0)
FBiGeom_MOAB.hpp
Go to the documentation of this file.
1 #ifndef FBIGEOM_MOAB_HPP
2 #define FBIGEOM_MOAB_HPP
3 
4 #include "FBiGeom.h"
5 //#include "moab/Forward.hpp"
6 #include "moab/Interface.hpp"
7 #include "moab/FBEngine.hpp"
8 #include "iMesh.h"
9 #include "MBiMesh.hpp"
10 
11 /* map from MOAB's MBErrorCode to tstt's */
12 extern "C" const iBase_ErrorType iBase_ERROR_MAP[moab::MB_FAILURE + 1];
13 
14 // the igeom moab instance should privide easy access to
15 // moab::Interface, FBEngine *, and equivalent MBiMesh instance, because a lot
16 // of code can be shared among iMesh and iGeom, especially
17 // with respect to tags and sets
18 // when a moab iGeom is instanced, moab will be instanced, and FBEngine too
19 //
20 class MBiGeom
21 {
25 
26  public:
28  {
29  // this will instance a moab Core, too
30  _mbimesh = new MBiMesh( NULL );
32  // pass mbi, so they will point to the same implementation
33  _fbe = new FBEngine( mbi );
35  }
37  {
38  _mbimesh = mbi;
39  _fbe = fbe;
40  _mbimeshCreated = _fbeCreated = false;
41  }
43  {
44  // some cleanup here
45  if( _fbeCreated ) delete _fbe;
46  if( _mbimeshCreated ) delete _mbimesh;
47  }
49  {
50  return _mbimesh->mbImpl;
51  }
53  {
54  return _fbe;
55  }
57  {
58  return _mbimesh;
59  }
60 };
61 /* Define macro for quick reference to MBInterface instance */
63 {
64  return reinterpret_cast< MBiGeom* >( i )->moabItf();
65 }
66 
67 #define MBI MBI_cast( instance )
68 
70 {
71  return reinterpret_cast< MBiGeom* >( i )->FBItf();
72 }
73 
74 /* Define macro for quick reference to moab::Interface instance */
76 {
77  return reinterpret_cast< moab::EntityHandle >( h );
78 }
79 
80 #define GETGTT( a ) ( reinterpret_cast< MBiGeom* >( a )->FBItf()->get_gtt() )
81 
82 static inline bool FBiGeom_isError( int code )
83 {
84  return ( iBase_SUCCESS != code );
85 }
86 static inline bool FBiGeom_isError( moab::ErrorCode code )
87 {
88  return ( moab::MB_SUCCESS != code );
89 }
90 
91 // easy access to imesh instance, used for tags, sets methods
92 #define IMESH_INSTANCE( i ) reinterpret_cast< iMesh_Instance >( reinterpret_cast< MBiGeom* >( i )->mbimesh() )
93 
94 // this assumes that iGeom instance is always instance
95 // uses MBiGeom class which sets the error
96 #define MBIM ( reinterpret_cast< MBiGeom* >( instance )->mbimesh() )
97 
98 #define RETURN( CODE ) \
99  do \
100  { \
101  *err = MBIM->set_last_error( ( CODE ), "" ); \
102  return; \
103  } while( false )
104 
105 #define ERROR( CODE, MSG ) \
106  do \
107  { \
108  *err = MBIM->set_last_error( ( CODE ), ( MSG ) ); \
109  return; \
110  } while( false )
111 
112 #define CHKERR( CODE, MSG ) \
113  do \
114  { \
115  if( FBiGeom_isError( ( CODE ) ) ) ERROR( ( CODE ), ( MSG ) ); \
116  } while( false )
117 
118 #define FWDERR() \
119  do \
120  { \
121  if( FBiGeom_isError( *err ) ) return; \
122  } while( false )
123 
124 #define CHECK_SIZE( array, allocated, size, type, retval ) \
125  do \
126  { \
127  if( 0 != ( allocated ) && NULL != ( array ) && ( allocated ) < ( size ) ) \
128  { \
129  ERROR( iBase_MEMORY_ALLOCATION_FAILED, "Allocated array not " \
130  "enough to hold returned contents." ); \
131  } \
132  if( ( size ) && ( ( allocated ) == 0 || NULL == ( array ) ) ) \
133  { \
134  ( array ) = (type*)malloc( ( size ) * sizeof( type ) ); \
135  ( allocated ) = ( size ); \
136  if( NULL == ( array ) ) \
137  { \
138  ERROR( iBase_MEMORY_ALLOCATION_FAILED, "Couldn't allocate array." ); \
139  } \
140  } \
141  } while( false )
142 
143 #endif // FBIGEOM_MOAB_HPP