MOAB: Mesh Oriented datABase  (version 5.2.1)
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 "moab/ErrorHandler.hpp"
00006 #include "DebugOutput.hpp"
00007 
00008 #include "damsel.h"
00009 #include "damsel-internal.h"
00010 
00011 // Some macros to handle error checking (cribbed from WriteHDF5).
00012 // All macros contain a "return" statement. These macros are coded with a do if while
00013 // to allow statements calling them to be terminated with a ;
00014 #define CHK_DMSL_ERR( A, B )            \
00015     do                                  \
00016     {                                   \
00017         if( DMSL_OK.id != A.id )        \
00018         {                               \
00019             MB_SET_ERR_CONT( B );       \
00020             return error( MB_FAILURE ); \
00021         }                               \
00022     } while( false )
00023 
00024 #define CHK_DMSL_ERR_NM( A )               \
00025     do                                     \
00026     {                                      \
00027         if( DMSL_OK.id != A.id )           \
00028         {                                  \
00029             MB_CHK_ERR_CONT( MB_FAILURE ); \
00030             return error( MB_FAILURE );    \
00031         }                                  \
00032     } while( false )
00033 
00034 namespace moab
00035 {
00036 
00037 class DamselUtil
00038 {
00039   public:
00040     friend class WriteDamsel;
00041     friend class ReadDamsel;
00042 
00043     //! Needs to be a constructor to initialize dtom_data_type
00044     DamselUtil();
00045 
00046     static damsel_data_type mtod_data_type[MB_MAX_DATA_TYPE + 1];
00047 
00048     static enum DataType dtom_data_type[DAMSEL_DATA_TYPE_PREDEFINED_WATERMARK + 1];
00049 
00050     static enum damsel_entity_type mtod_entity_type[MBMAXTYPE + 1];
00051 
00052     static enum EntityType dtom_entity_type[DAMSEL_ENTITY_TYPE_ALL_TYPES + 1];
00053 
00054     //! Convert handles in a container to a range; assumes EntityHandle and Damsel
00055     //! entity handles are the same size
00056     static ErrorCode container_to_range( damsel_model m, damsel_container& cont, Range& range );
00057 
00058     //! struct to hold information on damsel/moab tags
00059     class tinfo
00060     {
00061       public:
00062         tinfo( Tag mt, damsel_handle dt, TagType tt ) : mTagh( mt ), dTagh( dt ), tagType( tt ) {}
00063         tinfo() : mTagh( 0 ), dTagh( 0 ), tagType( MB_TAG_ANY ) {}
00064 
00065         Tag mTagh;
00066         damsel_handle dTagh;
00067         TagType tagType;
00068     };
00069 
00070     template < class T >
00071     struct MtagP : std::unary_function< T, bool >
00072     {
00073       public:
00074         MtagP( const Tag& th )
00075         {
00076             tH = th;
00077         }
00078         bool operator()( const T& tclass )
00079         {
00080             return tclass.mTagh == tH;
00081         }
00082         Tag tH;
00083     };
00084 
00085     template < class T >
00086     struct DtagP : std::unary_function< T, bool >
00087     {
00088       public:
00089         DtagP( const damsel_handle& th )
00090         {
00091             tH = th;
00092         }
00093         bool operator()( const T& tclass )
00094         {
00095             return tclass.dTagh == tH;
00096         }
00097         damsel_handle tH;
00098     };
00099 
00100   private:
00101     //! Damsel library id
00102     damsel_library dmslLib;
00103 
00104     //! Damsel model id
00105     damsel_model dmslModel;
00106 
00107     //! Other conventional tags
00108     tinfo xcoordsTag, ycoordsTag, zcoordsTag, collFlagsTag, parentsTag, childrenTag;
00109 
00110     //! MOAB/damsel handles for dense [0], sparse [1], and conventional [2] tags
00111     std::vector< tinfo > tagMap;
00112 
00113     //! Damsel handle type used in (this build of) MOAB
00114     damsel_handle_type moabHandleType;
00115 };
00116 
00117 // This function doesn't do anything useful. It's just a nice
00118 // place to set a break point to determine why the reader fails.
00119 static inline ErrorCode error( ErrorCode rval )
00120 {
00121     return rval;
00122 }
00123 
00124 }  // namespace moab
00125 
00126 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines