Made to Order Software Corporation Logo

odbcpp: odbcpp::object Class Reference

Base class used to handle smart pointers. More...

#include <object.h>

Inheritance diagram for odbcpp::object:

List of all members.

Public Member Functions

unsigned long addref () const
 Add one to the reference counter.

 object (const object &obj)
 Copy an existing object in a new object.

 object ()
 Constructor, setting the reference count to 1.

objectoperator= (const object &obj)
 Copy an object in another.

unsigned long release () const
 Subtract one from the reference counter.

 ~object ()
 The destructor verifies the reference counter.

Private Attributes

unsigned long f_refcount
 The reference counter of this object.


Detailed Description

Base class used to handle smart pointers.

This class is a base class used to have a reference counter in all the odbcpp objects.

This ensures that higher level objects do not get deleted when they are still in use by some lesser objects.

Definition at line 34 of file object.h.


Constructor & Destructor Documentation

odbcpp::object::object (  ) 

Constructor, setting the reference count to 1.

Initializes the object with a reference count of 1 meaning that at least one person is referencing it (which is correct since once created an object is somehow referenced.)

Definition at line 72 of file object.cpp.

odbcpp::object::object ( const object obj  ) 

Copy an existing object in a new object.

This constructor ensures that the new object has a reference counter of 1.

Parameters:
[in] obj Unused parameter.

Definition at line 85 of file object.cpp.

odbcpp::object::~object (  ) 

The destructor verifies the reference counter.

If an object is being created on the stack, its counter should never reached 0, but at time of destruction it has to be exactly 1.

The contructor/destructor cannot know whether the object is created on the stack, as a variable member or was allocated on the heap, so it accepts both values.

Definition at line 103 of file object.cpp.

References f_refcount.


Member Function Documentation

unsigned long odbcpp::object::addref (  )  const

Add one to the reference counter.

Each time an object is put in another, you need to call the addref() function.

Bug:
At this time, this function is not thread safe.
Returns:
The new reference count.

Definition at line 141 of file object.cpp.

References f_refcount.

object & odbcpp::object::operator= ( const object obj  ) 

Copy an object in another.

This copy operator ensures that the reference counters are not modified in either object since they are specific to the number of smart pointer and not the copy itself.

Parameters:
[in] obj Unused parameter.

Definition at line 123 of file object.cpp.

unsigned long odbcpp::object::release (  )  const

Subtract one from the reference counter.

Each time an object releases another one, call this function to let that other object that you are done with it.

If the counter reaches 0, then the object is automatically deleted since no one has a reference to it.

Returns:
The new counter value, 0 if the object was deleted

Definition at line 162 of file object.cpp.

References f_refcount.


Member Data Documentation

odbcpp::object::f_refcount [mutable, private]

The reference counter of this object.

The reference counter is set to 1 on initialization.

It is incremented each time the pointer is saved in a smart pointer.

It is decremented each time the pointer is replaced in a smart pointer.

It is decremented each time a smart pointer is deleted.

When the counter reaches 0, the object is deleted.

If you create an object on the stack, the delete should never be called since the reference counter will be 1 at the time the object is deleted.

Definition at line 47 of file object.h.

Referenced by addref(), release(), and ~object().


The documentation for this class was generated from the following files:
Generated on Mon Sep 19 12:52:28 2011 for odbcpp by  doxygen 1.6.3