moab
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 public:
00026   MBiGeom ()
00027   {
00028     // this will instance a moab Core, too
00029     _mbimesh = new MBiMesh(NULL);
00030     moab::Interface * mbi = _mbimesh->mbImpl;
00031     // pass mbi, so they will point to the same implementation
00032     _fbe = new FBEngine(mbi);
00033     _mbimeshCreated = _fbeCreated = true;
00034   }
00035   MBiGeom (MBiMesh * mbi, moab::FBEngine * fbe)
00036   {
00037     _mbimesh = mbi;
00038     _fbe = fbe;
00039     _mbimeshCreated = _fbeCreated = false;
00040   }
00041   ~MBiGeom()
00042   {
00043     // some cleanup here
00044     if (_fbeCreated) delete _fbe;
00045     if (_mbimeshCreated) delete _mbimesh;
00046   }
00047   moab::Interface * moabItf() { return _mbimesh->mbImpl;}
00048   moab::FBEngine * FBItf() { return _fbe;}
00049   MBiMesh * mbimesh() { return _mbimesh; }
00050 };
00051 /* Define macro for quick reference to MBInterface instance */
00052 static inline moab::Interface* MBI_cast( FBiGeom_Instance i )  
00053   { return reinterpret_cast<MBiGeom*>(i)->moabItf(); }
00054 
00055 #define MBI MBI_cast(instance)
00056 
00057 static inline moab::FBEngine* FBE_cast( FBiGeom_Instance i )
00058   { return reinterpret_cast<MBiGeom*>(i) -> FBItf(); }
00059 
00060 /* Define macro for quick reference to moab::Interface instance */
00061 static inline moab::EntityHandle MBH_cast( iBase_EntityHandle h )  
00062   { return reinterpret_cast<moab::EntityHandle>(h); }         
00063 
00064 #define GETGTT(a) (reinterpret_cast<MBiGeom*>(a)->FBItf()->get_gtt())
00065 
00066 static inline bool FBiGeom_isError(int code)
00067   { return (iBase_SUCCESS != code); }
00068 static inline bool FBiGeom_isError(moab::ErrorCode code)
00069   { return (moab::MB_SUCCESS != code); }
00070 
00071 // easy access to imesh instance, used for tags, sets methods
00072 #define IMESH_INSTANCE(i) reinterpret_cast<iMesh_Instance>( reinterpret_cast<MBiGeom*>(i)->mbimesh() )
00073 
00074 // this assumes that iGeom instance is always instance
00075 // uses MBiGeom class which sets the error
00076 #define MBIM reinterpret_cast<MBiGeom*>(instance)->mbimesh()
00077 
00078 #define RETURN(CODE)                                                   \
00079   do {                                                                 \
00080     *err = MBIM->set_last_error((CODE), "");                       \
00081     return;                                                            \
00082   } while(false)
00083 
00084 #define ERROR(CODE,MSG)                                                \
00085   do {                                                                 \
00086     *err = MBIM->set_last_error((CODE), (MSG));                    \
00087     return;                                                            \
00088   } while(false)
00089 
00090 #define CHKERR(CODE,MSG)                                               \
00091   do {                                                                 \
00092     if (FBiGeom_isError((CODE)))                                       \
00093       ERROR((CODE),(MSG));                                             \
00094   } while(false)
00095 
00096 #define FWDERR()                                                       \
00097   do {                                                                 \
00098     if (FBiGeom_isError(*err))                                         \
00099       return;                                                          \
00100   } while(false)
00101 
00102 #define CHECK_SIZE(array, allocated, size, type, retval)               \
00103   do {                                                                 \
00104     if (0 != allocated && NULL != array && allocated < (size)) {       \
00105       ERROR(iBase_MEMORY_ALLOCATION_FAILED, "Allocated array not "     \
00106             "enough to hold returned contents.");                      \
00107     }                                                                  \
00108     if ((size) && ((allocated) == 0 || NULL == (array))) {             \
00109       array = (type*)malloc((size)*sizeof(type));                      \
00110       allocated=(size);                                                \
00111       if (NULL == array) {                                             \
00112         ERROR(iBase_MEMORY_ALLOCATION_FAILED,                          \
00113               "Couldn't allocate array.");                             \
00114       }                                                                \
00115     }                                                                  \
00116   } while(false)
00117 
00118 #endif // FBIGEOM_MOAB_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines