1 /* 2 * Distributed under the OSI-approved Apache License, Version 2.0. See 3 * accompanying file Copyright.txt for details. 4 * 5 * ADIOSMacros.h : a set of helper macros used internally 6 * 7 * Created on: March 23, 2017 8 * Author: Chuck Atkins chuck.atkins@kitware.com 9 * William F Godoy godoywf@ornl.gov 10 */ 11 12 #ifndef ADIOS2_ADIOSMACROS_H 13 #define ADIOS2_ADIOSMACROS_H 14 15 #include <string> 16 17 #include "adios2/common/ADIOSTypes.h" 18 19 /** 20 <pre> 21 The ADIOS_FOREACH_TYPE_1ARG macro assumes the given argument is a macro which 22 takes a single argument that is a type and then inserts the given MACRO for 23 each of the known primitive types 24 25 An example of this might be to instantiate a template function for each 26 known type. For example: 27 28 template<typename T> int foo() { // some implementation of foo } 29 30 #define instantiate_foo(T) template int foo<T>(); 31 ADIOS_FOREACH_TYPE_1ARG(instantiate_foo) 32 #undef instantiate_foo 33 </pre> 34 */ 35 #define ADIOS2_FOREACH_ATTRIBUTE_PRIMITIVE_STDTYPE_1ARG(MACRO) \ 36 MACRO(int8_t) \ 37 MACRO(int16_t) \ 38 MACRO(int32_t) \ 39 MACRO(int64_t) \ 40 MACRO(uint8_t) \ 41 MACRO(uint16_t) \ 42 MACRO(uint32_t) \ 43 MACRO(uint64_t) \ 44 MACRO(float) \ 45 MACRO(double) \ 46 MACRO(long double) 47 48 #define ADIOS2_FOREACH_PRIMITIVE_STDTYPE_1ARG(MACRO) \ 49 ADIOS2_FOREACH_ATTRIBUTE_PRIMITIVE_STDTYPE_1ARG(MACRO) \ 50 MACRO(std::complex<float>) \ 51 MACRO(std::complex<double>) 52 53 #define ADIOS2_FOREACH_ATTRIBUTE_STDTYPE_1ARG(MACRO) \ 54 MACRO(std::string) \ 55 ADIOS2_FOREACH_PRIMITIVE_STDTYPE_1ARG(MACRO) 56 57 #define ADIOS2_FOREACH_STDTYPE_1ARG(MACRO) \ 58 MACRO(std::string) \ 59 ADIOS2_FOREACH_PRIMITIVE_STDTYPE_1ARG(MACRO) 60 61 #define ADIOS2_FOREACH_TYPE_1ARG(MACRO) \ 62 MACRO(std::string) \ 63 MACRO(char) \ 64 MACRO(signed char) \ 65 MACRO(unsigned char) \ 66 MACRO(short) \ 67 MACRO(unsigned short) \ 68 MACRO(int) \ 69 MACRO(unsigned int) \ 70 MACRO(long int) \ 71 MACRO(long long int) \ 72 MACRO(unsigned long int) \ 73 MACRO(unsigned long long int) \ 74 MACRO(float) \ 75 MACRO(double) \ 76 MACRO(long double) \ 77 MACRO(std::complex<float>) \ 78 MACRO(std::complex<double>) 79 80 #define ADIOS2_FOREACH_PRIMITIVE_TYPE_1ARG(MACRO) \ 81 MACRO(char) \ 82 MACRO(signed char) \ 83 MACRO(unsigned char) \ 84 MACRO(short) \ 85 MACRO(unsigned short) \ 86 MACRO(int) \ 87 MACRO(unsigned int) \ 88 MACRO(long int) \ 89 MACRO(long long int) \ 90 MACRO(unsigned long int) \ 91 MACRO(unsigned long long int) \ 92 MACRO(float) \ 93 MACRO(double) \ 94 MACRO(long double) \ 95 MACRO(std::complex<float>) \ 96 MACRO(std::complex<double>) 97 98 #define ADIOS2_FOREACH_COMPLEX_PRIMITIVE_TYPE_1ARG(MACRO) \ 99 MACRO(float) \ 100 MACRO(double) \ 101 MACRO(long double) 102 103 #define ADIOS2_FOREACH_CHAR_TYPE_1ARG(MACRO) \ 104 MACRO(char) \ 105 MACRO(signed char) \ 106 MACRO(unsigned char) 107 108 #define ADIOS2_FOREACH_NUMERIC_TYPE_1ARG(MACRO) \ 109 MACRO(short) \ 110 MACRO(unsigned short) \ 111 MACRO(int) \ 112 MACRO(unsigned int) \ 113 MACRO(long int) \ 114 MACRO(long long int) \ 115 MACRO(unsigned long int) \ 116 MACRO(unsigned long long int) \ 117 MACRO(float) \ 118 MACRO(double) \ 119 MACRO(long double) \ 120 MACRO(std::complex<float>) \ 121 MACRO(std::complex<double>) 122 123 #define ADIOS2_FOREACH_ZFP_TYPE_1ARG(MACRO) \ 124 MACRO(int32_t) \ 125 MACRO(int64_t) \ 126 MACRO(float) \ 127 MACRO(double) 128 129 #define ADIOS2_FOREACH_SZ_TYPE_1ARG(MACRO) \ 130 MACRO(float) \ 131 MACRO(double) 132 133 #define ADIOS2_FOREACH_MGARD_TYPE_1ARG(MACRO) MACRO(double) 134 135 #define ADIOS2_FOREACH_ATTRIBUTE_TYPE_1ARG(MACRO) \ 136 MACRO(std::string) \ 137 MACRO(char) \ 138 MACRO(signed char) \ 139 MACRO(unsigned char) \ 140 MACRO(short) \ 141 MACRO(unsigned short) \ 142 MACRO(int) \ 143 MACRO(unsigned int) \ 144 MACRO(long int) \ 145 MACRO(unsigned long int) \ 146 MACRO(long long int) \ 147 MACRO(unsigned long long int) \ 148 MACRO(float) \ 149 MACRO(double) \ 150 MACRO(long double) \ 151 MACRO(std::complex<float>) \ 152 MACRO(std::complex<double>) 153 154 #define ADIOS2_FOREACH_ATTRIBUTE_PRIMITIVE_TYPE_1ARG(MACRO) \ 155 MACRO(char) \ 156 MACRO(signed char) \ 157 MACRO(unsigned char) \ 158 MACRO(short) \ 159 MACRO(unsigned short) \ 160 MACRO(int) \ 161 MACRO(unsigned int) \ 162 MACRO(long int) \ 163 MACRO(unsigned long int) \ 164 MACRO(long long int) \ 165 MACRO(unsigned long long int) \ 166 MACRO(float) \ 167 MACRO(double) \ 168 MACRO(long double) \ 169 MACRO(std::complex<float>) \ 170 MACRO(std::complex<double>) 171 172 /** 173 <pre> 174 The ADIOS2_FOREACH_STDTYPE_2ARGS macro assumes the given argument is a macro 175 which takes two arguments, the first being a type, and the second being a 176 label for that type, i.e. std::complex<float> and CFloat. 177 178 An example of this might be to define a virtual method for each known 179 type, and since the method is virtual then it cannot be a template. 180 For example: 181 182 #define declare_foo(T,L) virtual const T& foo_## L (std::string bar); 183 ADIOS2_FOREACH_STDTYPE_2ARGS(declare_foo) 184 #undef declare_foo 185 186 is equivalent to: 187 188 virtual char& foo_Char(std::string bar); 189 virtual unsigned char& foo_UChar(std::string bar); 190 virtual short& foo_Short(std::string bar); 191 virtual unsigned short& foo_UShort(std::string bar); 192 ... 193 virtual std::complex<double>& foo_CDouble(std::string bar); 194 </pre> 195 */ 196 #define ADIOS2_FOREACH_ATTRIBUTE_STDTYPE_2ARGS(MACRO) \ 197 MACRO(std::string, string) \ 198 MACRO(int8_t, int8) \ 199 MACRO(uint8_t, uint8) \ 200 MACRO(int16_t, int16) \ 201 MACRO(uint16_t, uint16) \ 202 MACRO(int32_t, int32) \ 203 MACRO(uint32_t, uint32) \ 204 MACRO(int64_t, int64) \ 205 MACRO(uint64_t, uint64) \ 206 MACRO(float, float) \ 207 MACRO(double, double) \ 208 MACRO(long double, ldouble) \ 209 MACRO(std::complex<float>, cfloat) \ 210 MACRO(std::complex<double>, cdouble) 211 212 #define ADIOS2_FOREACH_PRIMITVE_STDTYPE_2ARGS(MACRO) \ 213 MACRO(int8_t, int8) \ 214 MACRO(uint8_t, uint8) \ 215 MACRO(int16_t, int16) \ 216 MACRO(uint16_t, uint16) \ 217 MACRO(int32_t, int32) \ 218 MACRO(uint32_t, uint32) \ 219 MACRO(int64_t, int64) \ 220 MACRO(uint64_t, uint64) \ 221 MACRO(float, float) \ 222 MACRO(double, double) \ 223 MACRO(long double, ldouble) \ 224 MACRO(std::complex<float>, cfloat) \ 225 MACRO(std::complex<double>, cdouble) 226 227 #define ADIOS2_FOREACH_STDTYPE_2ARGS(MACRO) \ 228 ADIOS2_FOREACH_ATTRIBUTE_STDTYPE_2ARGS(MACRO) 229 230 #define ADIOS2_CLASS_iterator \ 231 class iterator \ 232 { \ 233 public: \ 234 typedef iterator self_type; \ 235 typedef T value_type; \ 236 typedef T &reference; \ 237 typedef T *pointer; \ 238 typedef std::forward_iterator_tag iterator_category; \ 239 typedef int difference_type; \ 240 iterator(pointer ptr) : ptr_(ptr) {} \ 241 self_type operator++() \ 242 { \ 243 self_type i = *this; \ 244 ptr_++; \ 245 return i; \ 246 } \ 247 self_type operator++(int junk) \ 248 { \ 249 ptr_++; \ 250 return *this; \ 251 } \ 252 reference operator*() { return *ptr_; } \ 253 pointer operator->() { return ptr_; } \ 254 bool operator==(const self_type &rhs) { return ptr_ == rhs.ptr_; } \ 255 bool operator!=(const self_type &rhs) { return ptr_ != rhs.ptr_; } \ 256 \ 257 private: \ 258 pointer ptr_; \ 259 } 260 261 #define ADIOS2_iterators_functions(DATA_FUNCTION, SIZE_FUNCTION) \ 262 iterator begin() noexcept { return iterator(DATA_FUNCTION); } \ 263 iterator end() noexcept { return iterator(DATA_FUNCTION + SIZE_FUNCTION); } 264 265 #endif /* ADIOS2_ADIOSMACROS_H */ 266