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 
18 #include <stdint.h>
19 
20 #include <cstddef>
21 
22 #include <complex>
23 #include <stdexcept>
24 #include <string>
25 
26 #include <adios_types.h>
27 
28 namespace ADIOS
29 {
30 
31 // Description:
32 // Retrieve and parse error messages generated by the ADIOS write system
33 class WriteError : public std::runtime_error
34 {
35 public:
36  WriteError(const std::string& msg = "");
37  virtual ~WriteError() throw() { }
38 
39  // Description:
40  // Test error codes for expected values. An exception is thrown with the
41  // appropriate error message if detected
42  template<typename T>
43  static void TestEq(const T& expected, const T& actual,
44  const std::string& msg = "")
45  {
46  if(actual != expected)
47  {
48  throw WriteError(msg);
49  }
50  }
51 
52  // Description:
53  // Test error codes for unexpected values. An exception is thrown with
54  // The appropriate error message if detected.
55  template<typename T>
56  static void TestNe(const T& notExpected, const T& actual,
57  const std::string& msg = "")
58  {
59  if(actual == notExpected)
60  {
61  throw WriteError(msg);
62  }
63  }
64 };
65 
66 // Description:
67 // Retrieve and parse error messages generated by the ADIOS read system
68 class ReadError : public std::runtime_error
69 {
70 public:
71  ReadError(const std::string& msg = "");
72  virtual ~ReadError() throw() { }
73 
74  // Description:
75  // Test error codes for expected values. An exception is thrown with the
76  // appropriate error message if detected
77  template<typename T>
78  static void TestEq(const T& expected, const T& actual,
79  const std::string& msg = "")
80  {
81  if(actual != expected)
82  {
83  throw ReadError(msg);
84  }
85  }
86 
87  // Description:
88  // Test error codes for unexpected values. An exception is thrown with
89  // The appropriate error message if detected.
90  template<typename T>
91  static void TestNe(const T& notExpected, const T& actual,
92  const std::string& msg = "")
93  {
94  if(actual == notExpected)
95  {
96  throw ReadError(msg);
97  }
98  }
99 };
100 
101 namespace Type
102 {
103 
104 // Description:
105 // Given a size in bytes, return the ADIOS signed integral type
106 template<size_t S> ADIOS_DATATYPES SizeToInt();
107 template<> ADIOS_DATATYPES SizeToInt<1>();
108 template<> ADIOS_DATATYPES SizeToInt<2>();
109 template<> ADIOS_DATATYPES SizeToInt<4>();
110 template<> ADIOS_DATATYPES SizeToInt<8>();
111 
112 // Description:
113 // Given a size in bytes, return the ADIOS unsigned integral type
114 template<size_t S> ADIOS_DATATYPES SizeToUInt();
115 template<> ADIOS_DATATYPES SizeToUInt<1>();
116 template<> ADIOS_DATATYPES SizeToUInt<2>();
117 template<> ADIOS_DATATYPES SizeToUInt<4>();
118 template<> ADIOS_DATATYPES SizeToUInt<8>();
119 
120 // Description:
121 // Map C and C++ primitive datatypes into ADIOS datatypes
122 template<typename TN>
123 ADIOS_DATATYPES NativeToADIOS();
124 template<> ADIOS_DATATYPES NativeToADIOS<int8_t>();
125 template<> ADIOS_DATATYPES NativeToADIOS<int16_t>();
126 template<> ADIOS_DATATYPES NativeToADIOS<int32_t>();
127 template<> ADIOS_DATATYPES NativeToADIOS<int64_t>();
128 template<> ADIOS_DATATYPES NativeToADIOS<uint8_t>();
129 template<> ADIOS_DATATYPES NativeToADIOS<uint16_t>();
130 template<> ADIOS_DATATYPES NativeToADIOS<uint32_t>();
131 template<> ADIOS_DATATYPES NativeToADIOS<uint64_t>();
132 template<> ADIOS_DATATYPES NativeToADIOS<float>();
133 template<> ADIOS_DATATYPES NativeToADIOS<double>();
134 template<> ADIOS_DATATYPES NativeToADIOS<std::complex<float> >();
135 template<> ADIOS_DATATYPES NativeToADIOS<std::complex<double> >();
136 template<> ADIOS_DATATYPES NativeToADIOS<std::string>();
137 
138 // Description:
139 // Map type sizes
140 size_t SizeOf(ADIOS_DATATYPES ta);
141 
142 // Description:
143 // Is the specified type an integer
144 bool IsInt(ADIOS_DATATYPES ta);
145 
146 } // End namespace Type
147 } // End namespace ADIOS
148 #endif
149 // 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="")
ReadError(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()