Mesh Oriented datABase  (version 5.4.1)
Array-based unstructured mesh datastructure
FBiGeom_MOAB.hpp
Go to the documentation of this file.
00001 #ifndef FBIGEOM_MOAB_HPP
00002 #define FBIGEOM_MOAB_HPP
00003 
00004 #include "FBiGeom.h"
00005 //#include "moab/Forward.hpp"
00006 #include "moab/Interface.hpp"
00007 #include "moab/FBEngine.hpp"
00008 #include "iMesh.h"
00009 #include "MBiMesh.hpp"
00010 
00011 /* map from MOAB's MBErrorCode to tstt's */
00012 extern "C" const iBase_ErrorType iBase_ERROR_MAP[moab::MB_FAILURE + 1];
00013 
00014 // the igeom moab instance should privide easy access to
00015 // moab::Interface, FBEngine *, and equivalent MBiMesh instance, because a lot
00016 // of code can be shared among iMesh and iGeom, especially
00017 // with respect to tags and sets
00018 // when a moab iGeom is instanced, moab will be instanced, and FBEngine too
00019 //
00020 class MBiGeom
00021 {
00022     MBiMesh* _mbimesh;
00023     moab::FBEngine* _fbe;
00024     bool _mbimeshCreated, _fbeCreated;
00025 
00026   public:
00027     MBiGeom()
00028     {
00029         // this will instance a moab Core, too
00030         _mbimesh             = new MBiMesh( NULL );
00031         moab::Interface* mbi = _mbimesh->mbImpl;
00032         // pass mbi, so they will point to the same implementation
00033         _fbe            = new FBEngine( mbi );
00034         _mbimeshCreated = _fbeCreated = true;
00035     }
00036     MBiGeom( MBiMesh* mbi, moab::FBEngine* fbe )
00037     {
00038         _mbimesh        = mbi;
00039         _fbe            = fbe;
00040         _mbimeshCreated = _fbeCreated = false;
00041     }
00042     ~MBiGeom()
00043     {
00044         // some cleanup here
00045         if( _fbeCreated ) delete _fbe;
00046         if( _mbimeshCreated ) delete _mbimesh;
00047     }
00048     moab::Interface* moabItf()
00049     {
00050         return _mbimesh->mbImpl;
00051     }
00052     moab::FBEngine* FBItf()
00053     {
00054         return _fbe;
00055     }
00056     MBiMesh* mbimesh()
00057     {
00058         return _mbimesh;
00059     }
00060 };
00061 /* Define macro for quick reference to MBInterface instance */
00062 static inline moab::Interface* MBI_cast( FBiGeom_Instance i )
00063 {
00064     return reinterpret_cast< MBiGeom* >( i )->moabItf();
00065 }
00066 
00067 #define MBI MBI_cast( instance )
00068 
00069 static inline moab::FBEngine* FBE_cast( FBiGeom_Instance i )
00070 {
00071     return reinterpret_cast< MBiGeom* >( i )->FBItf();
00072 }
00073 
00074 /* Define macro for quick reference to moab::Interface instance */
00075 static inline moab::EntityHandle MBH_cast( iBase_EntityHandle h )
00076 {
00077     return reinterpret_cast< moab::EntityHandle >( h );
00078 }
00079 
00080 #define GETGTT( a ) ( reinterpret_cast< MBiGeom* >( a )->FBItf()->get_gtt() )
00081 
00082 static inline bool FBiGeom_isError( int code )
00083 {
00084     return ( iBase_SUCCESS != code );
00085 }
00086 static inline bool FBiGeom_isError( moab::ErrorCode code )
00087 {
00088     return ( moab::MB_SUCCESS != code );
00089 }
00090 
00091 // easy access to imesh instance, used for tags, sets methods
00092 #define IMESH_INSTANCE( i ) reinterpret_cast< iMesh_Instance >( reinterpret_cast< MBiGeom* >( i )->mbimesh() )
00093 
00094 // this assumes that iGeom instance is always instance
00095 // uses MBiGeom class which sets the error
00096 #define MBIM ( reinterpret_cast< MBiGeom* >( instance )->mbimesh() )
00097 
00098 #define RETURN( CODE )                               \
00099     do                                               \
00100     {                                                \
00101         *err = MBIM->set_last_error( ( CODE ), "" ); \
00102         return;                                      \
00103     } while( false )
00104 
00105 #define ERROR( CODE, MSG )                                \
00106     do                                                    \
00107     {                                                     \
00108         *err = MBIM->set_last_error( ( CODE ), ( MSG ) ); \
00109         return;                                           \
00110     } while( false )
00111 
00112 #define CHKERR( CODE, MSG )                                           \
00113     do                                                                \
00114     {                                                                 \
00115         if( FBiGeom_isError( ( CODE ) ) ) ERROR( ( CODE ), ( MSG ) ); \
00116     } while( false )
00117 
00118 #define FWDERR()                              \
00119     do                                        \
00120     {                                         \
00121         if( FBiGeom_isError( *err ) ) return; \
00122     } while( false )
00123 
00124 #define CHECK_SIZE( array, allocated, size, type, retval )                                \
00125     do                                                                                    \
00126     {                                                                                     \
00127         if( 0 != ( allocated ) && NULL != ( array ) && ( allocated ) < ( size ) )         \
00128         {                                                                                 \
00129             ERROR( iBase_MEMORY_ALLOCATION_FAILED, "Allocated array not "                 \
00130                                                    "enough to hold returned contents." ); \
00131         }                                                                                 \
00132         if( ( size ) && ( ( allocated ) == 0 || NULL == ( array ) ) )                     \
00133         {                                                                                 \
00134             ( array )     = (type*)malloc( ( size ) * sizeof( type ) );                   \
00135             ( allocated ) = ( size );                                                     \
00136             if( NULL == ( array ) )                                                       \
00137             {                                                                             \
00138                 ERROR( iBase_MEMORY_ALLOCATION_FAILED, "Couldn't allocate array." );      \
00139             }                                                                             \
00140         }                                                                                 \
00141     } while( false )
00142 
00143 #endif  // FBIGEOM_MOAB_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines