Files
uLib/src/Core/ObjectsContext.h

69 lines
1.7 KiB
C++

#ifndef U_CORE_OBJECTS_CONTEXT_H
#define U_CORE_OBJECTS_CONTEXT_H
#include "Core/Object.h"
#include <vector>
namespace uLib {
/**
* @brief ObjectsContext represents a collection of Object instances.
*/
class ObjectsContext : virtual public Object {
public:
ObjectsContext();
virtual ~ObjectsContext();
uLibTypeMacro(ObjectsContext, Object)
virtual ObjectsContext* GetChildren() override { return this; }
/**
* @brief Adds an object to the context.
* @param obj Pointer to the object to add.
*/
virtual void AddObject(Object* obj);
/**
* @brief Removes an object from the context.
* @param obj Pointer to the object to remove.
*/
virtual void RemoveObject(Object* obj);
/**
* @brief Clears all objects from the context.
*/
void Clear();
/**
* @brief Returns the collection of objects.
* @return Const reference to the vector of object pointers.
*/
const std::vector<Object*>& GetObjects() const;
signals:
/** @brief Signal emitted when an object is added. */
virtual void ObjectAdded(Object* obj);
/** @brief Signal emitted when an object is removed. */
virtual void ObjectRemoved(Object* obj);
/**
* @brief Returns the number of objects in the context.
* @return Size of the collection.
*/
size_t GetCount() const;
/**
* @brief Returns an object by index.
* @param index The index of the object.
* @return Pointer to the object or nullptr if index is out of bounds.
*/
Object* GetObject(size_t index) const;
private:
std::vector<Object*> m_objects;
};
} // namespace uLib
#endif // U_CORE_OBJECTS_CONTEXT_H