Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

CdbCPtr< P, CLOSE_POLICY > Class Template Reference

Smart counted pointer class supporting the automatic close policy. More...

#include <CdbCPtr.hh>

Inheritance diagram for CdbCPtr< P, CLOSE_POLICY >:

CdbCPtrBase< P > List of all members.

Public Types

typedef P element_type
 This is the type of objects pointed through this smart pointer.

typedef CLOSE_POLICY close_policy
 This is the type of the close policy.


Public Member Functions

 CdbCPtr (P *ptr=0)
 The constructor.

 CdbCPtr (const CdbCPtr< P, CLOSE_POLICY > &thePtr)
 The copy constructor.

 ~CdbCPtr ()
 The destructor.

CdbCPtr & operator= (const CdbCPtr< P, CLOSE_POLICY > &thePtr)
 Asignment operator.

CdbCPtr & operator= (P *ptr)
 Asignment operator.

P & operator * () const
 Dereference operator.

P * operator-> () const
 The arrow operator.

bool operator== (const CdbCPtr< P, CLOSE_POLICY > &thePtr) const
 The comparision operator.

bool operator!= (const CdbCPtr< P, CLOSE_POLICY > &thePtr) const
 The not-equal operator.

bool operator== (const P *ptr) const
 The comparision operator.

bool operator!= (const P *ptr) const
 The not-equal operator.

bool isNull () const
 Explicit check if the pointer does point onto 0.

P * get () const
 Return a non-const pointer to the pointed object.

bool unique () const
 Check if this smart pointer is the only clients of the held pointer.


Detailed Description

template<class P, class CLOSE_POLICY = CdbDoNotClosePolicy<P>>
class CdbCPtr< P, CLOSE_POLICY >

Smart counted pointer class supporting the automatic close policy.

The is a non-intrusive implementation that allocates an additional int and pointer for every counted object.

The close policy is provided through an additional policy class. The only method we expect from the policy class is:


     static void CLOSE_POLICY::close( P* ptr );
 

It's up to the developer of this class how it will interract with the pointee object in order to "close" its instances.

By default, the "CdbDoNotClosePolicy" policy class will be used.

Definition at line 33 of file CdbCPtr.hh.


Member Typedef Documentation

template<class P, class CLOSE_POLICY = CdbDoNotClosePolicy<P>>
typedef CLOSE_POLICY CdbCPtr< P, CLOSE_POLICY >::close_policy
 

This is the type of the close policy.

The concrete type will be available at the instantiation of the current template class.

Definition at line 49 of file CdbCPtr.hh.

template<class P, class CLOSE_POLICY = CdbDoNotClosePolicy<P>>
typedef P CdbCPtr< P, CLOSE_POLICY >::element_type
 

This is the type of objects pointed through this smart pointer.

The concrete type will be available at the instantiation of the current template class.

Definition at line 42 of file CdbCPtr.hh.


Constructor & Destructor Documentation

template<class P, class CLOSE_POLICY>
CdbCPtr< P, CLOSE_POLICY >::CdbCPtr P *    ptr = 0
 

The constructor.

This is the normal and default constructor. It will take the ownership of specified pointer and initialize the internal counter to 1 if a non-null pointer is passed.

Definition at line 18 of file CdbCPtr.cc.

template<class P, class CLOSE_POLICY>
CdbCPtr< P, CLOSE_POLICY >::CdbCPtr const CdbCPtr< P, CLOSE_POLICY > &    thePtr
 

The copy constructor.

This constructor initializes the current instance to share the counter object with the specified pointer. This will also increment by 1 the number of smart pointers pointing onto the poentee, if this is not a 0 pointer.

Definition at line 31 of file CdbCPtr.cc.

References CdbCPtr< P, CLOSE_POLICY >::_myCounter.

template<class P, class CLOSE_POLICY>
CdbCPtr< P, CLOSE_POLICY >::~CdbCPtr  
 

The destructor.

Decrement the number of clients for the pointee. If we're the last smart pointer then:

  • close the object. This operation is done through the supplied (as a template parameter) policy class.

  • destroy the pointee. Here we're assuming that its destructor is available for us.

Definition at line 25 of file CdbCPtr.cc.


Member Function Documentation

template<class P, class CLOSE_POLICY>
P * CdbCPtr< P, CLOSE_POLICY >::get   const
 

Return a non-const pointer to the pointed object.

Note, that this does not transfer the ownership over the pointed object.

Definition at line 108 of file CdbCPtr.cc.

Referenced by CdbTranslatorsDict::add(), main(), CdbRooDb::storeObject(), and CdbRooRoVectorCollection_SmartPointerPolicy< T >::to_plain_pointer().

template<class P, class CLOSE_POLICY>
bool CdbCPtr< P, CLOSE_POLICY >::isNull   const
 

Explicit check if the pointer does point onto 0.

This operation is equivalent to the "operator==((const P*)0 )".

An example:

   // Initialize a smart pointer to a real object of class A.
     CdbCPtr<A,...> aSomePtr( new A( ));

   // Compare this pointer with specified pointer.
     if( !aSomePtr.isNull( )) {
         // Okay, the pointer is pointing onto something usefull.
     }
 

Returns:
the result of comparision

Definition at line 101 of file CdbCPtr.cc.

References CdbCPtr< P, CLOSE_POLICY >::operator==().

Referenced by CdbTranslatorsDict::add(), CdbRooRoVectorCollectionR< T, STORAGE_POLICY >::addElement(), CdbNTupleAppend(), CdbNTupleCopy(), CdbNTupleGlue(), CdbNTupleMerge(), CdbSQLApiCondition::CdbSQLApiCondition(), CdbSQLApiFolder::CdbSQLApiFolder(), CdbSQLCluster::CdbSQLCluster(), CdbSQLClusterIncrement::CdbSQLClusterIncrement(), CdbSQLCondition::CdbSQLCondition(), CdbSQLConditionAtFolder::CdbSQLConditionAtFolder(), CdbSQLFolder::CdbSQLFolder(), CdbSQLOrigin::CdbSQLOrigin(), CdbSQLOriginalObject::CdbSQLOriginalObject(), CdbSQLPartition::CdbSQLPartition(), CdbSQLPartitionIncrement::CdbSQLPartitionIncrement(), CdbSQLRevision::CdbSQLRevision(), CdbSQLView::CdbSQLView(), CdbSQLVisibleObject::CdbSQLVisibleObject(), CdbBdb2RooPayloadConversionFwk::doConversion(), CdbMySQLQueryUtils::execute_query(), CdbSQLOrigin::find_next_final_partition(), CdbMySQLOrigin::find_next_partition(), CdbSQLApiCondition::findObject(), Cdb::findTranslator(), CdbSQLFolder::fullPathName(), CdbRooDb::initialize(), CdbRooRoVectorCollection_SmartPointerPolicy< T >::is_null(), main(), CdbNTuplePrintImpl< NTUPLE, CONVERTER >::print(), CdbRooDb::setDefaultDatabase(), CdbMySQLCondition::store_object(), CdbRooDb::storeObject(), and CdbRooNTupleConversionImpl_Helper< PERSISTENT, T, NCOL, ELEMENT_CONVERSION_RULES >::to_transient().

template<class P, class CLOSE_POLICY>
P & CdbCPtr< P, CLOSE_POLICY >::operator *   const
 

Dereference operator.

Return a reference to the pointed object.

Here is a trivial example on how to use this operator:

   // This is a simple class whose objects will be
   // pointed through the smart pointer.
     class A ... {
     public:
         void foo( );
     };

   // Initialize smart pointer to point onto a new object.
   // Remember, that the smart pointer will take ownership
   // over this object.
     CdbCPtr<A,SomePolicy> aPtr( new A( ));

   // Do something usefull
     (*Aptr).foo( );   // 
 

Definition at line 58 of file CdbCPtr.cc.

template<class P, class CLOSE_POLICY>
bool CdbCPtr< P, CLOSE_POLICY >::operator!= const P *    ptr const
 

The not-equal operator.

See also:
CdbCPtr::operator==( const P* ptr )

Definition at line 94 of file CdbCPtr.cc.

References CdbCPtr< P, CLOSE_POLICY >::operator==().

template<class P, class CLOSE_POLICY>
bool CdbCPtr< P, CLOSE_POLICY >::operator!= const CdbCPtr< P, CLOSE_POLICY > &    thePtr const
 

The not-equal operator.

See also:
CdbCPtr::operator==( CdbCPtr& thePtr )

Definition at line 80 of file CdbCPtr.cc.

References CdbCPtr< P, CLOSE_POLICY >::operator==().

template<class P, class CLOSE_POLICY>
P * CdbCPtr< P, CLOSE_POLICY >::operator->   const
 

The arrow operator.

This operator is meant to provide access to the members of the pointed object in the same way if it were the regular pointer.

Here is a trivial example on how to use this operator:

   // This is a simple class whose objects will be
   // pointed through the smart pointer.
     class A ... {
     public:
         void foo( );
     };

   // Initialize smart pointer to point onto a new object.
   // Remember, that the smart pointer will take ownership
   // over this object.
     CdbCPtr<A,SomePolicy> aPtr( new A( ));

   // Do something usefull
     APtr->foo( );   // 
 

Definition at line 65 of file CdbCPtr.cc.

template<class P, class CLOSE_POLICY>
CdbCPtr< P, CLOSE_POLICY > & CdbCPtr< P, CLOSE_POLICY >::operator= P *    ptr
 

Asignment operator.

Drop the currently hold pointee. And take ownership ower the specified pointee object. Set the total number of its clients to 1.

Definition at line 49 of file CdbCPtr.cc.

template<class P, class CLOSE_POLICY>
CdbCPtr< P, CLOSE_POLICY > & CdbCPtr< P, CLOSE_POLICY >::operator= const CdbCPtr< P, CLOSE_POLICY > &    thePtr
 

Asignment operator.

Drop the currently hold pointee. And borrow the counter object from the right-hand smart pointer object and increment by 1the number of clients for the pointee object (if this is not the 0).

Definition at line 38 of file CdbCPtr.cc.

References CdbCPtr< P, CLOSE_POLICY >::_myCounter.

template<class P, class CLOSE_POLICY>
bool CdbCPtr< P, CLOSE_POLICY >::operator== const P *    ptr const
 

The comparision operator.

This operator will compare a smart pointer with a regular pointer to see if the smart one points to the same object as the regular one. It will also return true if both pointers are pointinig to 0.

Note, that the primarily use of this operator is to check if the smart pointer is pointing to 0. The other cases should not be possible because smart pointer must be the only way to point objects.

It's also important to note, that because of the restricted syntax of the comparision operator in the class's scope, it's only possible to specify the regular pointer on the righ-hand side of the comparision as it's shown in a code example below. The reverse order can be added later for concrete instantiations of the smart pointer.

An example:

   // Initialize a smart pointer to a real object of class A.
     CdbCPtr<A,...> aSomePtr( new A( ));
     A*             ptr = ...;

   // Compare this pointer with specified pointer.
     if( aSomePtr == ptr ) {
         ...
     }
 

Returns:
the result of comparision

Definition at line 87 of file CdbCPtr.cc.

template<class P, class CLOSE_POLICY>
bool CdbCPtr< P, CLOSE_POLICY >::operator== const CdbCPtr< P, CLOSE_POLICY > &    thePtr const
 

The comparision operator.

This operator will compare two smart pointers if they both point onto the same object. It will also return true if both smart pointers are pointinig to 0.

An example:

   // Initialize two smart pointers in different ways: the first one
   // will point to 0, and the second one - to a real object of class A.
     CdbCPtr<A,...> aNullPtr;
     CdbCPtr<A,...> aSomePtr( new A( ));

   // Compare the pointers
     if( aSomePtr == aNullPtr ) {
         ...
     }
 

Returns:
the result of comparision

Definition at line 72 of file CdbCPtr.cc.

References CdbCPtr< P, CLOSE_POLICY >::_myCounter.

Referenced by CdbCPtr< P, CLOSE_POLICY >::isNull(), and CdbCPtr< P, CLOSE_POLICY >::operator!=().

template<class P, class CLOSE_POLICY>
bool CdbCPtr< P, CLOSE_POLICY >::unique   const
 

Check if this smart pointer is the only clients of the held pointer.

Returns:
true if this is the only client

Definition at line 115 of file CdbCPtr.cc.


The documentation for this class was generated from the following files:
Generated on Mon Dec 5 18:22:21 2005 for CDB by doxygen1.3-rc3