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.
DynamicType.h
1 /*
2 GRT MIT License
3 Copyright (c) <2012> <Nicholas Gillian, Media Lab, MIT>
4 
5 Permission is hereby granted, free of charge, to any person obtaining a copy of this software
6 and associated documentation files (the "Software"), to deal in the Software without restriction,
7 including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
9 subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included in all copies or substantial
12 portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15 LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
18 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 */
20 
21 #ifndef GRT_DYNAMIC_TYPE_HEADER
22 #define GRT_DYNAMIC_TYPE_HEADER
23 
24 #include "GRTTypedefs.h"
25 #include <memory>
26 
27 GRT_BEGIN_NAMESPACE
28 
30 public:
31  DynamicType():data(NULL){
32  }
33 
34  DynamicType( const DynamicType &rhs ):data(NULL){
35  this->data = rhs.data;
36  }
37 
38  ~DynamicType(){
39  reset();
40  }
41 
42  DynamicType& operator=(const DynamicType &rhs){
43  if( this != &rhs){
44  this->data = rhs.data;
45  }
46  return *this;
47  }
48 
49  template<typename T>
50  T& get(){
51  return *std::static_pointer_cast<T>( data );
52  }
53 
54  template<typename T>
55  const T& get() const {
56  return *std::static_pointer_cast<T>( data );
57  }
58 
59  template<typename T>
60  T get() const {
61  return *std::static_pointer_cast<T>( data );
62  }
63 
64  template<typename T>
65  bool set( const T &newData ){
66  data = std::make_shared< T >( newData );
67  return true;
68  }
69 
70  bool reset(){
71  data.reset();
72  return true;
73  }
74 
75 private:
76  std::shared_ptr<void> data;
77 };
78 
79 GRT_END_NAMESPACE
80 
81 #endif //GRT_HEADER_GUARD