DerivedValue.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
12 /*
13  * @file DerivedValue.h
14  * @date Jan 26, 2012
15  * @author Duy Nguyen Ta
16  */
17 
18 #pragma once
19 
20 #include <gtsam/base/Value.h>
21 #include <boost/make_shared.hpp>
22 
24 // The following includes windows.h in some MSVC versions, so we undef min, max, and ERROR
25 #include <boost/pool/singleton_pool.hpp>
26 
27 #ifdef min
28 #undef min
29 #endif
30 
31 #ifdef max
32 #undef max
33 #endif
34 
35 #ifdef ERROR
36 #undef ERROR
37 #endif
38 
40 
41 namespace rtabmap {
42 
43 template<class DERIVED>
44 class DerivedValue : public gtsam::Value {
45 
46 protected:
48 
49 public:
50 
51  virtual ~DerivedValue() {}
52 
58  virtual gtsam::Value* clone_() const {
59  void *place = boost::singleton_pool<PoolTag, sizeof(DERIVED)>::malloc();
60  DERIVED* ptr = new(place) DERIVED(static_cast<const DERIVED&>(*this));
61  return ptr;
62  }
63 
67  virtual void deallocate_() const {
68  this->~DerivedValue(); // Virtual destructor cleans up the derived object
69  boost::singleton_pool<PoolTag, sizeof(DERIVED)>::free((void*)this); // Release memory from pool
70  }
71 
76  return boost::make_shared<DERIVED>(static_cast<const DERIVED&>(*this));
77  }
78 
80  virtual bool equals_(const gtsam::Value& p, double tol = 1e-9) const {
81  // Cast the base class Value pointer to a derived class pointer
82  const DERIVED& derivedValue2 = dynamic_cast<const DERIVED&>(p);
83 
84  // Return the result of calling equals on the derived class
85  return (static_cast<const DERIVED*>(this))->equals(derivedValue2, tol);
86  }
87 
89  virtual gtsam::Value* retract_(const gtsam::Vector& delta) const {
90  // Call retract on the derived class
91  const DERIVED retractResult = (static_cast<const DERIVED*>(this))->retract(delta);
92 
93  // Create a Value pointer copy of the result
94  void* resultAsValuePlace = boost::singleton_pool<PoolTag, sizeof(DERIVED)>::malloc();
95  gtsam::Value* resultAsValue = new(resultAsValuePlace) DERIVED(retractResult);
96 
97  // Return the pointer to the Value base class
98  return resultAsValue;
99  }
100 
102  virtual gtsam::Vector localCoordinates_(const gtsam::Value& value2) const {
103  // Cast the base class Value pointer to a derived class pointer
104  const DERIVED& derivedValue2 = dynamic_cast<const DERIVED&>(value2);
105 
106  // Return the result of calling localCoordinates on the derived class
107  return (static_cast<const DERIVED*>(this))->localCoordinates(derivedValue2);
108  }
109 
111  virtual gtsam::Value& operator=(const gtsam::Value& rhs) {
112  // Cast the base class Value pointer to a derived class pointer
113  const DERIVED& derivedRhs = dynamic_cast<const DERIVED&>(rhs);
114 
115  // Do the assignment and return the result
116  return (static_cast<DERIVED*>(this))->operator=(derivedRhs);
117  }
118 
120  operator const DERIVED& () const {
121  return static_cast<const DERIVED&>(*this);
122  }
123 
125  operator DERIVED& () {
126  return static_cast<DERIVED&>(*this);
127  }
128 
129 protected:
133  // Nothing to do, do not call base class assignment operator
134  return *this;
135  }
136 
137 private:
139  struct PoolTag { };
140 
141 };
142 
143 } /* namespace gtsam */
DerivedValue< DERIVED > & operator=(const DerivedValue< DERIVED > &)
Definition: DerivedValue.h:132
virtual bool equals_(const gtsam::Value &p, double tol=1e-9) const
equals implementing generic Value interface
Definition: DerivedValue.h:80
virtual gtsam::Vector localCoordinates_(const gtsam::Value &value2) const
Generic Value interface version of localCoordinates.
Definition: DerivedValue.h:102
GLM_FUNC_DECL genType e()
virtual gtsam::Value * retract_(const gtsam::Vector &delta) const
Generic Value interface version of retract.
Definition: DerivedValue.h:89
virtual void deallocate_() const
Definition: DerivedValue.h:67
virtual gtsam::Value * clone_() const
Definition: DerivedValue.h:58
virtual gtsam::Value & operator=(const gtsam::Value &rhs)
Assignment operator.
Definition: DerivedValue.h:111
virtual boost::shared_ptr< gtsam::Value > clone() const
Definition: DerivedValue.h:75
Fake Tag struct for singleton pool allocator. In fact, it is never used!
Definition: DerivedValue.h:139


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Jan 23 2023 03:37:28