cartobase  4.7.0
datatypetraits.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2 * Institut Federatif de Recherche 49
3 * CEA/NeuroSpin, Batiment 145,
4 * 91191 Gif-sur-Yvette cedex
5 * France
6 *
7 * This software is governed by the CeCILL-B license under
8 * French law and abiding by the rules of distribution of free software.
9 * You can use, modify and/or redistribute the software under the
10 * terms of the CeCILL-B license as circulated by CEA, CNRS
11 * and INRIA at the following URL "http://www.cecill.info".
12 *
13 * As a counterpart to the access to the source code and rights to copy,
14 * modify and redistribute granted by the license, users are provided only
15 * with a limited warranty and the software's author, the holder of the
16 * economic rights, and the successive licensors have only limited
17 * liability.
18 *
19 * In this respect, the user's attention is drawn to the risks associated
20 * with loading, using, modifying and/or developing or reproducing the
21 * software by the user in light of its specific status of free software,
22 * that may mean that it is complicated to manipulate, and that also
23 * therefore means that it is reserved for developers and experienced
24 * professionals having in-depth computer knowledge. Users are therefore
25 * encouraged to load and test the software's suitability as regards their
26 * requirements in conditions enabling the security of their systems and/or
27 * data to be ensured and, more generally, to use and operate it in the
28 * same conditions as regards security.
29 *
30 * The fact that you are presently reading this means that you have had
31 * knowledge of the CeCILL-B license and that you accept its terms.
32 */
33 
34 #ifndef CARTOBASE_TYPE_DATATYPETRAITS_H
35 #define CARTOBASE_TYPE_DATATYPETRAITS_H
36 
37 //--- cartobase --------------------------------------------------------------
38 #include <cartobase/type/types.h>
42 
43 
44 #define DATA_TYPE_TRAITS_DECLARE_SPECIALIZATION_SINGLE_CHANNEL( T, IS_SCALAR, LONG, HAS_BOOL_CONVERSION ) \
45 template <> \
46 struct DataTypeTraits< T > \
47 { \
48  public: \
49  typedef T ChannelType; \
50  typedef LONG LongType; \
51  \
52  static const bool is_scalar = IS_SCALAR; \
53  static const bool is_multichannel = false; \
54  static const bool has_bool_conversion = HAS_BOOL_CONVERSION; \
55  static const unsigned int channelcount = 1; \
56 }; \
57 
58 #define DATA_TYPE_TRAITS_DECLARE_SPECIALIZATION_MULTI_CHANNEL( T, IS_SCALAR, LONG, HAS_BOOL_CONVERSION ) \
59 template <> \
60 struct DataTypeTraits< T > \
61 { \
62  public: \
63  typedef T::ChannelType ChannelType; \
64  typedef LONG LongType; \
65  \
66  static const bool is_scalar = false; \
67  static const bool is_multichannel = true; \
68  static const bool has_bool_conversion = HAS_BOOL_CONVERSION; \
69  static const unsigned int channelcount = T::channelcount; \
70 }; \
71 
72 #define DATA_TYPE_TRAITS_DECLARE_SPECIALIZATION( T, IS_SCALAR, IS_MULTICHANNEL, LONG, HAS_BOOL_CONVERSION ) \
73  DATA_TYPE_TRAITS_DECLARE_SPECIALIZATION_##IS_MULTICHANNEL(T, IS_SCALAR, LONG, HAS_BOOL_CONVERSION) \
74 
75 #define DATA_TYPE_TRAITS_INSTANCIATE_SPECIALIZATION( T ) \
76  const bool carto::DataTypeTraits< T >::is_scalar; \
77  const bool carto::DataTypeTraits< T >::is_multichannel; \
78  const bool carto::DataTypeTraits< T >::has_bool_conversion; \
79  const unsigned int carto::DataTypeTraits< T >::channelcount; \
80 
81 #define DATA_TYPE_TRAITS_INSTANCIATE_TEMPLATE_SPECIALIZATION( T ) \
82  template<> const bool carto::DataTypeTraits< T >::is_scalar; \
83  template<> const bool carto::DataTypeTraits< T >::is_multichannel; \
84  template<> const bool carto::DataTypeTraits< T >::has_bool_conversion; \
85  template<> const unsigned int carto::DataTypeTraits< T >::channelcount; \
86 
87 
88 namespace carto {
89 
102  template<typename DataType>
104  {
105  public:
106  // Types definition
107  typedef Void ChannelType;
108  typedef DataType LongType;
109 
110  static const bool is_scalar = false;
111  static const bool is_multichannel = false;
112  static const bool has_bool_conversion = false;
113  static const unsigned int channelcount = 0;
114  };
115 
117  DATA_TYPE_TRAITS_DECLARE_SPECIALIZATION( bool, true, SINGLE_CHANNEL, uintmax_t, true )
118  DATA_TYPE_TRAITS_DECLARE_SPECIALIZATION( uint8_t, true, SINGLE_CHANNEL, uintmax_t, true )
119  DATA_TYPE_TRAITS_DECLARE_SPECIALIZATION( int8_t, true, SINGLE_CHANNEL, intmax_t, true )
120  DATA_TYPE_TRAITS_DECLARE_SPECIALIZATION( uint16_t, true, SINGLE_CHANNEL, uintmax_t, true )
121  DATA_TYPE_TRAITS_DECLARE_SPECIALIZATION( int16_t, true, SINGLE_CHANNEL, intmax_t, true )
122  DATA_TYPE_TRAITS_DECLARE_SPECIALIZATION( uint32_t, true, SINGLE_CHANNEL, uintmax_t, true )
123  DATA_TYPE_TRAITS_DECLARE_SPECIALIZATION( int32_t, true, SINGLE_CHANNEL, intmax_t, true )
124  DATA_TYPE_TRAITS_DECLARE_SPECIALIZATION( unsigned long, true, SINGLE_CHANNEL, uintmax_t, true )
125  DATA_TYPE_TRAITS_DECLARE_SPECIALIZATION( long, true, SINGLE_CHANNEL, intmax_t, true )
126  DATA_TYPE_TRAITS_DECLARE_SPECIALIZATION( unsigned long long, true, SINGLE_CHANNEL, uintmax_t, true )
127  DATA_TYPE_TRAITS_DECLARE_SPECIALIZATION( long long, true, SINGLE_CHANNEL, intmax_t, true )
128  DATA_TYPE_TRAITS_DECLARE_SPECIALIZATION( float, true, SINGLE_CHANNEL, double, true )
129  DATA_TYPE_TRAITS_DECLARE_SPECIALIZATION( double, true, SINGLE_CHANNEL, double, true )
130  DATA_TYPE_TRAITS_DECLARE_SPECIALIZATION( cfloat, false, SINGLE_CHANNEL, cdouble, true )
131  DATA_TYPE_TRAITS_DECLARE_SPECIALIZATION( cdouble, false, SINGLE_CHANNEL, cdouble, true )
132 
134  DATA_TYPE_TRAITS_DECLARE_SPECIALIZATION( carto::VoxelRGB, false, MULTI_CHANNEL, carto::VoxelRGB, true )
135  DATA_TYPE_TRAITS_DECLARE_SPECIALIZATION( carto::VoxelRGBA, false, MULTI_CHANNEL, carto::VoxelRGBA, true )
136  DATA_TYPE_TRAITS_DECLARE_SPECIALIZATION( carto::VoxelHSV, false, MULTI_CHANNEL, carto::VoxelHSV, true )
137 
138 }
139 
140 
141 #endif
RGBA Value.
static const unsigned int channelcount
static const bool is_multichannel
HSV Value.
Definition: voxelhsv.h:67
std::complex< float > cfloat
Complex 32 bits float.
Definition: types.h:96
RGB Value.
Definition: voxelrgb_decl.h:71
Properties of data types.
static const bool is_scalar
static const bool has_bool_conversion
#define DATA_TYPE_TRAITS_DECLARE_SPECIALIZATION(T, IS_SCALAR, IS_MULTICHANNEL, LONG, HAS_BOOL_CONVERSION)
std::complex< double > cdouble
Complex 64 bits float.
Definition: types.h:98
Void does not contain anything.
Definition: types.h:60