FotoSHOCK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
ValueType.hpp
1 /*
2  * Copyright 2013 Lukas Jirkovsky
3  *
4  * This file is part of FotoSHOCKcore.
5  *
6  * FotoSHOCKcore is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, version 3 of the License.
9  *
10  * FotoSHOCKcore is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with FotoSHOCKcore. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef VALUETYPE_H
20 #define VALUETYPE_H
21 
22 #include "ColorSpace.hpp"
23 
24 #include <stdint.h>
25 #include <limits>
26 
27 namespace FotoSHOCKcore {
28 
30 
48 class ValueType {
49 public:
51  enum Enum {value_ANY, value_ANYINT, value_ANYFLOAT, value_SAME,
52  value_uint1, value_uint8, value_uint16, value_uint32, value_uint64,
53  value_float, value_double};
54 
55  friend class ValueTypeEnum;
56 
58 
62  : m_ID(value_ANY), m_bits(0), m_formatter(0) {}
64  ValueType(const ValueType& other) = default;
66  ValueType& operator=(const ValueType& other) = default;
67 
69  bool operator==(const ValueType& other) {return m_ID == other.m_ID;};
71  bool operator!=(const ValueType& other) {return !(*this == other);};
72 
74 
78  constexpr operator Enum() const {return m_ID;};
80  constexpr unsigned int bits() const {return m_bits;};
82  constexpr cmsUInt32Number cmsFormatter() const {return m_formatter;};
83 protected:
85  constexpr ValueType(const Enum v, const unsigned int bit, const cmsUInt32Number formatter)
86  : m_ID(v), m_bits(bit), m_formatter(formatter) {}
87 private:
88  Enum m_ID;
89  unsigned int m_bits;
90  cmsUInt32Number m_formatter;
91 };
92 
94 
99 public:
101  static constexpr ValueType ANY = ValueType(ValueType::value_ANY, 0, 0);
103  static constexpr ValueType ANYINT = ValueType(ValueType::value_ANYINT, 0, 0);
105  static constexpr ValueType ANYFLOAT = ValueType(ValueType::value_ANYFLOAT, 0, 0);
107  static constexpr ValueType SAME = ValueType(ValueType::value_SAME, 0, 0);
108 
110  static constexpr ValueType uint1 = ValueType(ValueType::value_uint1, 1, BYTES_SH(sizeof(bool)));
112  static constexpr ValueType uint8 = ValueType(ValueType::value_uint8, 8, BYTES_SH(sizeof(uint8_t)));
114  static constexpr ValueType uint16 = ValueType(ValueType::value_uint16, 16, BYTES_SH(sizeof(uint16_t)));
116  static constexpr ValueType uint32 = ValueType(ValueType::value_uint32, 32, BYTES_SH(sizeof(uint32_t)));
118  static constexpr ValueType uint64 = ValueType(ValueType::value_uint64, 64, BYTES_SH(sizeof(uint64_t)));
119 
121  static constexpr ValueType floatval = ValueType(ValueType::value_float, 32, FLOAT_SH(1) | BYTES_SH(4));
123  static constexpr ValueType doubleval = ValueType(ValueType::value_double, 64, FLOAT_SH(1) | BYTES_SH(0));
124 };
125 
127 
135 template <typename ValueDataType>
137  public:
139  typedef ValueDataType Type;
140 
142  static const Type min() {
143  return std::numeric_limits<ValueDataType>::min();
144  }
146  static const Type max() {
147  return std::numeric_limits<ValueDataType>::max();
148  }
149 };
150 
152 
169 template <ValueType::Enum format>
171 };
172 
173 template <>
174 class ValueTypeInfo<ValueType::value_uint1> : public ValueTypeInfoBase<bool> {
175  public:
176  typedef int_fast8_t SignedPromote;
177  typedef uint_fast8_t UnsignedPromote;
178 };
179 
180 template <>
181 class ValueTypeInfo<ValueType::value_uint8> : public ValueTypeInfoBase<uint8_t> {
182  public:
183  typedef int_fast16_t SignedPromote;
184  typedef uint_fast16_t UnsignedPromote;
185 };
186 
187 template <>
188 class ValueTypeInfo<ValueType::value_uint16> : public ValueTypeInfoBase<uint16_t> {
189  public:
190  typedef int_fast32_t SignedPromote;
191  typedef uint_fast32_t UnsignedPromote;
192 };
193 
194 template <>
195 class ValueTypeInfo<ValueType::value_uint32> : public ValueTypeInfoBase<uint32_t> {
196  public:
197  typedef int_fast64_t SignedPromote;
198  typedef uint_fast64_t UnsignedPromote;
199 };
200 
201 template <>
202 class ValueTypeInfo<ValueType::value_uint64> : public ValueTypeInfoBase<uint64_t> {
203  public:
204  typedef int_fast64_t SignedPromote;
205  typedef uint_fast64_t UnsignedPromote;
206 };
207 
208 template <>
209 class ValueTypeInfo<ValueType::value_float> : public ValueTypeInfoBase<float> {
210  public:
211  typedef double SignedPromote;
212  typedef double UnsignedPromote;
213 };
214 
215 template <>
216 class ValueTypeInfo<ValueType::value_double> : public ValueTypeInfoBase<double> {
217  public:
218  typedef double SignedPromote;
219  typedef double UnsignedPromote;
220 };
221 
223 
233 #define case_ANYINT \
234  case FotoSHOCKcore::ValueType::value_uint1: \
235  FORMAT_DO_STH(FotoSHOCKcore::ValueTypeEnum::uint1, FotoSHOCKcore::ValueTypeInfo<FotoSHOCKcore::ValueType::value_uint1>::Type); \
236  break; \
237  case FotoSHOCKcore::ValueType::value_uint8: \
238  FORMAT_DO_STH(FotoSHOCKcore::ValueTypeEnum::uint8, FotoSHOCKcore::ValueTypeInfo<FotoSHOCKcore::ValueType::value_uint8>::Type); \
239  break; \
240  case FotoSHOCKcore::ValueType::value_uint16: \
241  FORMAT_DO_STH(FotoSHOCKcore::ValueTypeEnum::uint16, FotoSHOCKcore::ValueTypeInfo<FotoSHOCKcore::ValueType::value_uint16>::Type); \
242  break; \
243  case FotoSHOCKcore::ValueType::value_uint32: \
244  FORMAT_DO_STH(FotoSHOCKcore::ValueTypeEnum::uint32, FotoSHOCKcore::ValueTypeInfo<FotoSHOCKcore::ValueType::value_uint32>::Type); \
245  break; \
246  case FotoSHOCKcore::ValueType::value_uint64: \
247  FORMAT_DO_STH(FotoSHOCKcore::ValueTypeEnum::uint64, FotoSHOCKcore::ValueTypeInfo<FotoSHOCKcore::ValueType::value_uint64>::Type); \
248  break
249 
251 
254 #define case_ANYFLOAT \
255  case FotoSHOCKcore::ValueType::value_float: \
256  FORMAT_DO_STH(FotoSHOCKcore::ValueTypeEnum::floatval, FotoSHOCKcore::ValueTypeInfo<FotoSHOCKcore::ValueType::value_float>::Type); \
257  break; \
258  case FotoSHOCKcore::ValueType::value_double: \
259  FORMAT_DO_STH(FotoSHOCKcore::ValueTypeEnum::doubleval, FotoSHOCKcore::ValueTypeInfo<FotoSHOCKcore::ValueType::value_double>::Type); \
260  break
261 
263 
266 #define case_ANY \
267  case_ANYINT; \
268  case_ANYFLOAT; \
269  default: \
270  break
271 
272 }
273 
274 #endif