Image Component Library (ICL)
|
00001 /******************************************************************** 00002 ** Image Component Library (ICL) ** 00003 ** ** 00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld ** 00005 ** Neuroinformatics Group ** 00006 ** Website: www.iclcv.org and ** 00007 ** http://opensource.cit-ec.de/projects/icl ** 00008 ** ** 00009 ** File : ICLUtils/src/ICLUtils/FixedArray.h ** 00010 ** Module : ICLUtils ** 00011 ** Authors: Christof Elbrechter ** 00012 ** ** 00013 ** ** 00014 ** GNU LESSER GENERAL PUBLIC LICENSE ** 00015 ** This file may be used under the terms of the GNU Lesser General ** 00016 ** Public License version 3.0 as published by the ** 00017 ** ** 00018 ** Free Software Foundation and appearing in the file LICENSE.GPL ** 00019 ** included in the packaging of this file. Please review the ** 00020 ** following information to ensure the license requirements will ** 00021 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt ** 00022 ** ** 00023 ** The development of this software was supported by the ** 00024 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. ** 00025 ** The Excellence Cluster EXC 277 is a grant of the Deutsche ** 00026 ** Forschungsgemeinschaft (DFG) in the context of the German ** 00027 ** Excellence Initiative. ** 00028 ** ** 00029 ********************************************************************/ 00030 00031 #pragma once 00032 00033 namespace icl{ 00034 namespace utils{ 00036 00042 template<class T,unsigned int DIM> 00043 struct FixedArray{ 00044 T m_data[DIM]; 00045 00047 T &operator[](unsigned int idx) { return m_data[idx]; } 00048 00050 const T &operator[](unsigned int idx) const { return m_data[idx]; } 00051 }; 00052 00054 template<class T> 00055 struct FixedArray<T,1u>{ 00056 union{ 00057 T m_data[1]; 00058 T x; 00059 }; 00060 00062 FixedArray(){} 00063 00065 FixedArray(const T &x) : x(x){} 00066 00068 T &operator[](unsigned int idx) { return m_data[idx]; } 00069 00071 const T &operator[](unsigned int idx) const { return m_data[idx]; } 00072 }; 00073 00075 template<class T> 00076 struct FixedArray<T,2u>{ 00077 union{ 00078 T m_data[2]; 00079 struct { T x; T y; }; 00080 }; 00081 00083 FixedArray(){} 00084 00086 FixedArray(const T &x, const T &y) : x(x),y (y){} 00087 00089 T &operator[](unsigned int idx) { return m_data[idx]; } 00090 00092 const T &operator[](unsigned int idx) const { return m_data[idx]; } 00093 }; 00094 00095 00097 template<class T> 00098 struct FixedArray<T,3u>{ 00099 00101 FixedArray(){} 00102 00104 FixedArray(const T &x, const T &y, const T &z) : x(x), y(y), z(z){} 00105 00106 union{ 00107 T m_data[3]; 00108 struct { T x; T y; T z; }; 00109 }; 00111 T &operator[](unsigned int idx) { return m_data[idx]; } 00112 00114 const T &operator[](unsigned int idx) const { return m_data[idx]; } 00115 }; 00116 00118 template<class T> 00119 struct FixedArray<T,4u>{ 00120 00122 FixedArray(){} 00123 00125 FixedArray(const T &x, const T &y, const T &z, const T &w) : x(x), y(y), z(z), w(w){} 00126 00127 union{ 00128 T m_data[4]; 00129 struct { 00130 T x; 00131 T y; 00132 T z; 00133 union { 00134 T h; 00135 T w; 00136 }; 00137 }; 00138 }; 00139 }; 00140 00141 } // namespace utils 00142 } // namespace icl 00143