Added clone() to Value

release/4.3a0
Richard Roberts 2012-07-09 20:17:49 +00:00
parent 8a8b27005f
commit dd8afd6527
2 changed files with 14 additions and 3 deletions

View File

@ -16,7 +16,7 @@
*/
#pragma once
#include <boost/make_shared.hpp>
#include <boost/pool/singleton_pool.hpp>
#include <gtsam/base/Value.h>
@ -37,7 +37,8 @@ public:
/**
* Create a duplicate object returned as a pointer to the generic Value interface.
* For the sake of performance, this function use singleton pool allocator instead of the normal heap allocator
* For the sake of performance, this function use singleton pool allocator instead of the normal heap allocator.
* The result must be deleted with Value::deallocate_, not with the 'delete' operator.
*/
virtual Value* clone_() const {
void *place = boost::singleton_pool<PoolTag, sizeof(DERIVED)>::malloc();
@ -53,6 +54,13 @@ public:
boost::singleton_pool<PoolTag, sizeof(DERIVED)>::free((void*)this);
}
/**
* Clone this value (normal clone on the heap, delete with 'delete' operator)
*/
virtual boost::shared_ptr<Value> clone() const {
return boost::make_shared<DERIVED>(static_cast<const DERIVED&>(*this));
}
/// equals implementing generic Value interface
virtual bool equals_(const Value& p, double tol = 1e-9) const {
// Cast the base class Value pointer to a derived class pointer

View File

@ -101,12 +101,15 @@ namespace gtsam {
class Value {
public:
/** Allocate and construct a clone of this value */
/** Clone this value in a special memory pool, must be deleted with Value::deallocate_, *not* with the 'delete' operator. */
virtual Value* clone_() const = 0;
/** Deallocate a raw pointer of this value */
virtual void deallocate_() const = 0;
/** Clone this value (normal clone on the heap, delete with 'delete' operator) */
virtual boost::shared_ptr<Value> clone() const = 0;
/** Compare this Value with another for equality. */
virtual bool equals_(const Value& other, double tol = 1e-9) const = 0;