.. _api_ObjectSystem: ObjectSystem ============ Inherited: None .. _api_ObjectSystem_description: Description ----------- ObjectSystem helps to developers create new instances and serialize/deserialize them on disc or in memory. .. _api_ObjectSystem_public: Public Methods -------------- +----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | | :ref:`ObjectSystem` () | +----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | | :ref:`~ObjectSystem` () | +----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`addObject` (Object * object) | +----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | bool | :ref:`compareTreads` (ObjectSystem * system) const | +----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | template void | :ref:`factoryAdd` (const std::string & group, const MetaObject * meta) | +----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | template void | :ref:`factoryRemove` (const std::string & group) | +----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Object::ObjectList` | :ref:`getAllObjectsByType` (const std::string & type) const | +----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Object` * | :ref:`instantiateObject` (const MetaObject * meta, const std::string & name, Object * parent) | +----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`processEvents` () | +----------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+ .. _api_ObjectSystem_static: Static Methods -------------- +--------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`ObjectSystem::GroupMap` | :ref:`factories` () | +--------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Object` * | :ref:`findObject` (uint32_t uuid, Object * root) | +--------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Object` * | :ref:`findRoot` (Object * object) | +--------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`uint32_t` | :ref:`generateUUID` () | +--------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`ObjectSystem::FactoryPair` * | :ref:`metaFactory` (const std::string & uri) | +--------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+ | template T | :ref:`objectCreate` (const std::string & name = string(), Object * parent = 0) | +--------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Object` * | :ref:`objectCreate` (const std::string & uri, const std::string & name = std::string(), Object * parent = nullptr) | +--------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`replaceClonedUUID` (Object * object, uint32_t uuid) | +--------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`replaceUUID` (Object * object, uint32_t uuid) | +--------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Object` * | :ref:`toObject` (const Variant & variant, Object * parent = nullptr, const std::string & name = std::string()) | +--------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Variant` | :ref:`toVariant` (const Object * object, bool force = false) | +--------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+ .. _api_ObjectSystem_methods: Methods Description ------------------- .. _api_ObjectSystem_ObjectSystem: **ObjectSystem::ObjectSystem** () Constructs ObjectSystem. ---- .. _api_ObjectSystem_~ObjectSystem: **ObjectSystem::~ObjectSystem** () Destructs ObjectSystem, related objects and registered object factories. ---- .. _api_ObjectSystem_addObject: void **ObjectSystem::addObject** (:ref:`Object` * *object*) Adds an *object* to main pull of *object*s in ObjectSystem ---- .. _api_ObjectSystem_compareTreads: bool **ObjectSystem::compareTreads** (:ref:`ObjectSystem` * *system*) const Returns true in case of other *system* execues in the same thread with current *system*; otherwise returns false. ---- .. _api_ObjectSystem_factories: :ref:`ObjectSystem::GroupMap` **ObjectSystem::factories** () Returns all registered classes. ---- .. _api_ObjectSystem_factoryAdd: template void **ObjectSystem::factoryAdd** (std::string & *group*, :ref:`MetaObject` * *meta*) Registers class with T type, *meta* object and *group* to object instantiation mechanism. **Note:** New classes inherited from base Object class can be automaticaly registered using T::registerClassFactory(). This is preferable way to use this functionality. ---- .. _api_ObjectSystem_factoryRemove: template void **ObjectSystem::factoryRemove** (std::string & *group*) Unregisters class with type T and *group* from object instantiation mechanism. **Note:** The preferable way to use this function is T::unregisterClassFactory() invocation. ---- .. _api_ObjectSystem_findObject: :ref:`Object` * **ObjectSystem::findObject** (:ref:`uint32_t` *uuid*, :ref:`Object` * *root*) Returns object with *uuid* or which was clonned from this. This algorithm recursively going down from the *root* object If the object doesn't exist in the hierarchy this method returns nullptr. ---- .. _api_ObjectSystem_findRoot: :ref:`Object` * **ObjectSystem::findRoot** (:ref:`Object` * *object*) Returns root *object* in the hierarchy. ---- .. _api_ObjectSystem_generateUUID: :ref:`uint32_t` **ObjectSystem::generateUUID** () Returns the new unique ID based on random number generator. ---- .. _api_ObjectSystem_getAllObjectsByType: :ref:`Object::ObjectList` **ObjectSystem::getAllObjectsByType** (std::string & *type*) const Returns a list of objects with specified *type*. Warning: This is very small function! ---- .. _api_ObjectSystem_instantiateObject: :ref:`Object` * **ObjectSystem::instantiateObject** (:ref:`MetaObject` * *meta*, std::string & *name*, :ref:`Object` * *parent*) The basic method to spawn a new object based on the provided *meta* object, *name* of object and *parent* object. Returns a pointer to spawned object. ---- .. _api_ObjectSystem_metaFactory: :ref:`ObjectSystem::FactoryPair` * **ObjectSystem::metaFactory** (std::string & *uri*) Returns MetaObject for registered factory by provided *uri*. ---- .. _api_ObjectSystem_objectCreate: template T **ObjectSystem::objectCreate** (std::string & *name* = string(), :ref:`Object` * *parent* = 0) Returns new instance of type T and *name* as child of *parent* object. **Note:** Class T should be registered first via factoryAdd() **See also** factoryAdd() and factoryRemove(). ---- .. _api_ObjectSystem_objectCreate: :ref:`Object` * **ObjectSystem::objectCreate** (std::string & *uri*, std::string & *name* = std::string(), :ref:`Object` * *parent* = nullptr) Returns new instance of type represented in *uri* and *name* as child of *parent* object. **Note:** Class represented as *uri* should be registered first via factoryAdd() **See also** factoryAdd() and factoryRemove(). ---- .. _api_ObjectSystem_processEvents: void **ObjectSystem::processEvents** () Updates all related objects. ---- .. _api_ObjectSystem_replaceClonedUUID: void **ObjectSystem::replaceClonedUUID** (:ref:`Object` * *object*, :ref:`uint32_t` *uuid*) Replaces current cloned *uuid* of the *object* with the new one. **Note:** This is a service function. Developers shouldn't call it manually. ---- .. _api_ObjectSystem_replaceUUID: void **ObjectSystem::replaceUUID** (:ref:`Object` * *object*, :ref:`uint32_t` *uuid*) Replaces current *uuid* of the *object* with the new one. ---- .. _api_ObjectSystem_toObject: :ref:`Object` * **ObjectSystem::toObject** (:ref:`Variant` & *variant*, :ref:`Object` * *parent* = nullptr, std::string & *name* = std::string()) Returns object deserialized from *variant* based representation. The Variant representation can be loaded from BSON or JSON formats or retrieved from memory. Deserialization will try to restore objects hierarchy with *parent*, its properties and connections. The root object will be created with a *name* in case of this parameter provided. ---- .. _api_ObjectSystem_toVariant: :ref:`Variant` **ObjectSystem::toVariant** (:ref:`Object` * *object*, bool *force* = false) Returns serialized to Variant version of *object* inherited from Object class. This method saves all *object* property values, active connections and necessary parameters. **Note:** All childs of *object* will be also serialized. **Note:** Function will ignore Object::isSerializable in case of *force* flag provided. The returned value can be saved on disk in BSON or JSON form or keep it in memory. Developers is able to save own data using Object::saveUserData() mechanism.