VTK
ADIOSUtilities.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: ADIOSUtilities.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 #ifndef __ADIOSUtilities_h
16 #define __ADIOSUtilities_h
17 #ifndef __VTK_WRAP__
18 #ifndef VTK_WRAPPING_CXX
19 
20 #include <stdint.h>
21 
22 #include <cstddef>
23 
24 #include <complex>
25 #include <stdexcept>
26 #include <string>
27 
28 #include <adios_types.h>
29 
30 namespace ADIOS
31 {
32 
33 // Description:
34 // Retrieve and parse error messages generated by the ADIOS write system
35 class WriteError : public std::runtime_error
36 {
37 public:
38  WriteError(const std::string& msg = "");
39  virtual ~WriteError() throw() { }
40 
41  // Description:
42  // Test error codes for expected values. An exception is thrown with the
43  // appropriate error message if detected
44  template<typename T>
45  static void TestEq(const T& expected, const T& actual,
46  const std::string& msg = "")
47  {
48  if(actual != expected)
49  {
50  throw WriteError(msg);
51  }
52  }
53 
54  // Description:
55  // Test error codes for unexpected values. An exception is thrown with
56  // The appropriate error message if detected.
57  template<typename T>
58  static void TestNe(const T& notExpected, const T& actual,
59  const std::string& msg = "")
60  {
61  if(actual == notExpected)
62  {
63  throw WriteError(msg);
64  }
65  }
66 };
67 
68 // Description:
69 // Retrieve and parse error messages generated by the ADIOS read system
70 class ReadError : public std::runtime_error
71 {
72 public:
73  ReadError(const std::string& msg = "");
74  virtual ~ReadError() throw() { }
75 
76  // Description:
77  // Test error codes for expected values. An exception is thrown with the
78  // appropriate error message if detected
79  template<typename T>
80  static void TestEq(const T& expected, const T& actual,
81  const std::string& msg = "")
82  {
83  if(actual != expected)
84  {
85  throw ReadError(msg);
86  }
87  }
88 
89  // Description:
90  // Test error codes for unexpected values. An exception is thrown with
91  // The appropriate error message if detected.
92  template<typename T>
93  static void TestNe(const T& notExpected, const T& actual,
94  const std::string& msg = "")
95  {
96  if(actual == notExpected)
97  {
98  throw ReadError(msg);
99  }
100  }
101 };
102 
103 namespace Type
104 {
105 
106 // Description:
107 // Given a size in bytes, return the ADIOS signed integral type
108 template<size_t S> ADIOS_DATATYPES SizeToInt();
109 template<> ADIOS_DATATYPES SizeToInt<1>();
110 template<> ADIOS_DATATYPES SizeToInt<2>();
111 template<> ADIOS_DATATYPES SizeToInt<4>();
112 template<> ADIOS_DATATYPES SizeToInt<8>();
113 
114 // Description:
115 // Given a size in bytes, return the ADIOS unsigned integral type
116 template<size_t S> ADIOS_DATATYPES SizeToUInt();
117 template<> ADIOS_DATATYPES SizeToUInt<1>();
118 template<> ADIOS_DATATYPES SizeToUInt<2>();
119 template<> ADIOS_DATATYPES SizeToUInt<4>();
120 template<> ADIOS_DATATYPES SizeToUInt<8>();
121 
122 // Description:
123 // Map C and C++ primitive datatypes into ADIOS datatypes
124 template<typename TN>
125 ADIOS_DATATYPES NativeToADIOS();
126 template<> ADIOS_DATATYPES NativeToADIOS<int8_t>();
127 template<> ADIOS_DATATYPES NativeToADIOS<int16_t>();
128 template<> ADIOS_DATATYPES NativeToADIOS<int32_t>();
129 template<> ADIOS_DATATYPES NativeToADIOS<int64_t>();
130 template<> ADIOS_DATATYPES NativeToADIOS<uint8_t>();
131 template<> ADIOS_DATATYPES NativeToADIOS<uint16_t>();
132 template<> ADIOS_DATATYPES NativeToADIOS<uint32_t>();
133 template<> ADIOS_DATATYPES NativeToADIOS<uint64_t>();
134 template<> ADIOS_DATATYPES NativeToADIOS<float>();
135 template<> ADIOS_DATATYPES NativeToADIOS<double>();
136 template<> ADIOS_DATATYPES NativeToADIOS<std::complex<float> >();
137 template<> ADIOS_DATATYPES NativeToADIOS<std::complex<double> >();
138 template<> ADIOS_DATATYPES NativeToADIOS<std::string>();
139 
140 // Description:
141 // Map type sizes
142 size_t SizeOf(ADIOS_DATATYPES ta);
143 
144 // Description:
145 // Is the specified type an integer
146 bool IsInt(ADIOS_DATATYPES ta);
147 
148 } // End namespace Type
149 } // End namespace ADIOS
150 #endif
151 #endif
152 #endif
153 // VTK-HeaderTest-Exclude: ADIOSUtilities.h
ADIOS_DATATYPES SizeToInt< 1 >()
ADIOS_DATATYPES NativeToADIOS< int8_t >()
ADIOS_DATATYPES SizeToInt< 2 >()
bool IsInt(ADIOS_DATATYPES ta)
ADIOS_DATATYPES SizeToUInt< 8 >()
ADIOS_DATATYPES NativeToADIOS< uint8_t >()
ADIOS_DATATYPES SizeToInt()
static void TestNe(const T &notExpected, const T &actual, const std::string &msg="")
virtual ~WriteError()
ADIOS_DATATYPES NativeToADIOS< int64_t >()
WriteError(const std::string &msg="")
static void TestNe(const T &notExpected, const T &actual, const std::string &msg="")
ADIOS_DATATYPES NativeToADIOS< double >()
static void TestEq(const T &expected, const T &actual, const std::string &msg="")
ADIOS_DATATYPES SizeToInt< 4 >()
virtual ~ReadError()
ADIOS_DATATYPES NativeToADIOS< uint32_t >()
ADIOS_DATATYPES SizeToUInt< 2 >()
ADIOS_DATATYPES NativeToADIOS< float >()
ADIOS_DATATYPES SizeToUInt()
ADIOS_DATATYPES NativeToADIOS< uint64_t >()
ADIOS_DATATYPES NativeToADIOS< int32_t >()
ADIOS_DATATYPES NativeToADIOS< uint16_t >()
ADIOS_DATATYPES SizeToUInt< 1 >()
static void TestEq(const T &expected, const T &actual, const std::string &msg="")
ADIOS_DATATYPES SizeToInt< 8 >()
ADIOS_DATATYPES SizeToUInt< 4 >()
ADIOS_DATATYPES NativeToADIOS< int16_t >()
size_t SizeOf(ADIOS_DATATYPES ta)
ADIOS_DATATYPES NativeToADIOS()