Object

Inherited: None

Description

The object is the central part of the Next library. For communication between objects two mechanisms was implemented the signals and slots also event based approach. To connect two objects between use connect() method and the sender object will notify the receiver object about necessary events.

Objects can be organized into an object trees. Each object can have an unlimited number of children objects. When you assign parent to an object it automatically add itself to the parent children list. Parent object takes ownership of the child object. This means that the child will be automatically deleted if the parent object is deleted. Child object can be found in hierarchy of objects by path or by the type using find(), findChild() or findChildren().

Each Object has name() and this name must be unique in space of object level in hierarchy i.e. parent with name “House” can’t has two childs with name “Roof”. This names is used to reach objects by its paths land.find(“House/Roof”) will return “Roof” object.

Each Object has MetaObject declaration. MetaObject system can be used to declare and retrieve structure of object at runtime.

Based on Actor model the object can’t be copied only clone().

Public Methods

Object ()

Object *

clone (Object * parent = nullptr)

int

clonedFrom () const

void

deleteLater ()

const int

dynamicPropertyNames () const

void

emitSignal (const char * signal, const Variant & args = Variant())

bool

event (Event * event)

Object *

find (const std::string & path) const

template <typename T> T

findChild (bool recursive = true)

template <typename T> int

findChildren (bool recursive)

const Object::ObjectList &

getChildren () const

const Object::LinkList &

getReceivers () const

bool

isSerializable () const

void

loadData (const VariantList & data)

void

loadObjectData (const VariantMap & data)

void

loadUserData (const VariantMap & data)

const MetaObject *

metaObject () const

void

methodCallEvent (MethodCallEvent * event)

std::string

name () const

Object *

parent () const

void

postEvent (Event * event)

Variant

property (const char * name) const

void

removeChild (Object * child)

VariantList

saveData () const

VariantMap

saveUserData () const

Object *

sender () const

void

setName (const std::string & name)

void

setProperty (const char * name, const Variant & value)

void

setType (const std::string & type)

ObjectSystem *

system () const

std::string

typeName () const

int

uuid () const

Public Enums

Synonym for list<Link *>.

enum Object::ObjectList

Synonym for list<Object *>.

Static Methods

bool

connect (Object * sender, const char * signal, Object * receiver, const char * method)

Object *

construct ()

void

disconnect (Object * sender, const char * signal, Object * receiver, const char * method)

const MetaObject *

metaClass ()

Methods Description

Object::Object ()

Constructs an object.

By default Object create without parent to assign the parent object use setParent().


Object * parent = nullptr)

Clones this object. Returns pointer to clone object.

When you clone the Object or subclasses of it, all child objects also will be cloned. By default the parent for the new object will be nullptr. This clone will not have the unique name so you will need to set it manualy if required.

Warning: Connections will NOT be transferred and the developer must create them manually.

See also connect().


int Object::clonedFrom () const

Returns the UUID of cloned object.


bool Object::connect (Object * sender, char * signal, Object * receiver, char * method)

Creates connection beteen the signal of the sender and the method of the receiver. Returns true if successful; otherwise returns false.

You must use the _SIGNAL() and _SLOT() macros when specifying signal and the method.

Note: The _SIGNAL() and _SLOT() must not contain any parameter values only parameter types.

class MyObject : public Object {
    A_OVERRIDE(MyObject, Object, Core)

    A_METHODS(
        A_SLOT(onSignal),
        A_SIGNAL(signal)
    )
public:
    void signal(bool value);

    void onSignal(bool value) {
        // Do some actions here
        ...
    }
};
...
MyObject obj1;
MyObject obj2;

Object::connect(&obj1, _SIGNAL(signal(bool)), &obj2, _SLOT(onSignal(bool)));

Note: Mehod signal in MyObject class may not have the implementation. It used only in description purposes in A_SIGNAL(signal) macros.

Signal can also be conected to another signal.

MyObject obj1;
MyObject obj2;

Object::connect(&obj1, _SIGNAL(signal(bool)), &obj2, _SIGNAL(signal(bool)));

:ref:`Object<api_Object>`* Object::construct ()

Returns new instance of Object class. This method is used in MetaObject system.

See also MetaObject.


void Object::deleteLater ()

Marks this object to be deleted. This object will be deleted when event loop will call processEvents() method for this object.


void Object::disconnect (Object * sender, char * signal, Object * receiver, char * method)

Disconnects signal in object sender from method in object receiver.

A connection is removed when either of the objects are destroyed.

disconnect() can be used in three ways:

Disconnect everything from a specific sender

Object::disconnect(&obj1, 0, 0, 0);

Disconnect everything connected to a specific signal

Object::disconnect(&obj1, _SIGNAL(signal(bool)), 0, 0);

Disconnect all connections from the receiver

Object::disconnect(&obj1, 0, &obj3, 0);

See also connect().


const int Object::dynamicPropertyNames () const

Returns the names of all properties that were dynamically added to the object using setProperty()


void Object::emitSignal (char * signal, Variant & args = Variant())

Send specific signal with args for all connected receivers.

For now it places signal directly to receivers queues. In case of another signal connected as method this signal will be emitted immediately.

Note: Receiver should be in event loop to process incoming message.

See also connect().


bool Object::event (Event * event)

Abstract event handler. Developers should reimplement this method to handle event*s manually. Returns true in case of *event was handled otherwise return false.


:ref:`Object<api_Object>`* Object::find (std::string & path) const

Returns an object located along the path.

Object obj1;
Object obj2;

obj1.setName("MainObject");
obj2.setName("TestComponent2");
obj2.setParent(&obj1);

// result will contain pointer to obj2
Object *result = obj1.find("/MainObject/TestComponent2");

Returns nullptr if no such object.

See also findChild().


template <typename T> T Object::findChild (bool recursive = true)

Returns the first child of this object that can be cast to type T. The search is performed recursive*ly, unless *recursive option is false.

Returns nullptr if no such object.

See also find() and findChildren().


template <typename T> int Object::findChildren (bool recursive)

Returns all children of this object that can be cast to type T. The search is performed recursive*ly, unless *recursive option is false.

Returns empty list if no such objects.

See also find() and findChildren().


const :ref:`Object::ObjectList<api_Object::ObjectList>`& Object::getChildren () const

Returns list of child objects for this object.


const :ref:`Object::LinkList<api_Object::LinkList>`& Object::getReceivers () const

Returns list of links to receivers objects for this object.


bool Object::isSerializable () const

Returns true if the object can be serialized; otherwise returns false.


void Object::loadData (VariantList & data)

This method allows to DESERIALIZE data of object like properties, connections and user data.


void Object::loadObjectData (VariantMap & data)

This method allows to DESERIALIZE data. It can be used to DESERIALIZE some specific data like prefabs.


void Object::loadUserData (VariantMap & data)

This method allows to DESERIALIZE data which not present as A_PROPERTY() in object.


const :ref:`MetaObject<api_MetaObject>`* Object::metaClass ()

Returns MetaObject and can be invoke without object of current class. This method is used in MetaObject system.

See also MetaObject.


const :ref:`MetaObject<api_MetaObject>`* Object::metaObject () const

Returns ponter MetaObject of this object. This method is used in MetaObject system.

See also MetaObject.


void Object::methodCallEvent (MethodCallEvent * event)

Method call event handler. Can be reimplemented to support different logic.


std::string Object::name () const

Returns name of the object.

See also setName().


:ref:`Object<api_Object>`* Object::parent () const

Returns a pointer to the parent object.


void Object::postEvent (Event * event)

Place event to internal event queue to be processed in event loop.


Variant Object::property (char * name) const

Returns the value of the object’s property by name.

If property not found returns invalid Variant. Information of all properties which provided by this object can be found in MetaObject.

See also setProperty(), metaObject(), and Variant::isValid().


void Object::removeChild (Object * child)

Removes a child object from the internal list of *child*ren.


VariantList Object::saveData () const

This method allows to SERIALIZE all object data like properties connections and user data. Returns serialized data as VariantList.


VariantMap Object::saveUserData () const

This method allows to SERIALIZE data which not present as A_PROPERTY() in object. Returns serialized data as VariantMap.


:ref:`Object<api_Object>`* Object::sender () const

Returns object which sent signal.

Note: This method returns a valid object only in receiver slot otherwise it’s return nullptr


void Object::setName (std::string & name)

Set object name by provided name.

See also *name*() and metaObject().


void Object::setProperty (char * name, Variant & value)

Sets the property with name to value.

If property not found do nothing. Property must be defined as A_PROPERTY(). Information of all properties which provided by this object can be found in MetaObject.

See also property(), metaObject(), and Variant::isValid().


void Object::setType (std::string & type)

Specify an additional type for the object.

Note: Most of the time this method does nothing.


:ref:`ObjectSystem<api_ObjectSystem>`* Object::system () const

Returns System which handles this object.


std::string Object::typeName () const

Returns class name the object.


int Object::uuid () const

Returns unique ID of the object.