Image Component Library (ICL)
FixedArray.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLUtils/src/ICLUtils/FixedArray.h **
10 ** Module : ICLUtils **
11 ** Authors: Christof Elbrechter **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 
31 #pragma once
32 
33 #include <ICLUtils/CompatMacros.h>
34 
35 namespace icl{
36  namespace utils{
38 
44  template<class T,unsigned int DIM>
45  struct FixedArray{
46  T m_data[DIM];
47 
49  T &operator[](unsigned int idx) { return m_data[idx]; }
50 
52  const T &operator[](unsigned int idx) const { return m_data[idx]; }
53  };
54 
56  template<class T>
57  struct FixedArray<T, 1u>{
58  union{
59  T m_data[1];
60  T x;
61  };
62 
65 
67  FixedArray(const T &x) : x(x){}
68 
70  T &operator[](unsigned int idx) { return m_data[idx]; }
71 
73  const T &operator[](unsigned int idx) const { return m_data[idx]; }
74 
76  inline operator T() const{
77  return x;
78  }
79  };
80 
82  template<class T>
83  struct FixedArray<T, 2u>{
84  union{
85  T m_data[2];
86  struct { T x; T y; };
87  };
88 
91 
93  FixedArray(const T &x, const T &y) : x(x),y (y){}
94 
96  T &operator[](unsigned int idx) { return m_data[idx]; }
97 
99  const T &operator[](unsigned int idx) const { return m_data[idx]; }
100  };
101 
102 
104  template<class T>
105  struct FixedArray<T, 3u>{
106 
109 
111  FixedArray(const T &x, const T &y, const T &z) : x(x), y(y), z(z){}
112 
113  union{
114  T m_data[3];
115  struct { T x; T y; T z; };
116  };
118  T &operator[](unsigned int idx) { return m_data[idx]; }
119 
121  const T &operator[](unsigned int idx) const { return m_data[idx]; }
122  };
123 
125  template<class T>
126  struct FixedArray<T, 4u>{
127 
130 
132  FixedArray(const T &x, const T &y, const T &z, const T &w) : x(x), y(y), z(z), w(w){}
133 
134  union{
135  T m_data[4];
136  struct {
137  T x;
138  T y;
139  T z;
140  union {
141  T h;
142  T w;
143  };
144  };
145  };
146 
148  T &operator[](unsigned int idx) { return m_data[idx]; }
149 
151  const T &operator[](unsigned int idx) const { return m_data[idx]; }
152  };
153 
154  } // namespace utils
155 } // namespace icl
156 
FixedArray(const T &x, const T &y, const T &z, const T &w)
constructor with given values, x, y, z and w
Definition: FixedArray.h:132
T m_data[DIM]
Definition: FixedArray.h:46
const T & operator[](unsigned int idx) const
index access operator (const)
Definition: FixedArray.h:52
undocument this line if you encounter any issues!
Definition: Any.h:37
FixedArray()
empty constructor (leaving data uninitialized)
Definition: FixedArray.h:129
T & operator[](unsigned int idx)
index access operator
Definition: FixedArray.h:96
Fixed C++-array wrapper class for data handling.
Definition: FixedArray.h:45
T z
Definition: FixedArray.h:115
T & operator[](unsigned int idx)
index access operator
Definition: FixedArray.h:70
FixedArray(const T &x, const T &y)
constructor with given values, x and y
Definition: FixedArray.h:93
FixedArray()
empty constructor (leaving data uninitialized)
Definition: FixedArray.h:108
T h
Definition: FixedArray.h:141
const T & operator[](unsigned int idx) const
index access operator (const)
Definition: FixedArray.h:73
FixedArray()
empty constructor (leaving data uninitialized)
Definition: FixedArray.h:64
const T & operator[](unsigned int idx) const
index access operator (const)
Definition: FixedArray.h:99
T x
Definition: FixedArray.h:137
T & operator[](unsigned int idx)
index access operator
Definition: FixedArray.h:118
T y
Definition: FixedArray.h:138
FixedArray(const T &x, const T &y, const T &z)
constructor with given values, x, y and z
Definition: FixedArray.h:111
FixedArray()
empty constructor (leaving data uninitialized)
Definition: FixedArray.h:90
T x
Definition: FixedArray.h:60
T & operator[](unsigned int idx)
index access operator
Definition: FixedArray.h:49
T w
Definition: FixedArray.h:142
FixedArray(const T &x)
constructor with given value x
Definition: FixedArray.h:67
const T & operator[](unsigned int idx) const
index access operator (const)
Definition: FixedArray.h:151
T & operator[](unsigned int idx)
index access operator
Definition: FixedArray.h:148
T z
Definition: FixedArray.h:139
T y
Definition: FixedArray.h:86
const T & operator[](unsigned int idx) const
index access operator (const)
Definition: FixedArray.h:121