moab
DamselUtil.hpp
Go to the documentation of this file.
00001 #ifndef DAMSEL_UTIL_HPP
00002 #define DAMSEL_UTIL_HPP
00003 
00004 #include "moab/Forward.hpp"
00005 #include "DebugOutput.hpp"
00006 
00007 #include "damsel.h"
00008 #include "damsel-internal.h"
00009 
00010   // Some macros to handle error checking (cribbed from WriteHDF5).  The
00011   // CHK_MB_ERR_* check the value of an ErrorCode.
00012   // The *_0 macros accept no other arguments. The *_1
00013   // macros accept a single damsel handle to close on error.
00014   // All macros contain a "return" statement.  These macros are coded with a do if while
00015   // to allow statements calling them to be terminated with a ;
00016 #define CHK_MB_ERR( A, B )                                    \
00017 do if (MB_SUCCESS != (A)) { \
00018 mError->set_last_error(B);\
00019 return error(A);} while(false)
00020 
00021 #define CHK_MB_ERR_NR( A, B )                                    \
00022 do if (MB_SUCCESS != (A)) { \
00023 mError->set_last_error(B);\
00024 std::cerr << B << std::endl;} while(false)
00025 
00026 #define CHK_MB_ERR_2( A, B, C )                   \
00027 do if (MB_SUCCESS != (A   )) { \
00028 mError->set_last_error(B, C);                 \
00029 return error(A);} while(false)
00030 
00031 #define CHK_MB_ERR_FINALIZE( A, B )       \
00032 do if (MB_SUCCESS != (A)) {             \
00033   DMSLlib_finalize(dmslLib); \
00034   dmslLib = 0;          \
00035   mError->set_last_error(B);\
00036   return error(A);     \
00037 } while(false)
00038 
00039 #define CHK_DMSL_ERR( A, B )                 \
00040 do if (DMSL_OK.id != A.id) {             \
00041 mError->set_last_error(B);\
00042 return error(MB_FAILURE);             \
00043 } while(false)
00044 
00045 #define CHK_DMSL_ERR_2( A, B, C )            \
00046 do if (DMSL_OK.id != A.id) {             \
00047 mError->set_last_error(B, C);            \
00048 return error(MB_FAILURE);             \
00049 } while(false)
00050 
00051 #define CHK_DMSL_ERR_NM( A )                 \
00052 if (DMSL_OK.id != A.id) return error(MB_FAILURE);
00053 
00054 #define CHK_DMSL_ERR_FINALIZE( A, B )        \
00055 do if (DMSL_OK.id != A.id) {             \
00056   DMSLlib_finalize(dmslLib); \
00057   dmslLib = 0;          \
00058   mError->set_last_error(B);\
00059   return error(MB_FAILURE);                    \
00060 } while(false)
00061 
00062 namespace moab {
00063 
00064 class DamselUtil 
00065 {
00066 public:
00067   friend class WriteDamsel;
00068   friend class ReadDamsel;
00069   
00071   DamselUtil();
00072 
00073   static damsel_data_type mtod_data_type[MB_MAX_DATA_TYPE+1];
00074 
00075   static enum DataType dtom_data_type[DAMSEL_DATA_TYPE_PREDEFINED_WATERMARK+1];
00076 
00077   static enum damsel_entity_type mtod_entity_type[MBMAXTYPE+1];
00078 
00079   static enum EntityType dtom_entity_type[DAMSEL_ENTITY_TYPE_ALL_TYPES+1];
00080 
00083   static ErrorCode container_to_range(damsel_model m, damsel_container &cont, Range &range);
00084 
00086   class tinfo
00087   {
00088     public:
00089     tinfo(Tag mt, damsel_handle dt, TagType tt) : mTagh(mt), dTagh(dt), tagType(tt) {};
00090     tinfo()  : mTagh(0), dTagh(0), tagType(MB_TAG_ANY) {};
00091           
00092     Tag mTagh;
00093     damsel_handle dTagh;
00094     TagType tagType;
00095   };
00096   template<class T> struct MtagP : std::unary_function<T, bool> {
00097     public:
00098     MtagP(const Tag &th) {tH = th;};
00099     bool operator() (const T &tclass) {return tclass.mTagh == tH;};
00100     Tag tH;
00101   };
00102   
00103   template<class T> struct DtagP : std::unary_function<T, bool> {
00104     public:
00105     DtagP(const damsel_handle &th) {tH = th;};
00106     bool operator() (const T &tclass) {return tclass.dTagh == tH;};
00107     damsel_handle tH;
00108   };
00109 
00110 private:
00112   damsel_library dmslLib;
00113   
00115   damsel_model dmslModel;
00116 
00118   tinfo xcoordsTag, ycoordsTag, zcoordsTag, 
00119       collFlagsTag, parentsTag, childrenTag;
00120 
00122   std::vector<tinfo> tagMap;
00123   
00125   damsel_handle_type moabHandleType;
00126 
00127 };
00128 
00129 // This function doesn't do anything useful.  It's just a nice
00130 // place to set a break point to determine why the reader fails.
00131     static inline ErrorCode error( ErrorCode rval )
00132   { return rval; }
00133 
00134 }
00135 
00136 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines