]> granicus.if.org Git - icinga2/commitdiff
Use BOOST_FOREACH for most for loops.
authorGunnar Beutner <gunnar.beutner@netways.de>
Mon, 16 Jul 2012 20:00:50 +0000 (22:00 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Mon, 16 Jul 2012 20:00:50 +0000 (22:00 +0200)
30 files changed:
base/application.cpp
base/dictionary.h
base/event.cpp
base/i2-base.h
base/logger.cpp
base/objectmap.h
base/objectset.h
base/process.cpp
cib/cib.vcxproj
cib/cib.vcxproj.filters
cib/host.cpp
cib/macroprocessor.cpp
cib/nagioschecktask.cpp
cib/nullchecktask.cpp
cib/service.cpp
components/cibsync/cibsynccomponent.cpp
components/compat/compatcomponent.cpp
components/configfile/configfilecomponent.cpp
components/convenience/conveniencecomponent.cpp
components/delegation/delegationcomponent.cpp
components/discovery/discoverycomponent.cpp
components/discovery/discoverymessage.cpp
components/discovery/discoverymessage.h
dyn/configcompiler.cpp
dyn/configitem.cpp
dyn/expression.cpp
dyn/expressionlist.cpp
dyn/expressionlist.h
icinga/endpointmanager.cpp
jsonrpc/jsonrpcclient.cpp

index 253d9d3e4ca47c66aecba93979bb429990e0d7c7..fe17a1ddaa3557b8fb4f94b6baef87eec08424eb 100644 (file)
@@ -61,9 +61,9 @@ Application::~Application(void)
        m_ShuttingDown = true;
 
        /* stop all components */
-       for (map<string, Component::Ptr>::iterator i = m_Components.begin();
-           i != m_Components.end(); i++) {
-               i->second->Stop();
+       Component::Ptr component;
+       BOOST_FOREACH(tie(tuples::ignore, component), m_Components) {
+               component->Stop();
        }
 
        m_Components.clear();
@@ -243,8 +243,8 @@ string Application::GetExePath(void) const
                        boost::algorithm::split(paths, pathEnv, boost::is_any_of(":"));
 
                        bool foundPath = false;
-                       for (vector<string>::iterator it = paths.begin(); it != paths.end(); it++) {
-                               string pathTest = *it + "/" + argv0;
+                       BOOST_FOREACH(string& path, paths) {
+                               string pathTest = path + "/" + argv0;
 
                                if (access(pathTest.c_str(), X_OK) == 0) {
                                        executablePath = pathTest;
index 28736d01371eba0e47085de2d5422ad0cb607c8b..919a608701ac290a731f2ba0ade8891957c2ffc1 100644 (file)
@@ -34,7 +34,6 @@ public:
        typedef shared_ptr<Dictionary> Ptr;
        typedef weak_ptr<Dictionary> WeakPtr;
 
-       typedef map<string, Variant>::const_iterator ConstIterator;
        typedef map<string, Variant>::iterator Iterator;
 
        /**
@@ -47,7 +46,7 @@ public:
        template<typename T>
        bool Get(const string& key, T *value) const
        {
-               ConstIterator i = m_Data.find(key);
+               map<string, Variant>::const_iterator i = m_Data.find(key);
 
                if (i == m_Data.end())
                        return false;
@@ -110,6 +109,33 @@ private:
        map<string, Variant> m_Data;
 };
 
+inline Dictionary::Iterator range_begin(Dictionary::Ptr x)
+{
+       return x->Begin();
+}
+
+inline Dictionary::Iterator range_end(Dictionary::Ptr x)
+{
+       return x->End();
+}
+
+}
+
+namespace boost
+{
+
+template<>
+struct range_mutable_iterator<icinga::Dictionary::Ptr>
+{
+       typedef icinga::Dictionary::Iterator type;
+};
+
+template<>
+struct range_const_iterator<icinga::Dictionary::Ptr>
+{
+       typedef icinga::Dictionary::Iterator type;
+};
+
 }
 
 #endif /* DICTIONARY_H */
index d3692f60eb16090c0005c847897300aae182130b..83ac4f0155c93adee0542282135161522ddc9e9c 100644 (file)
@@ -44,9 +44,9 @@ void Event::ProcessEvents(const system_time& wait_until)
                events.swap(m_Events);
        }
 
-       vector<Event>::iterator it;
-       for (it = events.begin(); it != events.end(); it++)
-               it->m_Callback();
+       BOOST_FOREACH(const Event& ev, events) {
+               ev.m_Callback();
+       }
 }
 
 void Event::Post(const function<void ()>& callback)
index e953777cfbb1572e351daf67675cb6207dfc58f8..94db9f57ad6274767840cbf1772a4aec9b55bfdf 100644 (file)
@@ -122,6 +122,8 @@ using std::type_info;
 #include <boost/thread.hpp>
 #include <boost/variant.hpp>
 #include <boost/lexical_cast.hpp>
+#include <boost/foreach.hpp>
+#include <boost/tuple/tuple.hpp>
 
 using boost::shared_ptr;
 using boost::weak_ptr;
@@ -134,6 +136,9 @@ using boost::thread_group;
 using boost::mutex;
 using boost::condition_variable;
 using boost::system_time;
+using boost::tie;
+
+namespace tuples = boost::tuples;
 
 #if defined(__APPLE__) && defined(__MACH__)
 #      pragma GCC diagnostic ignored "-Wdeprecated-declarations" 
index 591fe79528d6f4f91e05b1518186a1e0b3a92b8b..7b177af5af49d6bc4384835a783d2322a72f18d0 100644 (file)
@@ -93,10 +93,7 @@ LogSeverity Logger::GetMinSeverity(void) const
  */
 void Logger::ForwardLogEntry(const LogEntry& entry)
 {
-       set<Logger::Ptr>::iterator it;
-       for (it = m_Loggers.begin(); it != m_Loggers.end(); it++) {
-               Logger::Ptr logger = *it;
-
+       BOOST_FOREACH(const Logger::Ptr& logger, m_Loggers) {
                if (entry.Severity >= logger->GetMinSeverity())
                        logger->ProcessLogEntry(entry);
        }
index df9e14da03301adfdb9174dc4b7b143e4a172dbe..b275fc2ce1bae5839717e3a2822775d02236f135 100644 (file)
@@ -47,8 +47,9 @@ public:
                m_Parent->OnObjectCommitted.connect(boost::bind(&ObjectMap::ObjectCommittedHandler, this, _2));
                m_Parent->OnObjectRemoved.connect(boost::bind(&ObjectMap::ObjectRemovedHandler, this, _2));
 
-               for (typename ObjectSet<TValue>::Iterator it = m_Parent->Begin(); it != m_Parent->End(); it++)
-                       AddObject(*it);
+               BOOST_FOREACH(const TValue& object, m_Parent) {
+                       AddObject(object);
+               }
        }
 
        Range GetRange(TKey key)
@@ -60,8 +61,8 @@ public:
        {
                Range range = GetRange(key);
 
-               for (Iterator it = range.first; it != range.second; it++) {
-                       callback(GetSelf(), *it);
+               BOOST_FOREACH(const TValue& object, range) {
+                       callback(GetSelf(), object);
                }
        }
 
@@ -83,16 +84,16 @@ private:
        {
                TKey key;
                if (!m_KeyGetter(object, &key))
-                       return;
+                       return;
 
-               pair<Iterator, Iterator> range = GetRange(key);
+               pair<Iterator, Iterator> range = GetRange(key);
 
-               for (Iterator i = range.first; i != range.second; i++) {
-                       if (i->second == object) {
-                               m_Objects.erase(i);
-                               break;
-                       }
-               }
+               for (Iterator i = range.first; i != range.second; i++) {
+                       if (i->second == object) {
+                               m_Objects.erase(i);
+                               break;
+                       }
+               }
        }
 
        void CheckObject(const TValue& object)
@@ -117,6 +118,35 @@ private:
        }
 };
 
+template<typename TKey, typename TValue>
+typename ObjectMap<TKey, TValue>::Iterator range_begin(typename ObjectMap<TKey, TValue>::Ptr x)
+{
+       return x->Begin();
+}
+
+template <typename TKey, typename TValue>
+typename ObjectSet<TValue>::Iterator range_end(typename ObjectMap<TKey, TValue>::Ptr x)
+{
+       return x->End();
+}
+
+}
+
+namespace boost
+{
+
+template<typename TKey, typename TValue>
+struct range_mutable_iterator<shared_ptr<icinga::ObjectMap<TKey, TValue> > >
+{
+       typedef typename shared_ptr<icinga::ObjectMap<TKey, TValue> >::Iterator type;
+};
+
+template<typename TKey, typename TValue>
+struct range_const_iterator<shared_ptr<icinga::ObjectMap<TKey, TValue> > >
+{
+       typedef typename shared_ptr<icinga::ObjectMap<TKey, TValue> > type;
+};
+
 }
 
 #endif /* OBJECTMAP_H */
index 8441428f952da9da53b79771dc9f4c4d59532985..26cba08703ca65cd1262bcd20b5b2ad40252df5d 100644 (file)
@@ -47,9 +47,10 @@ public:
                        m_Parent->OnObjectCommitted.connect(boost::bind(&ObjectSet::ObjectAddedOrCommittedHandler, this, _2));
                        m_Parent->OnObjectRemoved.connect(boost::bind(&ObjectSet::ObjectRemovedHandler, this, _2));
 
-                       for (ObjectSet::Iterator it = m_Parent->Begin(); it != m_Parent->End(); it++)
-                               CheckObject(*it);
-        }
+                       BOOST_FOREACH(const TValue& object, m_Parent) {
+                               CheckObject(object);
+                       }
+               }
        }
 
        void AddObject(const TValue& object)
@@ -102,8 +103,8 @@ public:
 
        void ForeachObject(function<void (const typename Object::Ptr&, const TValue&)> callback)
        {
-               for (Iterator it = Begin(); it != End(); it++) {
-                       callback(GetSelf(), *it);
+               BOOST_FOREACH(const TValue& object, m_Objects) {
+                       callback(GetSelf(), object);
                }
        }
 
@@ -124,6 +125,35 @@ private:
        }
 };
 
+template<typename TValue>
+typename ObjectSet<TValue>::Iterator range_begin(shared_ptr<ObjectSet<TValue> > x)
+{
+       return x->Begin();
+}
+
+template <typename TValue>
+typename ObjectSet<TValue>::Iterator range_end(shared_ptr<ObjectSet<TValue> > x)
+{
+       return x->End();
+}
+
+}
+
+namespace boost
+{
+
+template<typename TValue>
+struct range_mutable_iterator<shared_ptr<icinga::ObjectSet<TValue> > >
+{
+       typedef typename icinga::ObjectSet<TValue>::Iterator type;
+};
+
+template<typename TValue>
+struct range_const_iterator<shared_ptr<icinga::ObjectSet<TValue> > >
+{
+       typedef typename icinga::ObjectSet<TValue>::Iterator type;
+};
+
 }
 
 #endif /* OBJECTSET_H */
index cc641f80d0cd9615b31cf948ebcaff983b9f44f2..4b24e3881ae2bee7f027ea3c4c4e0238013a454d 100644 (file)
@@ -66,11 +66,12 @@ void Process::WorkerThreadProc(void)
                        
                        FD_ZERO(&readfds);
 
-                       for (it = tasks.begin(); it != tasks.end(); it++) {
-                               if (it->first > nfds)
-                                       nfds = it->first;
+                       int fd;
+                       BOOST_FOREACH(tie(fd, tuples::ignore), tasks);
+                               if (fd > nfds)
+                                       nfds = fd;
 
-                               FD_SET(it->first, &readfds);
+                               FD_SET(fd, &readfds);
                        }
 
                        timeval tv;
index 50c9fdbc7e213ff1629c012a46d68cfb8a991bb3..3b5f858f8a20eacd4060104895ea673105707bea 100644 (file)
@@ -90,6 +90,7 @@
     <ClInclude Include="i2-cib.h" />
     <ClInclude Include="macroprocessor.h" />
     <ClInclude Include="nagioschecktask.h" />
+    <ClInclude Include="nullchecktask.h" />
     <ClInclude Include="service.h" />
     <ClInclude Include="servicegroup.h" />
     <ClInclude Include="servicestatusmessage.h" />
     </ClCompile>
     <ClCompile Include="macroprocessor.cpp" />
     <ClCompile Include="nagioschecktask.cpp" />
+    <ClCompile Include="nullchecktask.cpp" />
     <ClCompile Include="service.cpp" />
     <ClCompile Include="servicegroup.cpp" />
     <ClCompile Include="servicestatusmessage.cpp" />
index 049b0d6881f386b3f395854c1c8df150927acc11..81e391f32b18df28e52b1eec99514f0088316396 100644 (file)
@@ -44,6 +44,9 @@
     <ClInclude Include="servicestatusmessage.h">
       <Filter>Headerdateien</Filter>
     </ClInclude>
+    <ClInclude Include="nullchecktask.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="checkresult.cpp">
@@ -79,5 +82,8 @@
     <ClCompile Include="i2-cib.cpp">
       <Filter>Quelldateien</Filter>
     </ClCompile>
+    <ClCompile Include="nullchecktask.cpp">
+      <Filter>Quelldateien</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>
\ No newline at end of file
index 2b59cc98fd037d19c0f3b36da73c742e41523a9d..9b697c0822145fa8e8a419cecc09ff2498105dc5 100644 (file)
@@ -69,9 +69,9 @@ set<string> Host::GetParents(void) const
        if (GetProperty("dependencies", &dependencies)) {
                dependencies = Service::ResolveDependencies(*this, dependencies);
 
-               Dictionary::Iterator it;
-               for (it = dependencies->Begin(); it != dependencies->End(); it++) {
-                       Service service = Service::GetByName(it->second);
+               string dependency;
+               BOOST_FOREACH(tie(tuples::ignore, dependency), dependencies) {
+                       Service service = Service::GetByName(dependency);
 
                        string parent = service.GetHost().GetName();
 
@@ -99,9 +99,9 @@ bool Host::IsReachable(void) const
        if (GetProperty("dependencies", &dependencies)) {
                dependencies = Service::ResolveDependencies(*this, dependencies);
 
-               Dictionary::Iterator it;
-               for (it = dependencies->Begin(); it != dependencies->End(); it++) {
-                       Service service = Service::GetByName(it->second);
+               string dependency;
+               BOOST_FOREACH(tie(tuples::ignore, dependency), dependencies) {
+                       Service service = Service::GetByName(dependency);
 
                        if (!service.IsReachable() ||
                            (service.GetState() != StateOK && service.GetState() != StateWarning)) {
@@ -119,9 +119,10 @@ bool Host::IsUp(void) const
        if (GetProperty("hostchecks", &hostchecks)) {
                hostchecks = Service::ResolveDependencies(*this, hostchecks);
 
-               Dictionary::Iterator it;
-               for (it = hostchecks->Begin(); it != hostchecks->End(); it++) {
-                       Service service = Service::GetByName(it->second);
+               string hostcheck;
+               BOOST_FOREACH(tie(tuples::ignore, hostcheck), hostchecks) {
+                       Service service = Service::GetByName(hostcheck);
+
                        if (service.GetState() != StateOK && service.GetState() != StateWarning) {
                                return false;
                        }
index de5a2522849e2121097a937559fd4f0154af56d6..4bd4aeb2ff1e094dfc205151fa586bda957cc37d 100644 (file)
@@ -38,10 +38,8 @@ string MacroProcessor::ResolveMacros(const string& str, const vector<Dictionary:
                string value;
                bool resolved = false;
 
-               vector<Dictionary::Ptr>::const_iterator it;
-               for (it = macroDicts.begin(); it != macroDicts.end(); it++) {
-                       Dictionary::Ptr macros = *it;
-                       if (macros && macros->Get(name, &value)) {
+               BOOST_FOREACH(const Dictionary::Ptr& macroDict, macroDicts) {
+                       if (macroDict && macroDict->Get(name, &value)) {
                                resolved = true;
                                break;
                        }
index c8493df6dc89eff03375893c35f06ec82e8d36e8..6be960c703c91f52b2e22bef02a09851818a88bd 100644 (file)
@@ -110,10 +110,7 @@ void NagiosCheckTask::ProcessCheckOutput(CheckResult& result, const string& outp
        vector<string> lines;
        boost::algorithm::split(lines, output, is_any_of("\r\n"));
 
-       vector<string>::iterator it;
-       for (it = lines.begin(); it != lines.end(); it++) {
-               const string& line = *it;
-
+       BOOST_FOREACH (const string& line, lines) {
                string::size_type delim = line.find('|');
 
                if (!text.empty())
index f0ca1b9a00a12f13cbec670e1ef5504906ecc12b..479bbc95eac28346f6425597945558ae819a7721 100644 (file)
@@ -39,8 +39,8 @@ void NullCheckTask::ScriptFunc(const ScriptTask::Ptr& task, const vector<Variant
        task->FinishResult(cr.GetDictionary());
 }
 
-void NullCheckTask::Register(void)                                            
+void NullCheckTask::Register(void)
 {
-        ScriptFunction::Ptr func = boost::make_shared<ScriptFunction>(&NullCheckTask::ScriptFunc);
-        ScriptFunction::Register("native::NullCheck", func);
+       ScriptFunction::Ptr func = boost::make_shared<ScriptFunction>(&NullCheckTask::ScriptFunc);
+       ScriptFunction::Register("native::NullCheck", func);
 }
index 8092e024c26ab23be1044fb4dceae2167e802901..33773203e0b18d9108fe00cf63f7e7524a17d5f9 100644 (file)
@@ -117,14 +117,14 @@ void Service::GetDependenciesRecursive(const Dictionary::Ptr& result) const {
        if (!dependencies)
                return;
 
-       Dictionary::Iterator it;
-       for (it = dependencies->Begin(); it != dependencies->End(); it++) {
-               if (result->Contains(it->second))
+       string dependency;
+       BOOST_FOREACH(tie(tuples::ignore, dependency), dependencies) {
+               if (result->Contains(dependency))
                        continue;
 
-               result->Set(it->second, it->second);
+               result->Set(dependency, dependency);
 
-               Service service = Service::GetByName(it->second);
+               Service service = Service::GetByName(dependency);
                service.GetDependenciesRecursive(result);
        }
 }
@@ -148,9 +148,9 @@ bool Service::IsReachable(void) const
        Dictionary::Ptr dependencies = boost::make_shared<Dictionary>();
        GetDependenciesRecursive(dependencies);
 
-       Dictionary::Iterator it;
-       for (it = dependencies->Begin(); it != dependencies->End(); it++) {
-               Service service = Service::GetByName(it->second);
+       string dependency;
+       BOOST_FOREACH(tie(tuples::ignore, dependency), dependencies) {
+               Service service = Service::GetByName(dependency);
 
                /* ignore ourselves */
                if (service.GetName() == GetName())
@@ -379,10 +379,8 @@ bool Service::IsAllowedChecker(const string& checker) const
        if (!checkers)
                return true;
 
-       Dictionary::Iterator it;
-       for (it = checkers->Begin(); it != checkers->End(); it++) {
-               string pattern = it->second;
-
+       string pattern;
+       BOOST_FOREACH(tie(tuples::ignore, pattern), checkers) {
                if (Utility::Match(pattern, checker))
                        return true;
        }
@@ -397,14 +395,14 @@ Dictionary::Ptr Service::ResolveDependencies(Host host, const Dictionary::Ptr& d
 
        Dictionary::Ptr result = boost::make_shared<Dictionary>();
 
-       Dictionary::Iterator it;
-       for (it = dependencies->Begin(); it != dependencies->End(); it++) {
+       string dependency;
+       BOOST_FOREACH(tie(tuples::ignore, dependency), dependencies) {
                string name;
 
-               if (services && services->Contains(it->first))
-                       name = host.GetName() + "-" + it->first;
+               if (services && services->Contains(dependency))
+                       name = host.GetName() + "-" + dependency;
                else
-                       name = it->first;
+                       name = dependency;
 
                result->Set(name, name);
        }
index 7c0d27c472fd1c6b09508ab7fedbe44a70a92804..9ff9396035d8fbe7ac79aeddb0b58dc6633422c4 100644 (file)
@@ -171,9 +171,7 @@ void CIBSyncComponent::FetchObjectsHandler(const Endpoint::Ptr& sender)
 {
        ConfigObject::Set::Ptr allObjects = ConfigObject::GetAllObjects();
 
-       for (ConfigObject::Set::Iterator ci = allObjects->Begin(); ci != allObjects->End(); ci++) {
-               ConfigObject::Ptr object = *ci;
-
+       BOOST_FOREACH(const ConfigObject::Ptr& object, allObjects) {
                if (!ShouldReplicateObject(object))
                        continue;
 
index 37473b6f8a7aaa4d13a34f0ba2d165f3322cd263..0d759368f27dfae02285ccf4f85f47e78be6f486 100644 (file)
@@ -148,7 +148,7 @@ void CompatComponent::DumpServiceStatus(ofstream& fp, Service service)
                state = StateUnknown;
 
        fp << "servicestatus {" << "\n"
-           << "\t" << "host_name=" << service.GetHost().GetName() << "\n"
+          << "\t" << "host_name=" << service.GetHost().GetName() << "\n"
           << "\t" << "service_description=" << service.GetAlias() << "\n"
           << "\t" << "check_interval=" << service.GetCheckInterval() / 60.0 << "\n"
           << "\t" << "retry_interval=" << service.GetRetryInterval() / 60.0 << "\n"
@@ -233,31 +233,34 @@ void CompatComponent::StatusTimerHandler(void)
        ConfigObject::TMap::Range range;
        range = ConfigObject::GetObjects("host");
 
-       ConfigObject::TMap::Iterator it;
-       for (it = range.first; it != range.second; it++) {
-               Host host = it->second;
+       ConfigObject::Ptr object;
+       BOOST_FOREACH(tie(tuples::ignore, object), range) {
+               Host host = object;
 
                Dictionary::Ptr dict;
-               Dictionary::Iterator dt;
-
                dict = host.GetGroups();
 
                if (dict) {
-                       for (dt = dict->Begin(); dt != dict->End(); dt++)
-                               hostgroups[dt->second].push_back(host.GetName());
+                       string hostgroup;
+                       BOOST_FOREACH(tie(tuples::ignore, hostgroup), dict) {
+                               hostgroups[hostgroup].push_back(host.GetName());
+                       }
                }
 
                DumpHostStatus(statusfp, host);
                DumpHostObject(objectfp, host);
        }
 
-       map<string, vector<string> >::iterator hgt;
-       for (hgt = hostgroups.begin(); hgt != hostgroups.end(); hgt++) {
+       pair<string, vector<string > > hgt;
+       BOOST_FOREACH(hgt, hostgroups) {
+               const string& name = hgt.first;
+               const vector<string>& hosts = hgt.second;
+
                objectfp << "define hostgroup {" << "\n"
-                        << "\t" << "hostgroup_name" << "\t" << hgt->first << "\n";
+                        << "\t" << "hostgroup_name" << "\t" << name << "\n";
 
-               if (HostGroup::Exists(hgt->first)) {
-                       HostGroup hg = HostGroup::GetByName(hgt->first);
+               if (HostGroup::Exists(name)) {
+                       HostGroup hg = HostGroup::GetByName(name);
                        objectfp << "\t" << "alias" << "\t" << hg.GetAlias() << "\n"
                                 << "\t" << "notes_url" << "\t" << hg.GetNotesUrl() << "\n"
                                 << "\t" << "action_url" << "\t" << hg.GetActionUrl() << "\n";
@@ -265,7 +268,7 @@ void CompatComponent::StatusTimerHandler(void)
 
                objectfp << "\t" << "members" << "\t";
 
-               DumpStringList(objectfp, hgt->second);
+               DumpStringList(objectfp, hosts);
 
                objectfp << "\n"
                         << "}" << "\n";
@@ -275,30 +278,34 @@ void CompatComponent::StatusTimerHandler(void)
 
        map<string, vector<Service> > servicegroups;
 
-       for (it = range.first; it != range.second; it++) {
-               Service service = it->second;
+       BOOST_FOREACH(tie(tuples::ignore, object), range) {
+               Service service = object;
 
                Dictionary::Ptr dict;
-               Dictionary::Iterator dt;
 
                dict = service.GetGroups();
 
                if (dict) {
-                       for (dt = dict->Begin(); dt != dict->End(); dt++)
-                               servicegroups[dt->second].push_back(service);
+                       string servicegroup;
+                       BOOST_FOREACH(tie(tuples::ignore, servicegroup), dict) {
+                               servicegroups[servicegroup].push_back(service);
+                       }
                }
 
                DumpServiceStatus(statusfp, service);
                DumpServiceObject(objectfp, service);
        }
 
-       map<string, vector<Service > >::iterator sgt;
-       for (sgt = servicegroups.begin(); sgt != servicegroups.end(); sgt++) {
+       pair<string, vector<Service > > sgt;
+       BOOST_FOREACH(sgt, servicegroups) {
+               const string& name = sgt.first;
+               const vector<Service>& services = sgt.second;
+
                objectfp << "define servicegroup {" << "\n"
-                        << "\t" << "servicegroup_name" << "\t" << sgt->first << "\n";
+                        << "\t" << "servicegroup_name" << "\t" << name << "\n";
 
-               if (ServiceGroup::Exists(sgt->first)) {
-                       ServiceGroup sg = ServiceGroup::GetByName(sgt->first);
+               if (ServiceGroup::Exists(name)) {
+                       ServiceGroup sg = ServiceGroup::GetByName(name);
                        objectfp << "\t" << "alias" << "\t" << sg.GetAlias() << "\n"
                                 << "\t" << "notes_url" << "\t" << sg.GetNotesUrl() << "\n"
                                 << "\t" << "action_url" << "\t" << sg.GetActionUrl() << "\n";
@@ -309,9 +316,9 @@ void CompatComponent::StatusTimerHandler(void)
                vector<string> sglist;
                vector<Service>::iterator vt;
 
-               for (vt = sgt->second.begin(); vt != sgt->second.end(); vt++) {
-                       sglist.push_back(vt->GetHost().GetName());
-                       sglist.push_back(vt->GetAlias());
+               BOOST_FOREACH(const Service& service, services) {
+                       sglist.push_back(service.GetHost().GetName());
+                       sglist.push_back(service.GetAlias());
                }
 
                DumpStringList(objectfp, sglist);
index e0d753f48fb1d39d09bfcbad1abb6036a86aa1a4..6f9a2f71867f3374c49fd54f705c1aad147aa609 100644 (file)
@@ -40,9 +40,7 @@ void ConfigFileComponent::Start(void)
 
        Logger::Write(LogInformation, "configfile", "Executing config items...");
 
-       vector<ConfigItem::Ptr>::iterator it;
-       for (it = configItems.begin(); it != configItems.end(); it++) {
-               ConfigItem::Ptr item = *it;
+       BOOST_FOREACH(const ConfigItem::Ptr& item, configItems) {
                item->Commit();
        }
 }
index 8c7632fc79dcbcafddda4f5ac174d132a7ff7911..afcfcea925827b309b7873ac2ff30a86820ef716 100644 (file)
@@ -111,11 +111,9 @@ void ConvenienceComponent::HostCommittedHandler(const ConfigItem::Ptr& item)
        host->GetProperty("services", &serviceDescs);
 
        if (serviceDescs) {
-               Dictionary::Iterator it;
-               for (it = serviceDescs->Begin(); it != serviceDescs->End(); it++) {
-                       string svcname = it->first;
-                       Variant svcdesc = it->second;
-
+               string svcname;
+               Variant svcdesc;
+               BOOST_FOREACH(tie(svcname, svcdesc), serviceDescs) {
                        stringstream namebuf;
                        namebuf << item->GetName() << "-" << svcname;
                        string name = namebuf.str();
@@ -152,10 +150,8 @@ void ConvenienceComponent::HostCommittedHandler(const ConfigItem::Ptr& item)
        }
 
        if (oldServices) {
-               Dictionary::Iterator it;
-               for (it = oldServices->Begin(); it != oldServices->End(); it++) {
-                       ConfigItem::Ptr service = it->second;
-
+               ConfigItem::Ptr service;
+               BOOST_FOREACH(tie(tuples::ignore, service), oldServices) {
                        if (!newServices->Contains(service->GetName()))
                                service->Unregister();
                }
@@ -180,9 +176,8 @@ void ConvenienceComponent::HostRemovedHandler(const ConfigItem::Ptr& item)
        if (!services)
                return;
 
-       Dictionary::Iterator it;
-       for (it = services->Begin(); it != services->End(); it++) {
-               ConfigItem::Ptr service = it->second;
+       ConfigItem::Ptr service;
+       BOOST_FOREACH(tie(tuples::ignore, service), services) {
                service->Unregister();
        }
 }
index fc4ac880f85729c66701caef5f94a0488b835f33..d061e07598c15ad1a133e021babc445abff626ce 100644 (file)
@@ -161,9 +161,8 @@ void DelegationComponent::SessionEstablishedHandler(const Endpoint::Ptr& endpoin
                return;
 
        /* locally clear checker for all services that previously belonged to this endpoint */
-       ConfigObject::Set::Iterator it;
-       for (it = m_AllServices->Begin(); it != m_AllServices->End(); it++) {
-               Service service = *it;
+       BOOST_FOREACH(const ConfigObject::Ptr& object, m_AllServices) {
+               Service service = object;
 
                if (service.GetChecker() == endpoint->GetIdentity())
                        service.SetChecker("");
@@ -184,9 +183,8 @@ void DelegationComponent::DelegationTimerHandler(void)
        vector<Service> services;
 
        /* build "checker -> service count" histogram */
-       ConfigObject::Set::Iterator it;
-       for (it = m_AllServices->Begin(); it != m_AllServices->End(); it++) {
-               Service service = *it;
+       BOOST_FOREACH(const ConfigObject::Ptr& object, m_AllServices) {
+               Service service = object;
 
                services.push_back(service);
 
@@ -207,10 +205,7 @@ void DelegationComponent::DelegationTimerHandler(void)
        int delegated = 0;
 
        /* re-assign services */
-       vector<Service>::iterator sit;
-       for (sit = services.begin(); sit != services.end(); sit++) {
-               Service service = *sit;
-
+       BOOST_FOREACH(Service& service, services) {
                string checker = service.GetChecker();
 
                Endpoint::Ptr oldEndpoint;
@@ -229,8 +224,9 @@ void DelegationComponent::DelegationTimerHandler(void)
                        msgbuf << "Service: " << service.GetName() << ", candidates: " << candidates.size();
                        Logger::Write(LogDebug, "delegation", msgbuf.str());
 
-                       for (cit = candidates.begin(); cit != candidates.end(); cit++)
-                               avg_services += histogram[*cit];
+                       BOOST_FOREACH(const Endpoint::Ptr& candidate, candidates) {
+                               avg_services += histogram[candidate];
+                       }
 
                        avg_services /= candidates.size();
                        overflow_tolerance = candidates.size() * 2;
@@ -253,15 +249,13 @@ void DelegationComponent::DelegationTimerHandler(void)
                }
 
                /* find a new checker for the service */
-               for (cit = candidates.begin(); cit != candidates.end(); cit++) {
-                       Endpoint::Ptr newEndpoint = *cit;
-
+               BOOST_FOREACH(const Endpoint::Ptr& candidate, candidates) {
                        /* does this checker already have too many services */
-                       if (histogram[newEndpoint] > avg_services)
+                       if (histogram[candidate] > avg_services)
                                continue;
 
-                       service.SetChecker(newEndpoint->GetIdentity());
-                       histogram[newEndpoint]++;
+                       service.SetChecker(candidate->GetIdentity());
+                       histogram[candidate]++;
 
                        delegated++;
 
@@ -271,29 +265,30 @@ void DelegationComponent::DelegationTimerHandler(void)
                assert(candidates.size() == 0 || !service.GetChecker().empty());
        }
 
-       map<Endpoint::Ptr, int>::iterator hit;
-       for (hit = histogram.begin(); hit != histogram.end(); hit++) {
+       Endpoint::Ptr endpoint;
+       int count;
+       BOOST_FOREACH(tie(endpoint, count), histogram) {
                stringstream msgbuf;
-               msgbuf << "histogram: " << hit->first->GetIdentity() << " - " << hit->second;
+               msgbuf << "histogram: " << endpoint->GetIdentity() << " - " << count;
                Logger::Write(LogInformation, "delegation", msgbuf.str());
        }
 
        if (delegated > 0) {
                if (need_clear) {
-                       map<Endpoint::Ptr, int>::iterator hit;
-                       for (hit = histogram.begin(); hit != histogram.end(); hit++) {
-                               ClearServices(hit->first);
+                       Endpoint::Ptr endpoint;
+                       BOOST_FOREACH(tie(endpoint, tuples::ignore), histogram) {
+                               ClearServices(endpoint);
                        }
                }
 
-               for (sit = services.begin(); sit != services.end(); sit++) {
-                       string checker = sit->GetChecker();
+               BOOST_FOREACH(Service& service, services) {
+                       string checker = service.GetChecker();
                        Endpoint::Ptr endpoint = EndpointManager::GetInstance()->GetEndpointByIdentity(checker);
 
                        if (!endpoint)
                                continue;
 
-                       AssignService(endpoint, *sit);
+                       AssignService(endpoint, service);
                }
        }
 
index 2b7102e3b95d78b6e699f0a32c15ee933cd1b867..29811a2ae9d090fda32442214afadedaa697d31c 100644 (file)
@@ -168,12 +168,13 @@ void DiscoveryComponent::NewEndpointHandler(const Endpoint::Ptr& endpoint)
 
        // register published/subscribed topics for this endpoint
        ComponentDiscoveryInfo::Ptr info = ic->second;
-       set<string>::iterator it;
-       for (it = info->Publications.begin(); it != info->Publications.end(); it++)
-               endpoint->RegisterPublication(*it);
+       BOOST_FOREACH(string publication, info->Publications) {
+               endpoint->RegisterPublication(publication);
+       }
 
-       for (it = info->Subscriptions.begin(); it != info->Subscriptions.end(); it++)
-               endpoint->RegisterSubscription(*it);
+       BOOST_FOREACH(string subscription, info->Subscriptions) {
+               endpoint->RegisterSubscription(subscription);
+       }
 
        FinishDiscoverySetup(endpoint);
 }
@@ -299,15 +300,17 @@ void DiscoveryComponent::SendDiscoveryMessage(const string& method, const string
        }
 
        set<string>::iterator i;
-       MessagePart subscriptions;
-       for (i = info->Subscriptions.begin(); i != info->Subscriptions.end(); i++)
-               subscriptions.Add(*i);
+       Dictionary::Ptr subscriptions = boost::make_shared<Dictionary>();
+       BOOST_FOREACH(string subscription, info->Subscriptions) {
+               subscriptions->Add(subscription);
+       }
 
        params.SetSubscriptions(subscriptions);
 
-       MessagePart publications;
-       for (i = info->Publications.begin(); i != info->Publications.end(); i++)
-               publications.Add(*i);
+       Dictionary::Ptr publications = boost::make_shared<Dictionary>();
+       BOOST_FOREACH(string publication, info->Publications) {
+               publications->Add(publication);
+       }
 
        params.SetPublications(publications);
 
@@ -324,15 +327,15 @@ bool DiscoveryComponent::HasMessagePermission(const Dictionary::Ptr& roles, cons
 
        ConfigObject::TMap::Range range = ConfigObject::GetObjects("role");
 
-       for (ConfigObject::TMap::Iterator ip = range.first; ip != range.second; ip++) {
-               ConfigObject::Ptr role = ip->second;
-
+       ConfigObject::Ptr role;
+       BOOST_FOREACH(tie(tuples::ignore, role), range) {
                Dictionary::Ptr permissions;
                if (!role->GetProperty(messageType, &permissions))
                        continue;
 
-               for (Dictionary::Iterator is = permissions->Begin(); is != permissions->End(); is++) {
-                       if (Utility::Match(is->second, message))
+               string permission;
+               BOOST_FOREACH(tie(tuples::ignore, permission), permissions) {
+                       if (Utility::Match(permission, message))
                                return true;
                }
        }
@@ -373,26 +376,26 @@ void DiscoveryComponent::ProcessDiscoveryMessage(const string& identity, const D
 
        Endpoint::Ptr endpoint = EndpointManager::GetInstance()->GetEndpointByIdentity(identity);
 
-       MessagePart publications;
+       Dictionary::Ptr publications;
        if (message.GetPublications(&publications)) {
-               Dictionary::Iterator i;
-               for (i = publications.Begin(); i != publications.End(); i++) {
-                       if (trusted || HasMessagePermission(roles, "publications", i->second)) {
-                               info->Publications.insert(i->second);
+               string publication;
+               BOOST_FOREACH(tie(tuples::ignore, publication), publications) {
+                       if (trusted || HasMessagePermission(roles, "publications", publication)) {
+                               info->Publications.insert(publication);
                                if (endpoint)
-                                       endpoint->RegisterPublication(i->second);
+                                       endpoint->RegisterPublication(publication);
                        }
                }
        }
 
-       MessagePart subscriptions;
+       Dictionary::Ptr subscriptions;
        if (message.GetSubscriptions(&subscriptions)) {
-               Dictionary::Iterator i;
-               for (i = subscriptions.Begin(); i != subscriptions.End(); i++) {
-                       if (trusted || HasMessagePermission(roles, "subscriptions", i->second)) {
-                               info->Subscriptions.insert(i->second);
+               string subscription;
+               BOOST_FOREACH(tie(tuples::ignore, subscription), subscriptions) {
+                       if (trusted || HasMessagePermission(roles, "subscriptions", subscription)) {
+                               info->Subscriptions.insert(subscription);
                                if (endpoint)
-                                       endpoint->RegisterSubscription(i->second);
+                                       endpoint->RegisterSubscription(subscription);
                        }
                }
        }
@@ -456,9 +459,8 @@ void DiscoveryComponent::DiscoveryTimerHandler(void)
        /* check whether we have to reconnect to one of our upstream endpoints */
        ConfigObject::TMap::Range range = ConfigObject::GetObjects("endpoint");
 
-       for (ConfigObject::TMap::Iterator it = range.first; it != range.second; it++) {
-               ConfigObject::Ptr object = it->second;
-
+       ConfigObject::Ptr object;
+       BOOST_FOREACH(tie(tuples::ignore, object), range) {
                /* Check if we're already connected to this endpoint. */
                if (endpointManager->GetEndpointByIdentity(object->GetName()))
                        continue;
@@ -472,8 +474,8 @@ void DiscoveryComponent::DiscoveryTimerHandler(void)
 
        map<string, ComponentDiscoveryInfo::Ptr>::iterator curr, i;
        for (i = m_Components.begin(); i != m_Components.end(); ) {
-               string identity = i->first;
-               ComponentDiscoveryInfo::Ptr info = i->second;
+               const string& identity = i->first;
+               const ComponentDiscoveryInfo::Ptr& info = i->second;
 
                curr = i;
                i++;
index ccc0b78407c41eb37ecc9c5aa89bcadcc5e98999..354cf01df4e2c92014e3ddb2157baee52d5766d5 100644 (file)
@@ -59,22 +59,22 @@ void DiscoveryMessage::SetService(const string& value)
        Set("service", value);
 }
 
-bool DiscoveryMessage::GetSubscriptions(MessagePart *value) const
+bool DiscoveryMessage::GetSubscriptions(Dictionary::Ptr *value) const
 {
        return Get("subscriptions", value);
 }
 
-void DiscoveryMessage::SetSubscriptions(MessagePart value)
+void DiscoveryMessage::SetSubscriptions(const Dictionary::Ptr& value)
 {
        Set("subscriptions", value);
 }
 
-bool DiscoveryMessage::GetPublications(MessagePart *value) const
+bool DiscoveryMessage::GetPublications(Dictionary::Ptr *value) const
 {
        return Get("publications", value);
 }
 
-void DiscoveryMessage::SetPublications(MessagePart value)
+void DiscoveryMessage::SetPublications(const Dictionary::Ptr& value)
 {
        Set("publications", value);
 }
index cb304b03db0e33fab905123b7e88ec3ac787b259..9cce48a90198a700480eeb941c3bcdda7bd60943 100644 (file)
@@ -41,11 +41,11 @@ public:
        bool GetService(string *value) const;
        void SetService(const string& value);
 
-       bool GetSubscriptions(MessagePart *value) const;
-       void SetSubscriptions(MessagePart value);
+       bool GetSubscriptions(Dictionary::Ptr *value) const;
+       void SetSubscriptions(const Dictionary::Ptr& value);
 
-       bool GetPublications(MessagePart *value) const;
-       void SetPublications(MessagePart value);
+       bool GetPublications(Dictionary::Ptr *value) const;
+       void SetPublications(const Dictionary::Ptr& value);
 };
 
 }
index e951ff6ef59a96527a23c5ad81d633ab0e0d573a..ec10136761eb0169b6bab7191d37bf0cf6cc4035 100644 (file)
@@ -47,7 +47,7 @@ void *ConfigCompiler::GetScanner(void) const
 
 vector<ConfigItem::Ptr> ConfigCompiler::GetResult(void) const
 {
-        return m_Result;
+       return m_Result;
 }
 
 string ConfigCompiler::GetPath(void) const
index faea417ed48b9653e101ba19556e8eb635215306..3d7295e4d9349f4c48dfe7e90bafb0ff0a0702e7 100644 (file)
@@ -56,13 +56,12 @@ vector<string> ConfigItem::GetParents(void) const
 
 void ConfigItem::CalculateProperties(Dictionary::Ptr dictionary) const
 {
-       vector<string>::const_iterator it;
-       for (it = m_Parents.begin(); it != m_Parents.end(); it++) {
-               ConfigItem::Ptr parent = ConfigItem::GetObject(GetType(), *it);
+       BOOST_FOREACH(const string& name, m_Parents) {
+               ConfigItem::Ptr parent = ConfigItem::GetObject(GetType(), name);
 
                if (!parent) {
                        stringstream message;
-                       message << "Parent object '" << *it << "' does not exist (" << m_DebugInfo << ")";
+                       message << "Parent object '" << name << "' does not exist (" << m_DebugInfo << ")";
                        throw domain_error(message.str());
                }
 
@@ -76,12 +75,12 @@ ConfigItem::Set::Ptr ConfigItem::GetAllObjects(void)
 {
        static ObjectSet<ConfigItem::Ptr>::Ptr allObjects;
 
-        if (!allObjects) {
-                allObjects = boost::make_shared<ObjectSet<ConfigItem::Ptr> >();
-                allObjects->Start();
-        }
+       if (!allObjects) {
+               allObjects = boost::make_shared<ObjectSet<ConfigItem::Ptr> >();
+               allObjects->Start();
+       }
 
-        return allObjects;
+       return allObjects;
 }
 
 bool ConfigItem::GetTypeAndName(const ConfigItem::Ptr& object, pair<string, string> *key)
index 9dc5676465ab9a2191abefa6f72eb10c74e610a1..3f720133d5df058cb8ff83c8b893453e156e883c 100644 (file)
@@ -81,9 +81,10 @@ void Expression::Execute(const Dictionary::Ptr& dictionary) const
                        if (valueExprl) {
                                valueExprl->Execute(dict);
                        } else if (valueDict) {
-                               Dictionary::Iterator it;
-                               for (it = valueDict->Begin(); it != valueDict->End(); it++) {
-                                       dict->Set(it->first, it->second);
+                               string key;
+                               Variant value;
+                               BOOST_FOREACH(tie(key, value), valueDict) {
+                                       dict->Set(key, value);
                                }
                        } else {
                                stringstream message;
index c9d50487597ec22aa48507a32e5ef788270b4472..41cf019ea8bc1f8d9679a610d04a7e111bb0bef4 100644 (file)
 
 using namespace icinga;
 
-ExpressionList::ExpressionList(void)
-{
-}
-
 void ExpressionList::AddExpression(const Expression& expression)
 {
        m_Expressions.push_back(expression);
@@ -37,9 +33,7 @@ size_t ExpressionList::GetLength(void) const
 
 void ExpressionList::Execute(const Dictionary::Ptr& dictionary) const
 {
-       vector<Expression>::const_iterator it;
-
-       for (it = m_Expressions.begin(); it != m_Expressions.end(); it++) {
-               it->Execute(dictionary);
+       BOOST_FOREACH(const Expression& expression, m_Expressions) {
+               expression.Execute(dictionary);
        }
 }
index 527ec9e0c5fcb7ad50203e3b11d140224f890a69..d0364e5505420de2f7a06189761b07757d1e0881 100644 (file)
@@ -29,17 +29,12 @@ public:
        typedef shared_ptr<ExpressionList> Ptr;
        typedef weak_ptr<ExpressionList> WeakPtr;
 
-       ExpressionList(void);
-//     ExpressionList(Dictionary::Ptr serializedDictionary);
-
        void AddExpression(const Expression& expression);
 
        void Execute(const Dictionary::Ptr& dictionary) const;
 
        size_t GetLength(void) const;
 
-//     Dictionary::Ptr Serialize(void);
-
 private:
        vector<Expression> m_Expressions;
 };
index 40b9c688615216e0d6c897061581662042c79fc0..272819e3535dd7962445e270cc699bf82a1bdb22 100644 (file)
@@ -240,10 +240,8 @@ void EndpointManager::SendAnycastMessage(Endpoint::Ptr sender,
                throw invalid_argument("Message is missing the 'method' property.");
 
        vector<Endpoint::Ptr> candidates;
-       for (map<string, Endpoint::Ptr>::iterator i = m_Endpoints.begin(); i != m_Endpoints.end(); i++)
-       {
-               Endpoint::Ptr endpoint = i->second;
-
+       Endpoint::Ptr endpoint;
+       BOOST_FOREACH(tie(tuples::ignore, endpoint), m_Endpoints) {
                /* don't forward messages between non-local endpoints */
                if (!sender->IsLocal() && !endpoint->IsLocal())
                        continue;
@@ -277,11 +275,8 @@ void EndpointManager::SendMulticastMessage(Endpoint::Ptr sender,
        if (!message.GetMethod(&method))
                throw invalid_argument("Message is missing the 'method' property.");
 
-       map<string, Endpoint::Ptr>::iterator i;
-       for (i = m_Endpoints.begin(); i != m_Endpoints.end(); i++)
-       {
-               Endpoint::Ptr recipient = i->second;
-
+       Endpoint::Ptr recipient;
+       BOOST_FOREACH(tie(tuples::ignore, recipient), m_Endpoints) {
                /* don't forward messages back to the sender */
                if (sender == recipient)
                        continue;
index 1fda132740c594c90d7fe91986fe7491116d946e..6d0871b228abbaabe1e1fd10e713bc775821fc8b 100644 (file)
@@ -48,16 +48,11 @@ void JsonRpcClient::SendMessage(const MessagePart& message)
  */
 void JsonRpcClient::DataAvailableHandler(void)
 {
-       for (;;) {
-               string jsonString;
-               MessagePart message;
-
-               if (!Netstring::ReadStringFromIOQueue(this, &jsonString))
-                       return;
+       string jsonString;
 
+       while (Netstring::ReadStringFromIOQueue(this, &jsonString)) {
                try {
-                       message = MessagePart(jsonString);
-                       OnNewMessage(GetSelf(), message);
+                       OnNewMessage(GetSelf(), MessagePart(jsonString));
                } catch (const exception& ex) {
                        Logger::Write(LogCritical, "jsonrpc", "Exception while processing message from JSON-RPC client: " + string(ex.what()));
                }