XdmfArrayType.hpp 8.5 KB
Newer Older
Kenneth Leiter's avatar
Kenneth Leiter committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*****************************************************************************/
/*                                    XDMF                                   */
/*                       eXtensible Data Model and Format                    */
/*                                                                           */
/*  Id : XdmfArrayType.hpp                                                   */
/*                                                                           */
/*  Author:                                                                  */
/*     Kenneth Leiter                                                        */
/*     kenneth.leiter@arl.army.mil                                           */
/*     US Army Research Laboratory                                           */
/*     Aberdeen Proving Ground, MD                                           */
/*                                                                           */
/*     Copyright @ 2011 US Army Research Laboratory                          */
/*     All Rights Reserved                                                   */
/*     See Copyright.txt for details                                         */
/*                                                                           */
/*     This software is distributed WITHOUT ANY WARRANTY; without            */
/*     even the implied warranty of MERCHANTABILITY or FITNESS               */
/*     FOR A PARTICULAR PURPOSE.  See the above copyright notice             */
/*     for more information.                                                 */
/*                                                                           */
/*****************************************************************************/

24 25 26
#ifndef XDMFARRAYTYPE_HPP_
#define XDMFARRAYTYPE_HPP_

27
// C Compatible Includes
28
#include "XdmfCore.hpp"
29 30 31 32

#ifdef __cplusplus

// Includes
33
#include "XdmfItemProperty.hpp"
34
#include <vector>
35 36

/**
37 38
 * @brief Property describing what types of values an XdmfArray
 * contains.
39
 *
40
 * XdmfArrayType specifies the types of values stored in an XdmfArray.
41 42
 * A specific XdmfArrayType can be created by calling one of the
 * static methods in the class, i.e. XdmfArrayType::Int32().
43
 *
44
 * Example of use:
45 46 47 48
 *
 * C++
 *
 * @dontinclude ExampleXdmfArrayType.cpp
49 50
 * @skipline //#getType
 * @until //#getType
51 52 53 54
 *
 * Python
 *
 * @dontinclude XdmfExampleArrayType.py
55 56
 * @skipline #//getType
 * @until #//getType
57
 *
58
 * Xdmf supports the following attribute types:
59 60 61 62 63 64 65 66 67 68
 *   Uninitialized
 *   Int8
 *   Int16
 *   Int32
 *   Int64
 *   Float32
 *   Float64
 *   UInt8
 *   UInt16
 *   UInt32
Kenneth Leiter's avatar
Kenneth Leiter committed
69
 *   String
70
 */
71
class XDMFCORE_EXPORT XdmfArrayType : public XdmfItemProperty {
72

73
public:
74

75
  virtual ~XdmfArrayType();
76

77
  friend class XdmfArray;
78
  friend class XdmfCoreItemFactory;
79

80 81 82 83 84 85
  enum Format {
    Unsigned,
    Signed,
    Float
  };

86
  // Supported XdmfArrayTypes
87 88 89 90 91 92 93 94 95 96
  static shared_ptr<const XdmfArrayType> Uninitialized();
  static shared_ptr<const XdmfArrayType> Int8();
  static shared_ptr<const XdmfArrayType> Int16();
  static shared_ptr<const XdmfArrayType> Int32();
  static shared_ptr<const XdmfArrayType> Int64();
  static shared_ptr<const XdmfArrayType> Float32();
  static shared_ptr<const XdmfArrayType> Float64();
  static shared_ptr<const XdmfArrayType> UInt8();
  static shared_ptr<const XdmfArrayType> UInt16();
  static shared_ptr<const XdmfArrayType> UInt32();
Kenneth Leiter's avatar
Kenneth Leiter committed
97
  static shared_ptr<const XdmfArrayType> String();
98

99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
  /**
   * Compares the two types given and returns a type that is compatible with both.
   *
   * Example of use:
   *
   * C++
   *
   * @skipline //#comparePrecision
   * @until //#comparePrecision
   *
   * Python
   *
   * @skipline #//comparePrecision
   * @until #//comparePrecision
   *
114 115 116
   * @param     type1   The first type to be compared
   * @param     type2   The second type to be compared
   * @return            The type that is compatible with both provided types
117 118 119
   */
  static shared_ptr<const XdmfArrayType> comparePrecision(shared_ptr<const XdmfArrayType> type1, shared_ptr<const XdmfArrayType> type2);

120
  /**
121 122
   * Get the data size, in bytes, of the value associated with this
   * array type.
123
   *
124 125 126 127
   * Example of use:
   *
   * C++
   *
128
   * @dontinclude ExampleXdmfArrayType.cpp
129 130
   * @skipline //#getElementSize
   * @until //#getElementSize
131 132 133
   *
   * Python
   *
134
   * @dontinclude XdmfExampleArrayType.py
135 136
   * @skipline #//getElementSize
   * @until #//getElementSize
137
   *
138
   * @return    The data size, in bytes.
139 140
   */
  unsigned int getElementSize() const;
141

142
  /**
143
   * Gets whether the data type is floating point or not.
144
   *
145 146 147 148
   * Example of use:
   *
   * C++
   *
149
   * @dontinclude ExampleXdmfArrayType.cpp
150 151
   * @skipline //#getIsFloat
   * @until //#getIsFloat
152 153 154
   *
   * Python
   *
155
   * @dontinclude XdmfExampleArrayType.py
156 157
   * @skipline #//getIsFloat
   * @until #//getIsFloat
158
   *
159
   * @return    Whether the data type is signed.
160
   */
161
  bool getIsFloat() const;
162

163
  /**
164
   * Gets whether the data type is signed or not.
165 166 167 168 169 170
   *
   * Example of use:
   *
   * C++
   *
   * @dontinclude ExampleXdmfArrayType.cpp
171 172
   * @skipline //#getIsSigned
   * @until //#getIsSigned
173 174 175 176
   *
   * Python
   *
   * @dontinclude XdmfExampleArrayType.py
177 178
   * @skipline #//getIsSigned
   * @until #//getIsSigned
179 180 181
   *
   * @return    Whether the data type is signed.
   */
182
  bool getIsSigned() const;
183 184

  /**
185
   * Get the name of the data type.
186 187 188 189 190 191
   *
   * Example of use:
   *
   * C++
   *
   * @dontinclude ExampleXdmfArrayType.cpp
192 193
   * @skipline //#getName
   * @until //#getName
194 195 196 197
   *
   * Python
   *
   * @dontinclude XdmfExampleArrayType.py
198 199
   * @skipline #//getName
   * @until #//getName
200
   *
201
   * @return    The name of the data type.
202
   */
203
  std::string getName() const;
204

205 206
  void
  getProperties(std::map<std::string, std::string> & collectedProperties) const;
207

208
protected:
209

210
  /**
211 212 213
   * Protected constructor for XdmfArrayType. The constructor is
   * protected because all array types supported by Xdmf should be
   * accessed through more specific static methods that construct
214 215 216 217 218
   * XdmfArrayTypes - i.e. XdmfArrayType::Float64().
   *
   * @param name the name of the XdmfArrayType to construct.
   * @param precision the precision, in bytes, of the XdmfArrayType to
   * construct.
219
   * @param typeFormat The format description of the XdmfArrayType.
220 221
   */
  XdmfArrayType(const std::string & name,
222 223
                const unsigned int precision,
                const Format typeFormat);
224

225 226 227 228
  static std::map<std::string, std::map<unsigned int ,shared_ptr<const XdmfArrayType>(*)()> > mArrayDefinitions;

  static void InitTypes();

229
private:
230

231 232
  XdmfArrayType(const XdmfArrayType &); // Not implemented.
  void operator=(const XdmfArrayType &); // Not implemented.
233

234
  static shared_ptr<const XdmfArrayType>
235
  New(const std::map<std::string, std::string> & itemProperties);
236

237 238 239
  const std::string mName;
  const unsigned int mPrecision;
  std::string mPrecisionString;
240
  Format mTypeFormat;
241 242 243 244 245 246 247 248 249
  const char * mTypeId;

  // Allows for up to 16 byte sizes for unsigned, signed, and floating point types
  // The vector is actually larger than that to allow for the string and uninitialized types
  static std::vector<shared_ptr<const XdmfArrayType> > mTypes;
  // Due to uninitialized taking position 0 the size of the array is actually one over the max size
  static unsigned int mCurrentMaxSize;
  // Map of typeid to index in mTypes
  static std::map<std::string, shared_ptr<const XdmfArrayType> > mTypeIdMap;
250 251
};

252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
#endif

#define XDMF_ARRAY_TYPE_INT8    0
#define XDMF_ARRAY_TYPE_INT16   1
#define XDMF_ARRAY_TYPE_INT32   2
#define XDMF_ARRAY_TYPE_INT64   3
#define XDMF_ARRAY_TYPE_UINT8   4
#define XDMF_ARRAY_TYPE_UINT16  5
#define XDMF_ARRAY_TYPE_UINT32  6
#define XDMF_ARRAY_TYPE_FLOAT32 7
#define XDMF_ARRAY_TYPE_FLOAT64 8

#ifdef __cplusplus
extern "C" {
#endif

// These simply return the values defined above
XDMFCORE_EXPORT int XdmfArrayTypeInt8();
XDMFCORE_EXPORT int XdmfArrayTypeInt16();
XDMFCORE_EXPORT int XdmfArrayTypeInt32();
XDMFCORE_EXPORT int XdmfArrayTypeInt64();
XDMFCORE_EXPORT int XdmfArrayTypeFloat32();
XDMFCORE_EXPORT int XdmfArrayTypeFloat64();
XDMFCORE_EXPORT int XdmfArrayTypeUInt8();
XDMFCORE_EXPORT int XdmfArrayTypeUInt16();
XDMFCORE_EXPORT int XdmfArrayTypeUInt32();

XDMFCORE_EXPORT int XdmfArrayTypeComparePrecision(int type1, int type2, int * status);

XDMFCORE_EXPORT int XdmfArrayTypeGetElementSize(int type, int * status);

XDMFCORE_EXPORT int XdmfArrayTypeGetIsFloat(int type, int * status);

XDMFCORE_EXPORT int XdmfArrayTypeGetIsSigned(int type, int * status);

XDMFCORE_EXPORT char * XdmfArrayTypeGetName(int type, int * status);

#ifdef __cplusplus
}
#endif

293
#endif /* XDMFARRAYTYPE_HPP_ */