Base class used to handle smart pointers. More...
#include <object.h>
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. | |
object & | operator= (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. |
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.
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.
[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.
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.
Definition at line 141 of file object.cpp.
References f_refcount.
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.
[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.
Definition at line 162 of file object.cpp.
References f_refcount.
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.