ContRap-Core
|
Class DPtr is a base weak typed class for smart pointers. More...
#include <pointer.h>
Public Member Functions | |
DPtr () | |
Empty constructor. | |
DPtr (const DPtr &pointer) | |
Copy constructor increases the reference counter. | |
~DPtr () | |
Destructor. | |
void | operator= (const DPtr &pointer) |
Assignment operator. | |
operator bool () | |
Validity check as an operator. | |
operator bool () const | |
Validity check as an operator. | |
const std::string & | get_type_id () const |
Returns the type identifier of the object. | |
const std::string & | get_type_name () const |
Returns the type name of the object. | |
const MetaInfo * | get_meta_info () const |
Returns the meta info of the pointer. | |
long | get_time_stamp () const |
Returns the time stamp. | |
long | get_reference_time_stamp () const |
Returns the time stamp of the reference. | |
void | outdate () |
Outdates the smart pointer. | |
void | synchronize_time_stamp () |
Synchronizes the time stamp with the reference. | |
operator void * () | |
Returns the original object. | |
operator const void * () const | |
Returns the original object. | |
void * | get_ptr () |
Returns the pointer explicitly. | |
const void * | get_const_ptr () const |
Returns the pointer explicitly. | |
void | replace (DPtr &pointer) |
Replaces the object of the current pointers reference with the object of the other pointer. | |
int | get_rc () const |
Returns the reference counter value. | |
bool | is_referenced () |
Returns true if the object referenced by the current smart pointer is referenced by other smart pointers. | |
const RefPtr * | get_ref_ptr () const |
Returns the reference pointer. | |
bool | is_valid () const |
Returns if the pointer has a valid reference. | |
bool | is_null () const |
Returns if the pointer has a null pointer. | |
bool | is_new () const |
Checks if the local time stamp is older than the time stamp of the reference. | |
PointerMode | get_mode () const |
Returns the pointer mode. | |
void | set_mode (PointerMode mode) |
Sets the new deletion mode. | |
void | clear () |
Clears the contents of the pointer. | |
void | invalidate () |
Invalidates the reference. | |
void | destroy () |
Destroys the pointer and its contents. | |
std::string | to_string () const |
Prints the pointer to a string. | |
Static Public Member Functions | |
static long | get_global_time_stamp () |
Returns the time stamp of the reference. | |
static void | finalize_deletion_queue () |
Finalizes the unreferenced pointers scheduled for deletion with the delayed deletion mode. | |
Static Public Attributes | |
static DPtr | bottom |
Invalid object pointer. | |
static DPtr | null |
Valid null pointer. | |
Protected Member Functions | |
DPtr (void *pointer, MetaInfo *meta_info) | |
Pointer constructor from a pure object. | |
DPtr (void *pointer, MetaInfo *meta_info, const DPtr &source, PointerMode mode=SOURCE) | |
Pointer constructor from a pure object with reference data. | |
DPtr (const DPtr &pointer, MetaInfo *meta_info) | |
Creates a smart pointer from a reference object. | |
void | finalize () |
Destroys the pointer with its contents and the reference object. | |
int | increase_rc () |
Increments the reference counter. | |
int | decrease_rc () |
Decrements the reference counter. | |
RefPtr * | get_ref_ptr () |
Returns the reference pointer. | |
void | set_ref_ptr (RefPtr *reference, MetaInfo *meta_info) |
Sets the reference pointer. | |
Static Protected Member Functions | |
static std::list< Finalizer > & | get_deletion_queue () |
Returns the deletion queue. | |
Protected Attributes | |
RefPtr * | reference |
Pointer to the given object. | |
MetaInfo * | meta_info |
Type name. | |
long | time_stamp |
Time stamp. | |
Friends | |
class | ObjectFactory |
class | Template |
Class DPtr is a base weak typed class for smart pointers.
A DPtr is dynamically weak typed in the following sense. It has no template parameters which fix the type at compile type. The type is determined by a MetaInfo instance which carries the information about the real type of the pointer.
You can not create instances of DPtr by calling its constructors, since they are protected. Use the type-safe SPtr class instead, which is automatically copied to a DPtr instance whenever you want to assign an SPtr to a DPtr, e.g. when returning a DPtr or when adding elements to a List.
crp::DPtr::DPtr | ( | void * | pointer, |
MetaInfo * | meta_info | ||
) | [explicit, protected] |
Pointer constructor from a pure object.
pointer | Pointer to an object |
meta_info | Meta info of the type |
source | Pointer to the data source |
crp::DPtr::DPtr | ( | void * | pointer, |
MetaInfo * | meta_info, | ||
const DPtr & | source, | ||
PointerMode | mode = SOURCE |
||
) | [explicit, protected] |
Pointer constructor from a pure object with reference data.
If you specify the source pointer, the source object will not be deleted until the last copy of this pointer is deleted. The deletion mode of this pointer is then per default PERSISTENT. This reflects that the pointer you have created originates from a memory frame of the source object and should be deleted by the source object.
pointer | Pointer to an object |
meta_info | Meta info of the type |
source | Pointer to the data source |
mode | Destruction mode of the pointer |
Creates a smart pointer from a reference object.
This is used to assign an object pointer a different meta information.
pointer | Reference object |
type_nae | Name of the type |
crp::DPtr::DPtr | ( | ) | [inline] |
Empty constructor.
crp::DPtr::DPtr | ( | const DPtr & | pointer | ) |
Copy constructor increases the reference counter.
pointer | Pointer to copy |
crp::DPtr::~DPtr | ( | ) | [inline] |
Destructor.
void crp::DPtr::clear | ( | ) |
Clears the contents of the pointer.
The function removes the link to reference of the pointer. The pointer becomes invalid. The reference contents are not affected besides decreasing the reference counter.
int crp::DPtr::decrease_rc | ( | ) | [protected] |
Decrements the reference counter.
void crp::DPtr::destroy | ( | ) |
Destroys the pointer and its contents.
All objects referencing the pointers object point to a valid null object.
Reimplemented in crp::SPtr< T >, crp::SPtr< Scope >, crp::SPtr< Class >, crp::SPtr< AtomicFunction >, crp::SPtr< Block >, crp::SPtr< bool >, crp::SPtr< Engine >, and crp::SPtr< List >.
void crp::DPtr::finalize | ( | ) | [protected] |
Destroys the pointer with its contents and the reference object.
static void crp::DPtr::finalize_deletion_queue | ( | ) | [static] |
Finalizes the unreferenced pointers scheduled for deletion with the delayed deletion mode.
const void* crp::DPtr::get_const_ptr | ( | ) | const |
Returns the pointer explicitly.
static std::list<Finalizer>& crp::DPtr::get_deletion_queue | ( | ) | [static, protected] |
Returns the deletion queue.
static long crp::DPtr::get_global_time_stamp | ( | ) | [static] |
Returns the time stamp of the reference.
const MetaInfo* crp::DPtr::get_meta_info | ( | ) | const [inline] |
Returns the meta info of the pointer.
PointerMode crp::DPtr::get_mode | ( | ) | const |
Returns the pointer mode.
void* crp::DPtr::get_ptr | ( | ) |
Returns the pointer explicitly.
Reimplemented in crp::SPtr< T >, crp::SPtr< Scope >, crp::SPtr< Class >, crp::SPtr< AtomicFunction >, crp::SPtr< Block >, crp::SPtr< bool >, crp::SPtr< Engine >, and crp::SPtr< List >.
int crp::DPtr::get_rc | ( | ) | const |
Returns the reference counter value.
RefPtr* crp::DPtr::get_ref_ptr | ( | ) | [protected] |
Returns the reference pointer.
const RefPtr* crp::DPtr::get_ref_ptr | ( | ) | const [inline] |
Returns the reference pointer.
long crp::DPtr::get_reference_time_stamp | ( | ) | const |
Returns the time stamp of the reference.
long crp::DPtr::get_time_stamp | ( | ) | const [inline] |
Returns the time stamp.
const std::string& crp::DPtr::get_type_id | ( | ) | const [inline] |
Returns the type identifier of the object.
The type identifier is a platform dependent name of a type returned by the RTTI.
const std::string& crp::DPtr::get_type_name | ( | ) | const |
Returns the type name of the object.
The type name is the exact name of the type as it was registered by the meta registration macros.
int crp::DPtr::increase_rc | ( | ) | [protected] |
Increments the reference counter.
void crp::DPtr::invalidate | ( | ) |
Invalidates the reference.
After the call to this function the object and its reference point to an invalid null pointer. The object contents are not destroyed.
bool crp::DPtr::is_new | ( | ) | const |
Checks if the local time stamp is older than the time stamp of the reference.
bool crp::DPtr::is_null | ( | ) | const |
Returns if the pointer has a null pointer.
bool crp::DPtr::is_referenced | ( | ) | [inline] |
Returns true if the object referenced by the current smart pointer is referenced by other smart pointers.
It this method returns false, you can reuse the memory of the referenced object.
bool crp::DPtr::is_valid | ( | ) | const [inline] |
Returns if the pointer has a valid reference.
crp::DPtr::operator bool | ( | ) | const |
Validity check as an operator.
crp::DPtr::operator bool | ( | ) |
Validity check as an operator.
crp::DPtr::operator const void * | ( | ) | const |
Returns the original object.
crp::DPtr::operator void * | ( | ) |
Returns the original object.
void crp::DPtr::operator= | ( | const DPtr & | pointer | ) |
Assignment operator.
pointer | Other reference pointer to the object |
void crp::DPtr::outdate | ( | ) |
Outdates the smart pointer.
After the call to this function the time stamp of the pointer is set to zero if the pointer was synchronized. Otherwise the pointer is untouched.
void crp::DPtr::replace | ( | DPtr & | pointer | ) |
Replaces the object of the current pointers reference with the object of the other pointer.
All smart pointers which have pointed to the current object point after the call to the object which was referenced by the other pointer. The other pointers reference becomes illegal and is destroyed. All pointers which have pointed to it are invalid after the function call.
The invalidation of the source reference is a tool to guarantee that both pointers do not become illegal.
pointer | Pointer to replace |
void crp::DPtr::set_mode | ( | PointerMode | mode | ) |
Sets the new deletion mode.
mode | New deletion mode |
Sets the reference pointer.
reference | New object reference |
meta_info | New object meta info |
void crp::DPtr::synchronize_time_stamp | ( | ) |
Synchronizes the time stamp with the reference.
std::string crp::DPtr::to_string | ( | ) | const |
Prints the pointer to a string.
friend class ObjectFactory [friend] |
friend class Template [friend] |
DPtr crp::DPtr::bottom [static] |
Invalid object pointer.
MetaInfo* crp::DPtr::meta_info [protected] |
Type name.
DPtr crp::DPtr::null [static] |
Valid null pointer.
RefPtr* crp::DPtr::reference [protected] |
Pointer to the given object.
long crp::DPtr::time_stamp [protected] |
Time stamp.