context in core
This commit is contained in:
47
src/Core/ObjectsContext.cpp
Normal file
47
src/Core/ObjectsContext.cpp
Normal 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
|
||||
Reference in New Issue
Block a user