mirror of https://github.com/Icinga/icinga2.git
Build fix for GCC.
This commit is contained in:
parent
8144ca398b
commit
f971152349
|
@ -45,10 +45,10 @@ public:
|
||||||
typedef weak_ptr<DynamicDictionary> WeakPtr;
|
typedef weak_ptr<DynamicDictionary> WeakPtr;
|
||||||
|
|
||||||
DynamicDictionary(void);
|
DynamicDictionary(void);
|
||||||
DynamicDictionary(Dictionary::Ptr serializedDictionary);
|
// DynamicDictionary(Dictionary::Ptr serializedDictionary);
|
||||||
|
|
||||||
void AddParent(DynamicDictionary::Ptr parent);
|
// void AddParent(DynamicDictionary::Ptr parent);
|
||||||
void ClearParents(void);
|
// void ClearParents(void);
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool GetProperty(string name, T *value, DynamicDictionaryOperator *op) const
|
bool GetProperty(string name, T *value, DynamicDictionaryOperator *op) const
|
||||||
|
@ -63,14 +63,20 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void SetProperty(string name, const T& value, DynamicDictionaryOperator op);
|
void SetProperty(string name, const T& value, DynamicDictionaryOperator op)
|
||||||
|
{
|
||||||
|
DynamicDictionaryValue ddv;
|
||||||
|
ddv.Value = value;
|
||||||
|
ddv.Operator = op;
|
||||||
|
m_Values[name] = ddv;
|
||||||
|
}
|
||||||
|
|
||||||
Dictionary::Ptr ToFlatDictionary(void) const;
|
// Dictionary::Ptr ToFlatDictionary(void) const;
|
||||||
|
|
||||||
Dictionary::Ptr Serialize(void);
|
// Dictionary::Ptr Serialize(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
set<DynamicDictionary::Ptr> m_Parents;
|
// set<DynamicDictionary::Ptr> m_Parents;
|
||||||
map<string, DynamicDictionaryValue> m_Values;
|
map<string, DynamicDictionaryValue> m_Values;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -76,18 +76,18 @@ ObjectMap::Range ObjectMap::GetRange(string key)
|
||||||
|
|
||||||
int ObjectMap::ObjectAddedHandler(const ObjectSetEventArgs& ea)
|
int ObjectMap::ObjectAddedHandler(const ObjectSetEventArgs& ea)
|
||||||
{
|
{
|
||||||
AddObject(ea.Object);
|
AddObject(ea.Target);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ObjectMap::ObjectCommittedHandler(const ObjectSetEventArgs& ea)
|
int ObjectMap::ObjectCommittedHandler(const ObjectSetEventArgs& ea)
|
||||||
{
|
{
|
||||||
CheckObject(ea.Object);
|
CheckObject(ea.Target);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ObjectMap::ObjectRemovedHandler(const ObjectSetEventArgs& ea)
|
int ObjectMap::ObjectRemovedHandler(const ObjectSetEventArgs& ea)
|
||||||
{
|
{
|
||||||
RemoveObject(ea.Object);
|
RemoveObject(ea.Target);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,4 +56,4 @@ private:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif OBJECTMAP_H
|
#endif /* OBJECTMAP_H */
|
||||||
|
|
|
@ -34,7 +34,8 @@ ObjectSet::ObjectSet(const ObjectSet::Ptr& parent, ObjectPredicate filter)
|
||||||
void ObjectSet::Start(void)
|
void ObjectSet::Start(void)
|
||||||
{
|
{
|
||||||
if (m_Parent) {
|
if (m_Parent) {
|
||||||
m_Parent->OnObjectCommitted += bind_weak(&ObjectSet::ObjectCommittedHandler, shared_from_this());
|
m_Parent->OnObjectAdded += bind_weak(&ObjectSet::ObjectAddedOrCommittedHandler, shared_from_this());
|
||||||
|
m_Parent->OnObjectCommitted += bind_weak(&ObjectSet::ObjectAddedOrCommittedHandler, shared_from_this());
|
||||||
m_Parent->OnObjectRemoved += bind_weak(&ObjectSet::ObjectRemovedHandler, shared_from_this());
|
m_Parent->OnObjectRemoved += bind_weak(&ObjectSet::ObjectRemovedHandler, shared_from_this());
|
||||||
|
|
||||||
for (ObjectSet::Iterator it = m_Parent->Begin(); it != m_Parent->End(); it++)
|
for (ObjectSet::Iterator it = m_Parent->Begin(); it != m_Parent->End(); it++)
|
||||||
|
@ -48,7 +49,7 @@ void ObjectSet::AddObject(const Object::Ptr& object)
|
||||||
|
|
||||||
ObjectSetEventArgs ea;
|
ObjectSetEventArgs ea;
|
||||||
ea.Source = shared_from_this();
|
ea.Source = shared_from_this();
|
||||||
ea.Object = object;
|
ea.Target = object;
|
||||||
OnObjectAdded(ea);
|
OnObjectAdded(ea);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +62,7 @@ void ObjectSet::RemoveObject(const Object::Ptr& object)
|
||||||
|
|
||||||
ObjectSetEventArgs ea;
|
ObjectSetEventArgs ea;
|
||||||
ea.Source = shared_from_this();
|
ea.Source = shared_from_this();
|
||||||
ea.Object = object;
|
ea.Target = object;
|
||||||
OnObjectRemoved(ea);
|
OnObjectRemoved(ea);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,21 +84,21 @@ void ObjectSet::CheckObject(const Object::Ptr& object)
|
||||||
else {
|
else {
|
||||||
ObjectSetEventArgs ea;
|
ObjectSetEventArgs ea;
|
||||||
ea.Source = shared_from_this();
|
ea.Source = shared_from_this();
|
||||||
ea.Object = object;
|
ea.Target = object;
|
||||||
OnObjectCommitted(ea);
|
OnObjectCommitted(ea);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ObjectSet::ObjectCommittedHandler(const ObjectSetEventArgs& ea)
|
int ObjectSet::ObjectAddedOrCommittedHandler(const ObjectSetEventArgs& ea)
|
||||||
{
|
{
|
||||||
CheckObject(ea.Object);
|
CheckObject(ea.Target);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ObjectSet::ObjectRemovedHandler(const ObjectSetEventArgs& ea)
|
int ObjectSet::ObjectRemovedHandler(const ObjectSetEventArgs& ea)
|
||||||
{
|
{
|
||||||
RemoveObject(ea.Object);
|
RemoveObject(ea.Target);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace icinga
|
||||||
|
|
||||||
struct ObjectSetEventArgs : public EventArgs
|
struct ObjectSetEventArgs : public EventArgs
|
||||||
{
|
{
|
||||||
Object::Ptr Object;
|
Object::Ptr Target;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef function<bool (const Object::Ptr&)> ObjectPredicate;
|
typedef function<bool (const Object::Ptr&)> ObjectPredicate;
|
||||||
|
@ -64,7 +64,7 @@ private:
|
||||||
ObjectSet::Ptr m_Parent;
|
ObjectSet::Ptr m_Parent;
|
||||||
ObjectPredicate m_Filter;
|
ObjectPredicate m_Filter;
|
||||||
|
|
||||||
int ObjectCommittedHandler(const ObjectSetEventArgs& ea);
|
int ObjectAddedOrCommittedHandler(const ObjectSetEventArgs& ea);
|
||||||
int ObjectRemovedHandler(const ObjectSetEventArgs& ea);
|
int ObjectRemovedHandler(const ObjectSetEventArgs& ea);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2,36 +2,37 @@
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
bool foogetter(const Object::Ptr& object, string *key)
|
bool propgetter(string prop, const Object::Ptr& object, string *key)
|
||||||
{
|
{
|
||||||
DynamicObject::Ptr dobj = dynamic_pointer_cast<DynamicObject>(object);
|
DynamicObject::Ptr dobj = dynamic_pointer_cast<DynamicObject>(object);
|
||||||
return dobj->GetConfig()->GetProperty("foo", key);
|
return dobj->GetConfig()->GetProperty(prop, key);
|
||||||
}
|
|
||||||
|
|
||||||
bool foo(const Object::Ptr& object)
|
|
||||||
{
|
|
||||||
DynamicObject::Ptr dobj = dynamic_pointer_cast<DynamicObject>(object);
|
|
||||||
|
|
||||||
string value;
|
|
||||||
return dobj->GetConfig()->GetProperty("foo", &value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 1000000; i++) {
|
for (int i = 0; i < 10000; i++) {
|
||||||
|
stringstream sname;
|
||||||
|
sname << "foo" << i;
|
||||||
|
|
||||||
DynamicObject::Ptr dobj = make_shared<DynamicObject>();
|
DynamicObject::Ptr dobj = make_shared<DynamicObject>();
|
||||||
dobj->GetConfig()->SetProperty("foo", "bar");
|
dobj->GetConfig()->SetProperty("type", "process");
|
||||||
|
dobj->GetConfig()->SetProperty("name", sname.str());
|
||||||
dobj->Commit();
|
dobj->Commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectSet::Ptr filtered = make_shared<ObjectSet>(ObjectSet::GetAllObjects(), &foo);
|
ObjectMap::Ptr byType = make_shared<ObjectMap>(ObjectSet::GetAllObjects(),
|
||||||
filtered->Start();
|
bind(&propgetter, "type", _1, _2));
|
||||||
|
byType->Start();
|
||||||
|
|
||||||
ObjectMap::Ptr m = make_shared<ObjectMap>(ObjectSet::GetAllObjects(), &foogetter);
|
ObjectMap::Ptr byName = make_shared<ObjectMap>(ObjectSet::GetAllObjects(),
|
||||||
m->Start();
|
bind(&propgetter, "name", _1, _2));
|
||||||
|
byName->Start();
|
||||||
|
|
||||||
ObjectMap::Range range = m->GetRange("bar");
|
ObjectMap::Range processes = byType->GetRange("process");
|
||||||
cout << distance(range.first, range.second) << " elements" << endl;
|
cout << distance(processes.first, processes.second) << " processes" << endl;
|
||||||
|
|
||||||
|
ObjectMap::Range foo55 = byName->GetRange("foo55");
|
||||||
|
cout << distance(foo55.first, foo55.second) << " foo55s" << endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue