context in core

This commit is contained in:
AndreaRigoni
2026-03-21 16:30:56 +00:00
parent cd95f16221
commit 0bff36f8ba
6 changed files with 163 additions and 26 deletions

View File

@@ -0,0 +1,47 @@
#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);
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()) {
m_objects.erase(it);
this->Updated(); // Signal that the context has been updated
}
}
void ObjectsContext::Clear() {
if (!m_objects.empty()) {
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;
}
} // namespace uLib