12 #include "RMF/config.h"
14 #include <boost/cstdint.hpp>
17 #if RMF_HAS_DEPRECATED_BACKENDS
34 struct ValueTraitsBase {
36 typedef std::vector<T> Types;
37 typedef T ArgumentType;
39 static bool get_are_equal(T a, T b) {
return a == b; }
43 struct ReferenceTraitsBase {
45 typedef std::vector<T> Types;
46 typedef const T& ArgumentType;
47 typedef const T& ReturnType;
51 struct Traits<
Int> :
public ValueTraitsBase<Int> {
52 static bool get_is_null_value(
const Type& t) {
return t == get_null_value(); }
53 static ReturnType get_null_value() {
54 return std::numeric_limits<Type>::max();
56 #if RMF_HAS_DEPRECATED_BACKENDS
57 typedef HDF5::IntTraits HDF5Traits;
58 typedef boost::int32_t AvroType;
60 static std::string get_tag() {
return "ki"; }
61 static std::string get_name() {
return "int"; }
65 struct Traits<
Float> :
public ValueTraitsBase<Float> {
66 static bool get_is_null_value(
const Type& t) {
67 return t >= std::numeric_limits<Float>::max();
69 static ReturnType get_null_value() {
70 return std::numeric_limits<Type>::infinity();
72 #if RMF_HAS_DEPRECATED_BACKENDS
73 typedef HDF5::FloatTraits HDF5Traits;
74 typedef double AvroType;
76 static bool get_are_equal(ArgumentType a, ArgumentType b) {
77 return std::abs(a - b) < .0000001 * std::abs(a + b) + .000000001;
79 static std::string get_tag() {
return "kf"; }
80 static std::string get_name() {
return "float"; }
84 struct Traits<
String> :
public ValueTraitsBase<String> {
85 static bool get_is_null_value(
const Type& t) {
return t.empty(); }
86 static ReturnType get_null_value() {
90 #if RMF_HAS_DEPRECATED_BACKENDS
91 typedef HDF5::StringTraits HDF5Traits;
92 typedef Type AvroType;
94 static std::string get_tag() {
return "ks"; }
95 static std::string get_name() {
return "string"; }
99 struct SequenceTraitsBase {
100 typedef std::vector<T> Type;
101 typedef std::vector<Type> Types;
102 typedef Type ReturnType;
103 typedef const Type& ArgumentType;
104 static bool get_is_null_value(
const Type& t) {
return t.empty(); }
105 static ReturnType get_null_value() {
109 static bool get_are_equal(ArgumentType a, ArgumentType b) {
110 if (a.size() != b.size())
return false;
111 for (
unsigned int i = 0; i < a.size(); ++i) {
112 if (!Traits<T>::get_are_equal(a[i], b[i]))
return false;
116 static std::string get_tag() {
return Traits<T>::get_tag() +
"s"; }
117 static std::string get_name() {
return Traits<T>::get_name() +
"s"; }
121 struct Traits<
Ints> :
public SequenceTraitsBase<Int> {
122 #if RMF_HAS_DEPRECATED_BACKENDS
123 typedef HDF5::IntsTraits HDF5Traits;
124 typedef std::vector<Traits<Int>::AvroType> AvroType;
129 struct Traits<
Floats> :
public SequenceTraitsBase<Float> {
130 #if RMF_HAS_DEPRECATED_BACKENDS
131 typedef HDF5::FloatsTraits HDF5Traits;
132 typedef std::vector<double> AvroType;
137 struct Traits<
Strings> :
public SequenceTraitsBase<String> {
138 #if RMF_HAS_DEPRECATED_BACKENDS
139 typedef HDF5::StringsTraits HDF5Traits;
140 typedef Type AvroType;
144 template <
unsigned int D>
145 class Traits<Vector<D> > :
public ReferenceTraitsBase<Vector<D> > {
146 static std::string make_tag() {
147 std::ostringstream oss;
151 static std::string make_name() {
152 std::ostringstream oss;
153 oss <<
"vector" << D;
158 static bool get_is_null_value(
const RMF_VECTOR<D>& t) {
159 return t[0] > std::numeric_limits<double>::max();
161 static const RMF_VECTOR<D>& get_null_value() {
162 static const RMF_VECTOR<D> null(
Floats(
163 D, std::numeric_limits<
typename Traits<Float>::Type>::infinity()));
166 static bool get_are_equal(
const RMF_VECTOR<D>& a,
const RMF_VECTOR<D>& b) {
167 for (
unsigned int i = 0; i < D; ++i) {
168 if (!Traits<Float>::get_are_equal(a[i], b[i]))
return false;
172 static std::string get_tag() {
173 static std::string tag = make_tag();
176 static std::string get_name() {
177 static std::string name = make_name();
182 template <
unsigned int D>
183 struct Traits<std::vector<Vector<D> > > :
public SequenceTraitsBase<
186 typedef Traits<Int> IntTraits;
187 typedef Traits<Float> FloatTraits;
188 typedef Traits<String> StringTraits;
189 typedef Traits<Ints> IntsTraits;
190 typedef Traits<Floats> FloatsTraits;
191 typedef Traits<Strings> StringsTraits;
192 typedef Traits<Vector<3> > Vector3Traits;
193 typedef Traits<Vector<4> > Vector4Traits;
194 typedef Traits<std::vector<Vector<3> > > Vector3sTraits;
195 typedef Traits<std::vector<Vector<4> > > Vector4sTraits;
207 typedef IntTraits IntTag;
208 typedef FloatTraits FloatTag;
209 typedef StringTraits StringTag;
210 typedef Vector3Traits Vector3Tag;
211 typedef Vector4Traits Vector4Tag;
212 typedef IntsTraits IntsTag;
213 typedef FloatsTraits FloatsTag;
214 typedef StringsTraits StringsTag;
215 typedef Vector3sTraits Vector3sTag;
216 typedef Vector4sTraits Vector4sTag;
222 struct Vector3Tag {};
223 struct Vector4Tag {};
226 struct StringsTag {};
227 struct Vector3sTag {};
228 struct Vector4sTag {};
Default implementation for types.h.
std::vector< String > Strings
std::vector< Float > Floats
Handle read/write of Model data from/to files.
Traits classes describing how RMF uses types for storing data.