ObjectSystem
Inherited: None
Description
ObjectSystem helps to developers create new instances and serialize/deserialize them on disc or in memory.
Public Methods
ObjectSystem () |
|
void |
addObject (Object * object) |
bool |
compareTreads (ObjectSystem * system) const |
template <typename T> void |
factoryAdd (const std::string & group, const MetaObject * meta) |
template <typename T> void |
factoryRemove (const std::string & group) |
Object::ObjectList |
getAllObjectsByType (const std::string & type) const |
Object * |
instantiateObject (const MetaObject * meta, const std::string & name, Object * parent) |
void |
Static Methods
ObjectSystem::GroupMap |
factories () |
Object * |
findObject (uint32_t uuid, Object * root) |
Object * |
findRoot (Object * object) |
uint32_t |
generateUUID () |
ObjectSystem::FactoryPair * |
metaFactory (const std::string & uri) |
template <typename T> T |
objectCreate (const std::string & name = string(), Object * parent = 0) |
Object * |
objectCreate (const std::string & uri, const std::string & name = std::string(), Object * parent = nullptr) |
void |
replaceClonedUUID (Object * object, uint32_t uuid) |
void |
replaceUUID (Object * object, uint32_t uuid) |
Object * |
toObject (const Variant & variant, Object * parent = nullptr, const std::string & name = std::string()) |
toVariant (const Object * object, bool force = false) |
Methods Description
ObjectSystem::ObjectSystem ()
Constructs ObjectSystem.
ObjectSystem::~ObjectSystem ()
Destructs ObjectSystem, related objects and registered object factories.
void ObjectSystem::addObject (Object * object)
Adds an object to main pull of *object*s in ObjectSystem
bool ObjectSystem::compareTreads (ObjectSystem * system) const
Returns true in case of other system execues in the same thread with current system; otherwise returns false.
ObjectSystem::GroupMap ObjectSystem::factories ()
Returns all registered classes.
template <typename T> void ObjectSystem::factoryAdd (std::string & group, 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.
template <typename T> 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.
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.
Returns root object in the hierarchy.
uint32_t ObjectSystem::generateUUID ()
Returns the new unique ID based on random number generator.
Object::ObjectList ObjectSystem::getAllObjectsByType (std::string & type) const
Returns a list of objects with specified type.
Warning: This is very small function!
Object * ObjectSystem::instantiateObject (MetaObject * meta, std::string & name, 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.
ObjectSystem::FactoryPair * ObjectSystem::metaFactory (std::string & uri)
Returns MetaObject for registered factory by provided uri.
template <typename T> T ObjectSystem::objectCreate (std::string & name = string(), 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().
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().
void ObjectSystem::processEvents ()
Updates all related objects.
void ObjectSystem::replaceClonedUUID (Object * object, 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.
void ObjectSystem::replaceUUID (Object * object, uint32_t uuid)
Replaces current uuid of the object with the new one.
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.
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.