ContRap-Core
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends

crp::DPtr Class Reference

Class DPtr is a base weak typed class for smart pointers. More...

#include <pointer.h>

Inheritance diagram for crp::DPtr:
crp::SPtr< T >

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 MetaInfoget_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 RefPtrget_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.
RefPtrget_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

RefPtrreference
 Pointer to the given object.
MetaInfometa_info
 Type name.
long time_stamp
 Time stamp.

Friends

class ObjectFactory
class Template

Detailed Description

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.


Constructor & Destructor Documentation

crp::DPtr::DPtr ( void *  pointer,
MetaInfo meta_info 
) [explicit, protected]

Pointer constructor from a pure object.

Parameters:
pointerPointer to an object
meta_infoMeta info of the type
sourcePointer 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.

Parameters:
pointerPointer to an object
meta_infoMeta info of the type
sourcePointer to the data source
modeDestruction mode of the pointer
crp::DPtr::DPtr ( const DPtr pointer,
MetaInfo meta_info 
) [explicit, protected]

Creates a smart pointer from a reference object.

This is used to assign an object pointer a different meta information.

Parameters:
pointerReference object
type_naeName of the type
crp::DPtr::DPtr ( ) [inline]

Empty constructor.

crp::DPtr::DPtr ( const DPtr pointer)

Copy constructor increases the reference counter.

Parameters:
pointerPointer to copy
crp::DPtr::~DPtr ( ) [inline]

Destructor.


Member Function Documentation

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.

Returns:
Status of the garbage collector
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.

Returns:
Pure object pointer
static std::list<Finalizer>& crp::DPtr::get_deletion_queue ( ) [static, protected]

Returns the deletion queue.

Returns:
Deletion queue
static long crp::DPtr::get_global_time_stamp ( ) [static]

Returns the time stamp of the reference.

Returns:
Time stamp of the object
const MetaInfo* crp::DPtr::get_meta_info ( ) const [inline]

Returns the meta info of the pointer.

Returns:
Meta info of the pointer
PointerMode crp::DPtr::get_mode ( ) const

Returns the pointer mode.

Returns:
Pointer mode of the reference.
void* crp::DPtr::get_ptr ( )
int crp::DPtr::get_rc ( ) const

Returns the reference counter value.

Returns:
Reference counter value
RefPtr* crp::DPtr::get_ref_ptr ( ) [protected]

Returns the reference pointer.

Returns:
Reference pointer
const RefPtr* crp::DPtr::get_ref_ptr ( ) const [inline]

Returns the reference pointer.

Returns:
Reference pointer
long crp::DPtr::get_reference_time_stamp ( ) const

Returns the time stamp of the reference.

Returns:
Time stamp of the object
long crp::DPtr::get_time_stamp ( ) const [inline]

Returns the time stamp.

Returns:
Time stamp of the object
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.

Returns:
Type name of the object
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.

Returns:
Type name of the object
int crp::DPtr::increase_rc ( ) [protected]

Increments the reference counter.

Returns:
Status of the garbage collector
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.

Returns:
True if the local time stamp is smaller than that of the reference
bool crp::DPtr::is_null ( ) const

Returns if the pointer has a null pointer.

Returns:
True if the object is valid
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.

Returns:
True if there are other referers to the object or the object is the null pointer or is invalid.
bool crp::DPtr::is_valid ( ) const [inline]

Returns if the pointer has a valid reference.

Returns:
True if the object is valid
crp::DPtr::operator bool ( ) const

Validity check as an operator.

Returns:
True if the object is a valid non-zero pointer
crp::DPtr::operator bool ( )

Validity check as an operator.

Returns:
True if the object is a valid non-zero pointer
crp::DPtr::operator const void * ( ) const

Returns the original object.

Returns:
Pointer to the original object
crp::DPtr::operator void * ( )

Returns the original object.

Returns:
Pointer to the original object
void crp::DPtr::operator= ( const DPtr pointer)

Assignment operator.

Parameters:
pointerOther 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.

Parameters:
pointerPointer to replace
void crp::DPtr::set_mode ( PointerMode  mode)

Sets the new deletion mode.

Parameters:
modeNew deletion mode
void crp::DPtr::set_ref_ptr ( RefPtr reference,
MetaInfo meta_info 
) [protected]

Sets the reference pointer.

Parameters:
referenceNew object reference
meta_infoNew 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.

Returns:
String representation of the contained object

Friends And Related Function Documentation

friend class ObjectFactory [friend]
friend class Template [friend]

Field Documentation

Invalid object pointer.

Type name.

Valid null pointer.

Pointer to the given object.

long crp::DPtr::time_stamp [protected]

Time stamp.


The documentation for this class was generated from the following file: