MOAB: Mesh Oriented datABase  (version 5.3.0)
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
00072     {
00073       // deprecation of unary_function
00074       typedef T argument_type;
00075       typedef bool result_type;
00076 
00077       public:
00078         MtagP( const Tag& th )
00079         {
00080             tH = th;
00081         }
00082         bool operator()( const T& tclass )
00083         {
00084             return tclass.mTagh == tH;
00085         }
00086         Tag tH;
00087     };
00088 
00089     template < class T >
00090     struct DtagP
00091     {
00092       // deprecation of unary_function
00093       typedef T argument_type;
00094       typedef bool result_type;
00095 
00096       public:
00097         DtagP( const damsel_handle& th )
00098         {
00099             tH = th;
00100         }
00101         bool operator()( const T& tclass )
00102         {
00103             return tclass.dTagh == tH;
00104         }
00105         damsel_handle tH;
00106     };
00107 
00108   private:
00109     //! Damsel library id
00110     damsel_library dmslLib;
00111 
00112     //! Damsel model id
00113     damsel_model dmslModel;
00114 
00115     //! Other conventional tags
00116     tinfo xcoordsTag, ycoordsTag, zcoordsTag, collFlagsTag, parentsTag, childrenTag;
00117 
00118     //! MOAB/damsel handles for dense [0], sparse [1], and conventional [2] tags
00119     std::vector< tinfo > tagMap;
00120 
00121     //! Damsel handle type used in (this build of) MOAB
00122     damsel_handle_type moabHandleType;
00123 };
00124 
00125 // This function doesn't do anything useful. It's just a nice
00126 // place to set a break point to determine why the reader fails.
00127 static inline ErrorCode error( ErrorCode rval )
00128 {
00129     return rval;
00130 }
00131 
00132 }  // namespace moab
00133 
00134 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines