ponder 3.1
C++ reflection library
ponder::UserObject Class Reference

Wrapper to manipulate user objects in the Ponder system. More...

#include <userobject.hpp>

Public Member Functions

 UserObject ()
 Default constructor. More...
 
template<typename T >
 UserObject (const T &object)
 Construct the user object from an instance copy. More...
 
template<typename T >
 UserObject (T *object)
 Construct the user object from an instance reference. More...
 
 UserObject (const UserObject &other)
 Copy constructor. More...
 
 UserObject (UserObject &&other) noexcept
 Move constructor. More...
 
UserObjectoperator= (const UserObject &other)
 Copy assignment operator. More...
 
UserObjectoperator= (UserObject &&other) noexcept
 Move assignment operator. More...
 
template<typename T >
detail::ReferenceTraits< T >::ReferenceType get () const
 Retrieve the instance stored in the user object. More...
 
void * pointer () const
 Retrieve the address of the stored object. More...
 
template<typename T >
const T & cref () const
 Get a const reference to the object data contained. More...
 
template<typename T >
T & ref () const
 Get a non-const reference to the object data contained. More...
 
const ClassgetClass () const
 Retrieve the metaclass of the stored instance. More...
 
Value get (IdRef property) const
 Get the value of an object's property by name. More...
 
Value get (std::size_t index) const
 Get the value of an object's property by index. More...
 
void set (IdRef property, const Value &value) const
 Set the value of an object's property by name. More...
 
void set (std::size_t index, const Value &value) const
 Set the value of an object's property by index. More...
 
bool operator== (const UserObject &other) const
 Operator == to compare equality between two user objects. More...
 
bool operator != (const UserObject &other) const
 Operator != to compare inequality between two user objects. More...
 
bool operator< (const UserObject &other) const
 Operator < to compare two user objects. More...
 

Static Public Member Functions

template<typename T >
static UserObject makeRef (T &object)
 Construct a user object from a reference to an object. More...
 
template<typename T >
static UserObject makeRef (T *object)
 Construct a user object from a const reference to an object. More...
 
template<typename T >
static UserObject makeCopy (const T &object)
 Construct a user object with a copy of an object. More...
 

Static Public Attributes

static const UserObject nothing
 Special UserObject instance representing an empty object.
 

Friends

class Property
 

Detailed Description

Wrapper to manipulate user objects in the Ponder system.

ponder::UserObject is an abstract representation of object instances, which can safely be passed to and manipulated by all the entities in Ponder.

Note
UserObjects are stored interally as objects (a copy) or references (an existing object). To be sure which you are constructing use UserObject::makeRef() or UserObject::makeCopy().
See also
EnumObject

Constructor & Destructor Documentation

◆ UserObject() [1/5]

ponder::UserObject::UserObject ( )

Default constructor.

Constructs an empty/invalid object

◆ UserObject() [2/5]

template<typename T >
ponder::UserObject::UserObject ( const T &  object)

Construct the user object from an instance copy.

Parameters
objectInstance to store in the user object
See also
makeRef(), makeCopy()

◆ UserObject() [3/5]

template<typename T >
ponder::UserObject::UserObject ( T *  object)

Construct the user object from an instance reference.

Parameters
objectPointer to the object to reference in the user object
See also
makeRef(), makeCopy()

◆ UserObject() [4/5]

ponder::UserObject::UserObject ( const UserObject other)

Copy constructor.

Parameters
otherinstance to copy

◆ UserObject() [5/5]

ponder::UserObject::UserObject ( UserObject &&  other)
noexcept

Move constructor.

Parameters
otherinstance to move

Member Function Documentation

◆ cref()

template<typename T >
const T& ponder::UserObject::cref ( ) const

Get a const reference to the object data contained.

Returns a const reference to the contained object, of type T. The user is responsible for ensuring that the type passed is correct. See ref() for non-const ref.

Returns
A const reference to the contained object.

◆ get() [1/3]

template<typename T >
detail::ReferenceTraits<T>::ReferenceType ponder::UserObject::get ( ) const

Retrieve the instance stored in the user object.

The template parameter T is the type to convert the instance to. T must be compatible with the original type of the instance.

Returns
Reference to the instance of the stored object
Exceptions
NullObjectthe stored object is invalid
ClassNotFoundT has not metaclass
ClassUnrelatedthe type of the object is not compatible with T

◆ get() [2/3]

Value ponder::UserObject::get ( IdRef  property) const

Get the value of an object's property by name.

This function is defined for convenience, it is a shortcut for object.getClass().property(name).get(object);

Parameters
propertyName of the property to get
Returns
Current value of the property
Exceptions
PropertyNotFoundproperty is not a property of the object
ForbiddenReadproperty is not readable

◆ get() [3/3]

Value ponder::UserObject::get ( std::size_t  index) const

Get the value of an object's property by index.

This function is defined for convenience, it is a shortcut for object.getClass().property(index).get(object);

Parameters
indexIndex of the property to get
Returns
Current value of the property
Exceptions
OutOfRangeindex is invalid
ForbiddenReadproperty is not readable

◆ getClass()

const Class& ponder::UserObject::getClass ( ) const

Retrieve the metaclass of the stored instance.

Returns
Reference to the instance's metaclass
Exceptions
NullObjectthe stored object has no metaclass

◆ makeCopy()

template<typename T >
static UserObject ponder::UserObject::makeCopy ( const T &  object)
static

Construct a user object with a copy of an object.

This functions is not equivalent to calling UserObject(object).

Parameters
objectInstance to store in the user object
Returns
UserObject containing a copy of object

◆ makeRef() [1/2]

template<typename T >
static UserObject ponder::UserObject::makeRef ( T &  object)
static

Construct a user object from a reference to an object.

This functions is equivalent to calling UserObject(&object).

Parameters
objectInstance to store in the user object
Returns
UserObject containing a reference to object

◆ makeRef() [2/2]

template<typename T >
static UserObject ponder::UserObject::makeRef ( T *  object)
static

Construct a user object from a const reference to an object.

This functions is equivalent to calling UserObject(&object).

Parameters
objectInstance to store in the user object
Returns
UserObject containing a const reference to object

◆ operator !=()

bool ponder::UserObject::operator != ( const UserObject other) const
inline

Operator != to compare inequality between two user objects.

See also
operator ==

◆ operator<()

bool ponder::UserObject::operator< ( const UserObject other) const

Operator < to compare two user objects.

Parameters
otherUser object to compare with this
Returns
True if this < other

◆ operator=() [1/2]

UserObject& ponder::UserObject::operator= ( const UserObject other)

Copy assignment operator.

Parameters
otherUser object to assign
Returns
Reference to this

◆ operator=() [2/2]

UserObject& ponder::UserObject::operator= ( UserObject &&  other)
noexcept

Move assignment operator.

Parameters
otherUser object to assign
Returns
Reference to this

◆ operator==()

bool ponder::UserObject::operator== ( const UserObject other) const

Operator == to compare equality between two user objects.

Two user objects are equal if their metaclasses and pointers are both equal, i.e. they point to the same object, not if the object values are the same.

Parameters
otherUser object to compare with this
Returns
True if both user objects are the same, false otherwise

◆ pointer()

void* ponder::UserObject::pointer ( ) const

Retrieve the address of the stored object.

This function must be used with caution, as the returned address may not be what you expect it to be!

Returns
Pointer to the stored object

◆ ref()

template<typename T >
T& ponder::UserObject::ref ( ) const

Get a non-const reference to the object data contained.

Returns a reference to the contained object, of type T. The user is responsible for ensuring that the type passed is correct. See cref() for const ref.

Returns
A reference to the contained object.

◆ set() [1/2]

void ponder::UserObject::set ( IdRef  property,
const Value value 
) const

Set the value of an object's property by name.

This function is defined for convenience, it is a shortcut for object.getClass().property(name).set(object, value);

Parameters
propertyName of the property to set
valueValue to set
Exceptions
PropertyNotFoundproperty is not a property of the object
ForbiddenWriteproperty is not writable
BadTypevalue can't be converted to the property's type

◆ set() [2/2]

void ponder::UserObject::set ( std::size_t  index,
const Value value 
) const

Set the value of an object's property by index.

This function is defined for convenience, it is a shortcut for object.getClass().property(index).set(object, value);

Parameters
indexIndex of the property to set
valueValue to set
Exceptions
OutOfRangeindex is invalid
ForbiddenWriteproperty is not writable
BadTypevalue can't be converted to the property's type

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