Public Types

PtrTraits< ObjectType > Struct Template Reference

Meta-function that define smart pointer traits. More...

#include <keyvalue/value/PtrTraits.h>

List of all members.

Public Types

typedef ::boost::shared_ptr
< ObjectType > 
Type_
typedef ::boost::intrusive_ptr
< ObjectType > 
Type_
typedef ::boost::shared_ptr
< ObjectType > 
Type_

Detailed Description

template<typename ObjectType>
struct keyvalue::value::PtrTraits< ObjectType >

Meta-function that define smart pointer traits.

The core library creates various types of objects on the heap. Pointers to these objects go back and forth between KeyValue and the core library. To prevent memory leaks smart pointers (with shared semantics) must be used.

The type of smart pointer varies across different core libraries and this meta-function is used by KeyValue to know about the smart pointer used by the current core library.

The bridge library is then, responsible to provide the correct implementation. There should be a general implementation paramatrized on ObjectType, the type of object, and a specialization of it (when ObjectType is void) to define the type of generic pointer that can point to all relevant types of core library objects. For instance, suppose that all objects created by the core library derives from a common base class, say core::Polygon, and we want to use boost::shared_ptr. Then the general implementation and its specialization would be:

 namespace keyvalue {
 namespace value {
 
   template <typename objecttype>="">
   class PtrTraits {
     typedef boost::shared_ptr<ObjectType> Type_;
   };
 
   template <>
   class PtrTraits<void> {
     typedef boost::shared_ptr< ::core::Polygon> Type_;
   };
 
 } // namespace value
 } // namespace keyvalue
Parameters:
ObjectType : (template parameter) The type of pointed object.
Return values:
Type_ : The instantiation of the smart pointer template class for the ObjectType.