rtcArray2.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2009
00003  * Robert Bosch LLC
00004  * Research and Technology Center North America
00005  * Palo Alto, California
00006  *
00007  * All rights reserved.
00008  *
00009  *------------------------------------------------------------------------------
00010  * project ....: Autonomous Technologies
00011  * file .......: rtcArray2.h
00012  * authors ....: Benjamin Pitzer
00013  * organization: Robert Bosch LLC
00014  * creation ...: 08/16/2006
00015  * modified ...: $Date: 2009-01-21 18:19:16 -0800 (Wed, 21 Jan 2009) $
00016  * changed by .: $Author: benjaminpitzer $
00017  * revision ...: $Revision: 14 $
00018  */
00019 #ifndef RTC_ARRAY2_H
00020 #define RTC_ARRAY2_H
00021 
00022 //== INCLUDES ==================================================================
00023 #include "rtc/rtcMath.h"
00024 #include "rtc/rtcVec2.h"
00025 #include "rtc/rtcArray.h"
00026 
00027 //== NAMESPACES ================================================================
00028 namespace rtc {
00029 
00030 // Forward declarations
00031 template <class T, int K> class Array;  // K-dimensional array
00032 template <class T> class Array2;        // 2-dimensional array
00033 template <class T> class Vec2;          // 2d Vector
00034 
00038 template <class T>
00039 class Array2: public Array<T,2> {
00040 public:
00041   // Constructors/Destructor
00042   Array2();
00043   Array2(int rows, int columns);
00044   Array2(int rows, int columns, const T* d);
00045   Array2(int rows, int columns, const T a);
00046   Array2(const Array<T,2>& a);
00047 
00048   // Mutators
00049   void setSize(int rows, int cols);
00050 
00051   // Accessors
00052   int rows() const;
00053   int columns() const;
00054   T& at(int rows, int columns);
00055   const T& at(int rows, int columns) const;
00056   T& operator () (int rows, int columns);
00057   T operator () (int rows, int columns) const;
00058 
00059   // Helper functions
00060   int indexOf(int rows, int columns) const;
00061 
00062   // inherit member data and functions of parent
00063   using Array<T,2>::x;
00064   using Array<T,2>::reset;
00065   using Array<T,2>::operator ();
00066   using Array<T,2>::size;
00067   using Array<T,2>::setSize;
00068   using Array<T,2>::at;
00069 protected:
00070   // inherit member data and functions of parent
00071   using Array<T,2>::dim;
00072   using Array<T,2>::mul;
00073   using Array<T,2>::len;
00074 };
00075 
00076 // Declare a few common typdefs
00077 typedef Array2<bool> Array2b;
00078 typedef Array2<char> Array2c;
00079 typedef Array2<unsigned char> Array2uc;
00080 typedef Array2<int> Array2i;
00081 typedef Array2<float> Array2f;
00082 typedef Array2<double> Array2d;
00083 
00084 //==============================================================================
00085 // Array2<T>
00086 //==============================================================================
00087 
00088 // Constructors/Destructor
00089 
00092 template <class T>
00093 inline Array2<T>::Array2() : Array<T,2>() {}
00094 
00099 template <class T>
00100 inline Array2<T>::Array2(int rows, int columns) : Array<T,2>() {
00101   setSize(rows,columns);
00102 }
00103 
00109 template <class T>
00110 inline Array2<T>::Array2(int rows, int columns, const T* d) {
00111   setSize(rows,columns);
00112   Array<T,2>::set(d);
00113 }
00114 
00120 template <class T>
00121 inline Array2<T>::Array2(int rows, int columns, const T a) {
00122   setSize(rows,columns);
00123   Array<T,2>::set(a);
00124 }
00125 
00129 template <class T>
00130 inline Array2<T>::Array2(const Array<T,2>& a) : Array<T,2>(a) {
00131 }
00132 
00133 // Mutators
00134 
00139 template <class T>
00140 inline void Array2<T>::setSize(int rows, int columns) {
00141   Array<T,2>::setSize(Vec2i(rows,columns));
00142 }
00143 
00149 template <class T>
00150 inline T& Array2<T>::at(int row, int column) {
00151   return x[indexOf(row,column)];
00152 }
00153 
00159 template <class T>
00160 inline const T& Array2<T>::at(int row, int column) const {
00161   return x[indexOf(row,column)];
00162 }
00163 
00169 template <class T>
00170 inline T& Array2<T>::operator () (int row, int column) {
00171   return x[indexOf(row,column)];
00172 }
00173 
00179 template <class T>
00180 inline T Array2<T>::operator () (int row, int column) const {
00181   return x[indexOf(row,column)];
00182 }
00183 
00187 template <class T>
00188 inline int Array2<T>::rows() const {
00189   return Array<T,2>::dim[0];
00190 }
00191 
00195 template <class T>
00196 inline int Array2<T>::columns() const {
00197   return Array<T,2>::dim[1];
00198 }
00199 
00200 // Helper functions (used internally only)
00201 
00207 template <class T>
00208 inline int Array2<T>::indexOf(int row, int column) const {
00209 #if AR_CHECK_BOUNDS
00210   if (row<0 || row>=dim(0) || column<0 || column>=dim(1)) {
00211     std::stringstream ss;
00212     ss << "Array2: Error. Indices (" << row << ", " << column;
00213     ss << ") exceed bounds [0, ";
00214     ss << dim(0) << "] or [0, " << dim(1) << "].";
00215     ss << std::endl << std::flush;
00216     throw Exception(ss.str());
00217   }
00218 #endif
00219   return row*mul(0)+column;
00220 }
00221 
00222 //==============================================================================
00223 } // namespace rtc
00224 //==============================================================================
00225 #endif // RTC_ARRAY2_H defined
00226 //==============================================================================
00227 


rtc
Author(s): Benjamin Pitzer
autogenerated on Thu Jan 2 2014 11:04:53