62 lines
1.6 KiB
C++
62 lines
1.6 KiB
C++
#include "Core/ObjectsContext.h"
|
|
#include <algorithm>
|
|
|
|
namespace uLib {
|
|
|
|
ObjectsContext::ObjectsContext() : Object() {}
|
|
|
|
ObjectsContext::~ObjectsContext() {}
|
|
|
|
void ObjectsContext::AddObject(Object* obj) {
|
|
if (obj && std::find(m_objects.begin(), m_objects.end(), obj) == m_objects.end()) {
|
|
m_objects.push_back(obj);
|
|
ULIB_SIGNAL_EMIT(ObjectsContext::ObjectAdded, obj);
|
|
this->Updated(); // Signal that the context has been updated
|
|
}
|
|
}
|
|
|
|
void ObjectsContext::RemoveObject(Object* obj) {
|
|
auto it = std::find(m_objects.begin(), m_objects.end(), obj);
|
|
if (it != m_objects.end()) {
|
|
Object* removedObj = *it;
|
|
m_objects.erase(it);
|
|
ULIB_SIGNAL_EMIT(ObjectsContext::ObjectRemoved, removedObj);
|
|
this->Updated(); // Signal that the context has been updated
|
|
}
|
|
}
|
|
|
|
void ObjectsContext::Clear() {
|
|
if (!m_objects.empty()) {
|
|
for (auto obj : m_objects) {
|
|
ULIB_SIGNAL_EMIT(ObjectsContext::ObjectRemoved, obj);
|
|
}
|
|
m_objects.clear();
|
|
this->Updated();
|
|
}
|
|
}
|
|
|
|
const std::vector<Object*>& ObjectsContext::GetObjects() const {
|
|
return m_objects;
|
|
}
|
|
|
|
size_t ObjectsContext::GetCount() const {
|
|
return m_objects.size();
|
|
}
|
|
|
|
Object* ObjectsContext::GetObject(size_t index) const {
|
|
if (index < m_objects.size()) {
|
|
return m_objects[index];
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
void ObjectsContext::ObjectAdded(Object* obj) {
|
|
ULIB_SIGNAL_EMIT(ObjectsContext::ObjectAdded, obj);
|
|
}
|
|
|
|
void ObjectsContext::ObjectRemoved(Object* obj) {
|
|
ULIB_SIGNAL_EMIT(ObjectsContext::ObjectRemoved, obj);
|
|
}
|
|
|
|
} // namespace uLib
|