Build fix for GCC.

This commit is contained in:
Gunnar Beutner 2012-05-31 08:54:36 +02:00
parent 8144ca398b
commit f971152349
6 changed files with 46 additions and 38 deletions

View File

@ -45,10 +45,10 @@ public:
typedef weak_ptr<DynamicDictionary> WeakPtr;
DynamicDictionary(void);
DynamicDictionary(Dictionary::Ptr serializedDictionary);
// DynamicDictionary(Dictionary::Ptr serializedDictionary);
void AddParent(DynamicDictionary::Ptr parent);
void ClearParents(void);
// void AddParent(DynamicDictionary::Ptr parent);
// void ClearParents(void);
template<typename T>
bool GetProperty(string name, T *value, DynamicDictionaryOperator *op) const
@ -63,14 +63,20 @@ public:
}
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:
set<DynamicDictionary::Ptr> m_Parents;
// set<DynamicDictionary::Ptr> m_Parents;
map<string, DynamicDictionaryValue> m_Values;
};

View File

@ -76,18 +76,18 @@ ObjectMap::Range ObjectMap::GetRange(string key)
int ObjectMap::ObjectAddedHandler(const ObjectSetEventArgs& ea)
{
AddObject(ea.Object);
AddObject(ea.Target);
return 0;
}
int ObjectMap::ObjectCommittedHandler(const ObjectSetEventArgs& ea)
{
CheckObject(ea.Object);
CheckObject(ea.Target);
return 0;
}
int ObjectMap::ObjectRemovedHandler(const ObjectSetEventArgs& ea)
{
RemoveObject(ea.Object);
RemoveObject(ea.Target);
return 0;
}

View File

@ -56,4 +56,4 @@ private:
}
#endif OBJECTMAP_H
#endif /* OBJECTMAP_H */

View File

@ -34,7 +34,8 @@ ObjectSet::ObjectSet(const ObjectSet::Ptr& parent, ObjectPredicate filter)
void ObjectSet::Start(void)
{
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());
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;
ea.Source = shared_from_this();
ea.Object = object;
ea.Target = object;
OnObjectAdded(ea);
}
@ -61,7 +62,7 @@ void ObjectSet::RemoveObject(const Object::Ptr& object)
ObjectSetEventArgs ea;
ea.Source = shared_from_this();
ea.Object = object;
ea.Target = object;
OnObjectRemoved(ea);
}
}
@ -83,21 +84,21 @@ void ObjectSet::CheckObject(const Object::Ptr& object)
else {
ObjectSetEventArgs ea;
ea.Source = shared_from_this();
ea.Object = object;
ea.Target = object;
OnObjectCommitted(ea);
}
}
}
int ObjectSet::ObjectCommittedHandler(const ObjectSetEventArgs& ea)
int ObjectSet::ObjectAddedOrCommittedHandler(const ObjectSetEventArgs& ea)
{
CheckObject(ea.Object);
CheckObject(ea.Target);
return 0;
}
int ObjectSet::ObjectRemovedHandler(const ObjectSetEventArgs& ea)
{
RemoveObject(ea.Object);
RemoveObject(ea.Target);
return 0;
}

View File

@ -25,7 +25,7 @@ namespace icinga
struct ObjectSetEventArgs : public EventArgs
{
Object::Ptr Object;
Object::Ptr Target;
};
typedef function<bool (const Object::Ptr&)> ObjectPredicate;
@ -64,7 +64,7 @@ private:
ObjectSet::Ptr m_Parent;
ObjectPredicate m_Filter;
int ObjectCommittedHandler(const ObjectSetEventArgs& ea);
int ObjectAddedOrCommittedHandler(const ObjectSetEventArgs& ea);
int ObjectRemovedHandler(const ObjectSetEventArgs& ea);
};

View File

@ -2,36 +2,37 @@
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);
return dobj->GetConfig()->GetProperty("foo", key);
}
bool foo(const Object::Ptr& object)
{
DynamicObject::Ptr dobj = dynamic_pointer_cast<DynamicObject>(object);
string value;
return dobj->GetConfig()->GetProperty("foo", &value);
return dobj->GetConfig()->GetProperty(prop, key);
}
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>();
dobj->GetConfig()->SetProperty("foo", "bar");
dobj->GetConfig()->SetProperty("type", "process");
dobj->GetConfig()->SetProperty("name", sname.str());
dobj->Commit();
}
ObjectSet::Ptr filtered = make_shared<ObjectSet>(ObjectSet::GetAllObjects(), &foo);
filtered->Start();
ObjectMap::Ptr byType = make_shared<ObjectMap>(ObjectSet::GetAllObjects(),
bind(&propgetter, "type", _1, _2));
byType->Start();
ObjectMap::Ptr m = make_shared<ObjectMap>(ObjectSet::GetAllObjects(), &foogetter);
m->Start();
ObjectMap::Ptr byName = make_shared<ObjectMap>(ObjectSet::GetAllObjects(),
bind(&propgetter, "name", _1, _2));
byName->Start();
ObjectMap::Range range = m->GetRange("bar");
cout << distance(range.first, range.second) << " elements" << endl;
ObjectMap::Range processes = byType->GetRange("process");
cout << distance(processes.first, processes.second) << " processes" << endl;
ObjectMap::Range foo55 = byName->GetRange("foo55");
cout << distance(foo55.first, foo55.second) << " foo55s" << endl;
return 0;
}