GestureRecognitionToolkit  Version: 0.1.0
The Gesture Recognition Toolkit (GRT) is a cross-platform, open-source, c++ machine learning library for real-time gesture recognition.
Vector.h
Go to the documentation of this file.
1 
10 /*
11  GRT MIT License
12  Copyright (c) <2012> <Nicholas Gillian, Media Lab, MIT>
13 
14  Permission is hereby granted, free of charge, to any person obtaining a copy of this software
15  and associated documentation files (the "Software"), to deal in the Software without restriction,
16  including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
17  and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
18  subject to the following conditions:
19 
20  The above copyright notice and this permission notice shall be included in all copies or substantial
21  portions of the Software.
22 
23  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24  LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28  */
29 
30 #ifndef GRT_VECTOR_HEADER
31 #define GRT_VECTOR_HEADER
32 
33 #include <iostream>
34 #include <iterator> // std::front_inserter
35 #include <algorithm> // std::copy
36 #include <vector>
37 #include "../Util/GRTTypedefs.h"
38 
39 GRT_BEGIN_NAMESPACE
40 
41 template <class T> class Vector : public std::vector< T >{
42 public:
46  //Vector(){}
47 
53  Vector( const unsigned int size = 0 ):std::vector< T >(size){}
54 
60  Vector( const unsigned int size, const T &value ):std::vector< T >(size, value){}
61 
67  Vector( const Vector &rhs ){
68  UINT N = rhs.getSize();
69  if( N > 0 ){
70  this->resize( N );
71  std::copy( rhs.begin(), rhs.end(), this->begin() );
72  }else this->clear();
73  }
74 
80  Vector( const std::vector< T > &rhs ){
81  UINT N = (UINT)rhs.size();
82  if( N > 0 ){
83  this->resize( N );
84  std::copy( rhs.begin(), rhs.end(), this->begin() );
85  }else this->clear();
86  }
87 
91  virtual ~Vector(){ }
92 
99  Vector& operator=(const Vector &rhs){
100  if(this!=&rhs){
101  UINT N = rhs.getSize();
102  if( N > 0 ){
103  this->resize( N );
104  std::copy( rhs.begin(), rhs.end(), this->begin() );
105  }else this->clear();
106  }
107  return *this;
108  }
109 
116  Vector& operator=(const std::vector< T > &rhs){
117  if(this!=&rhs){
118  UINT N = rhs.getSize();
119  if( N > 0 ){
120  this->resize( N );
121  std::copy( rhs.begin(), rhs.end(), this->begin() );
122  }else this->clear();
123  }
124  return *this;
125  }
126 
133  virtual bool resize( const unsigned int size ){
134  std::vector< T >::resize( size );
135  return getSize() == size;
136  }
137 
145  virtual bool resize( const unsigned int size, const T& value ){
146  std::vector< T >::resize( size, value );
147  return getSize() == size;
148  }
149 
156  virtual bool copy( const Vector<T> &rhs ){
157 
158  if( this != &rhs ){
159  UINT N = rhs.getSize();
160  if( N > 0 ){
161  this->resize( N );
162  std::copy( rhs.begin(), rhs.end(), this->begin() );
163  }
164  }
165 
166  return true;
167  }
168 
175  bool setAll(const T &value){
176 
177  const size_t N = this->size();
178 
179  if( N == 0 ) return false;
180 
181  T *data = &(*this)[0];
182  for(size_t i=0; i<N; i++)
183  data[i] = value;
184 
185  return true;
186  }
187 
193  inline unsigned int getSize() const{ return (unsigned int)this->size(); }
194 
200  T* getData() {
201  if( this->size() == 0 ) return NULL;
202  return &(*this)[0];
203  }
204 
210  const T* getData() const {
211  if( this->size() == 0 ) return NULL;
212  return &(*this)[0];
213  }
214 
215 protected:
216  //std::vector< T > data;
217 };
218 
219 GRT_END_NAMESPACE
220 
221 #endif //GRT_VECTOR_HEADER
bool setAll(const T &value)
Definition: Vector.h:175
virtual bool resize(const unsigned int size)
Definition: Vector.h:133
unsigned int getSize() const
Definition: Vector.h:193
Vector(const std::vector< T > &rhs)
Definition: Vector.h:80
Vector & operator=(const std::vector< T > &rhs)
Definition: Vector.h:116
const T * getData() const
Definition: Vector.h:210
Vector & operator=(const Vector &rhs)
Definition: Vector.h:99
virtual ~Vector()
Definition: Vector.h:91
T * getData()
Definition: Vector.h:200
Vector(const unsigned int size, const T &value)
Definition: Vector.h:60
Definition: Vector.h:41
Vector(const Vector &rhs)
Definition: Vector.h:67
virtual bool resize(const unsigned int size, const T &value)
Definition: Vector.h:145
Vector(const unsigned int size=0)
Definition: Vector.h:53
virtual bool copy(const Vector< T > &rhs)
Definition: Vector.h:156