icinga2/base/confighive.cpp

42 lines
1021 B
C++
Raw Normal View History

#include "i2-base.h"
using namespace icinga;
2012-04-03 11:39:26 +02:00
void ConfigHive::AddObject(const ConfigObject::Ptr& object)
{
object->SetHive(static_pointer_cast<ConfigHive>(shared_from_this()));
GetCollection(object->GetType())->AddObject(object);
}
2012-04-03 11:39:26 +02:00
void ConfigHive::RemoveObject(const ConfigObject::Ptr& object)
{
GetCollection(object->GetType())->RemoveObject(object);
}
ConfigObject::Ptr ConfigHive::GetObject(const string& type, const string& name)
{
return GetCollection(type)->GetObject(name);
}
ConfigCollection::Ptr ConfigHive::GetCollection(const string& collection)
{
CollectionIterator ci = Collections.find(collection);
if (ci == Collections.end()) {
Collections[collection] = make_shared<ConfigCollection>();
ci = Collections.find(collection);
}
return ci->second;
}
2012-04-18 15:22:25 +02:00
void ConfigHive::ForEachObject(const string& type, function<int (const ConfigObjectEventArgs&)> callback)
{
CollectionIterator ci = Collections.find(type);
if (ci == Collections.end())
return;
ci->second->ForEachObject(callback);
}