Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
DamselUtil.hpp
Go to the documentation of this file.
1 #ifndef DAMSEL_UTIL_HPP
2 #define DAMSEL_UTIL_HPP
3 
4 #include "moab/Forward.hpp"
5 #include "moab/ErrorHandler.hpp"
6 #include "DebugOutput.hpp"
7 
8 #include "damsel.h"
9 #include "damsel-internal.h"
10 
11 // Some macros to handle error checking (cribbed from WriteHDF5).
12 // All macros contain a "return" statement. These macros are coded with a do if while
13 // to allow statements calling them to be terminated with a ;
14 #define CHK_DMSL_ERR( A, B ) \
15  do \
16  { \
17  if( DMSL_OK.id != ( A ).id ) \
18  { \
19  MB_SET_ERR_CONT( B ); \
20  return error( MB_FAILURE ); \
21  } \
22  } while( false )
23 
24 #define CHK_DMSL_ERR_NM( A ) \
25  do \
26  { \
27  if( DMSL_OK.id != ( A ).id ) \
28  { \
29  MB_CHK_ERR_CONT( MB_FAILURE ); \
30  return error( MB_FAILURE ); \
31  } \
32  } while( false )
33 
34 namespace moab
35 {
36 
38 {
39  public:
40  friend class WriteDamsel;
41  friend class ReadDamsel;
42 
43  //! Needs to be a constructor to initialize dtom_data_type
44  DamselUtil();
45 
46  static damsel_data_type mtod_data_type[MB_MAX_DATA_TYPE + 1];
47 
48  static enum DataType dtom_data_type[DAMSEL_DATA_TYPE_PREDEFINED_WATERMARK + 1];
49 
50  static enum damsel_entity_type mtod_entity_type[MBMAXTYPE + 1];
51 
52  static enum EntityType dtom_entity_type[DAMSEL_ENTITY_TYPE_ALL_TYPES + 1];
53 
54  //! Convert handles in a container to a range; assumes EntityHandle and Damsel
55  //! entity handles are the same size
56  static ErrorCode container_to_range( damsel_model m, damsel_container& cont, Range& range );
57 
58  //! struct to hold information on damsel/moab tags
59  class tinfo
60  {
61  public:
62  tinfo( Tag mt, damsel_handle dt, TagType tt ) : mTagh( mt ), dTagh( dt ), tagType( tt ) {}
63  tinfo() : mTagh( 0 ), dTagh( 0 ), tagType( MB_TAG_ANY ) {}
64 
66  damsel_handle dTagh;
68  };
69 
70  template < class T >
71  struct MtagP
72  {
73  // deprecation of unary_function
74  typedef T argument_type;
75  typedef bool result_type;
76 
77  public:
78  MtagP( const Tag& th )
79  {
80  tH = th;
81  }
82  bool operator()( const T& tclass )
83  {
84  return tclass.mTagh == tH;
85  }
87  };
88 
89  template < class T >
90  struct DtagP
91  {
92  // deprecation of unary_function
93  typedef T argument_type;
94  typedef bool result_type;
95 
96  public:
97  DtagP( const damsel_handle& th )
98  {
99  tH = th;
100  }
101  bool operator()( const T& tclass )
102  {
103  return tclass.dTagh == tH;
104  }
105  damsel_handle tH;
106  };
107 
108  private:
109  //! Damsel library id
110  damsel_library dmslLib;
111 
112  //! Damsel model id
113  damsel_model dmslModel;
114 
115  //! Other conventional tags
117 
118  //! MOAB/damsel handles for dense [0], sparse [1], and conventional [2] tags
119  std::vector< tinfo > tagMap;
120 
121  //! Damsel handle type used in (this build of) MOAB
122  damsel_handle_type moabHandleType;
123 };
124 
125 // This function doesn't do anything useful. It's just a nice
126 // place to set a break point to determine why the reader fails.
127 static inline ErrorCode error( ErrorCode rval )
128 {
129  return rval;
130 }
131 
132 } // namespace moab
133 
134 #endif