GestureRecognitionToolkit  Version: 0.2.5
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  unsigned int 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  unsigned int N = 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  unsigned int 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  unsigned int N = rhs.size();
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  unsigned int 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 fill(const T &value){
176 
177  const unsigned int N = this->size();
178 
179  if( N == 0 ) return false;
180 
181  std::fill(this->begin(),this->end(),value);
182 
183  return true;
184  }
185 
192  bool setAll(const T &value){
193  return fill(value);
194  }
195 
201  inline UINT getSize() const{ return static_cast<UINT>(this->size()); }
202 
208  T* getData() {
209  if( this->size() == 0 ) return NULL;
210  return &(*this)[0];
211  }
212 
218  const T* getData() const {
219  if( this->size() == 0 ) return NULL;
220  return &(*this)[0];
221  }
222 
223 protected:
224 };
225 
226 GRT_END_NAMESPACE
227 
228 #endif //GRT_VECTOR_HEADER
bool setAll(const T &value)
Definition: Vector.h:192
virtual bool resize(const unsigned int size)
Definition: Vector.h:133
UINT getSize() const
Definition: Vector.h:201
Vector(const std::vector< T > &rhs)
Definition: Vector.h:80
Vector & operator=(const std::vector< T > &rhs)
Definition: Vector.h:116
bool fill(const T &value)
Definition: Vector.h:175
const T * getData() const
Definition: Vector.h:218
Vector & operator=(const Vector &rhs)
Definition: Vector.h:99
virtual ~Vector()
Definition: Vector.h:91
T * getData()
Definition: Vector.h:208
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