Skip to content

Commit

Permalink
Replace BOOST_FOREACH with range-based for loops
Browse files Browse the repository at this point in the history
fixes #12538
  • Loading branch information
gunnarbeutner committed Aug 25, 2016
1 parent bdaf022 commit 34e3b6c
Show file tree
Hide file tree
Showing 203 changed files with 808 additions and 1,007 deletions.
7 changes: 3 additions & 4 deletions icinga-app/icinga.cpp
Expand Up @@ -34,7 +34,6 @@
#include "config.h"
#include <boost/program_options.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/foreach.hpp>

#ifndef _WIN32
# include <sys/types.h>
Expand Down Expand Up @@ -243,7 +242,7 @@ int Main(void)
#endif /* _WIN32 */

if (vm.count("define")) {
BOOST_FOREACH(const String& define, vm["define"].as<std::vector<std::string> >()) {
for (const String& define : vm["define"].as<std::vector<std::string> >()) {
String key, value;
size_t pos = define.FindFirstOf('=');
if (pos != String::NPos) {
Expand All @@ -269,7 +268,7 @@ int Main(void)
ConfigCompiler::AddIncludeSearchDir(Application::GetIncludeConfDir());

if (!autocomplete && vm.count("include")) {
BOOST_FOREACH(const String& includePath, vm["include"].as<std::vector<std::string> >()) {
for (const String& includePath : vm["include"].as<std::vector<std::string> >()) {
ConfigCompiler::AddIncludeSearchDir(includePath);
}
}
Expand All @@ -293,7 +292,7 @@ int Main(void)
}

if (vm.count("library")) {
BOOST_FOREACH(const String& libraryName, vm["library"].as<std::vector<std::string> >()) {
for (const String& libraryName : vm["library"].as<std::vector<std::string> >()) {
try {
(void) Loader::LoadExtensionLibrary(libraryName);
} catch (const std::exception& ex) {
Expand Down
17 changes: 7 additions & 10 deletions icinga-studio/mainform.cpp
Expand Up @@ -21,7 +21,6 @@
#include "icinga-studio/aboutform.hpp"
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/foreach.hpp>
#include <wx/msgdlg.h>

using namespace icinga;
Expand Down Expand Up @@ -72,11 +71,11 @@ void MainForm::TypesCompletionHandler(boost::exception_ptr eptr, const std::vect

wxTreeItemId rootNode = m_TypesTree->AddRoot("root");

BOOST_FOREACH(const ApiType::Ptr& type, types) {
for (const ApiType::Ptr& type : types) {
m_Types[type->Name] = type;
}

BOOST_FOREACH(const ApiType::Ptr& type, types) {
for (const ApiType::Ptr& type : types) {
if (type->Abstract)
continue;

Expand Down Expand Up @@ -146,7 +145,7 @@ void MainForm::ObjectsCompletionHandler(boost::exception_ptr eptr, const std::ve
std::vector<ApiObject::Ptr> sortedObjects = objects;
std::sort(sortedObjects.begin(), sortedObjects.end(), ApiObjectLessComparer);

BOOST_FOREACH(const ApiObject::Ptr& object, sortedObjects) {
for (const ApiObject::Ptr& object : sortedObjects) {
std::string name = object->Name;
m_ObjectsList->InsertItem(0, name);
}
Expand Down Expand Up @@ -195,7 +194,7 @@ wxPGProperty *MainForm::ValueToProperty(const String& name, const Value& value)

{
ObjectLock olock(arr);
BOOST_FOREACH(const Value& aitem, arr) {
for (const Value& aitem : arr) {
String val1 = aitem;
val.Add(val1.GetData());
}
Expand All @@ -211,7 +210,7 @@ wxPGProperty *MainForm::ValueToProperty(const String& name, const Value& value)

{
ObjectLock olock(dict);
BOOST_FOREACH(const Dictionary::Pair& kv, dict) {
for (const Dictionary::Pair& kv : dict) {
if (kv.first != "type")
prop->AppendChild(ValueToProperty(kv.first, kv.second));
}
Expand Down Expand Up @@ -268,8 +267,7 @@ void MainForm::ObjectDetailsCompletionHandler(boost::exception_ptr eptr, const s

std::map<String, wxStringProperty *> parents;

typedef std::pair<String, Value> kv_pair_attr;
BOOST_FOREACH(const kv_pair_attr& kv, object->Attrs) {
for (const auto& kv : object->Attrs) {
std::vector<String> tokens;
boost::algorithm::split(tokens, kv.first, boost::is_any_of("."));

Expand Down Expand Up @@ -298,8 +296,7 @@ void MainForm::ObjectDetailsCompletionHandler(boost::exception_ptr eptr, const s
parents.erase(propName);
}

typedef std::pair<String, wxStringProperty *> kv_pair_prop;
BOOST_FOREACH(const kv_pair_prop& kv, parents) {
for (const auto& kv : parents) {
m_PropertyGrid->Append(kv.second);
m_PropertyGrid->SetPropertyReadOnly(kv.second);
}
Expand Down
5 changes: 2 additions & 3 deletions lib/base/application.cpp
Expand Up @@ -32,7 +32,6 @@
#include "base/scriptglobal.hpp"
#include "base/process.hpp"
#include <boost/algorithm/string/classification.hpp>
#include <boost/foreach.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/exception/errinfo_api_function.hpp>
Expand Down Expand Up @@ -115,7 +114,7 @@ void Application::Exit(int rc)
std::cout.flush();
std::cerr.flush();

BOOST_FOREACH(const Logger::Ptr& logger, Logger::GetLoggers()) {
for (const Logger::Ptr& logger : Logger::GetLoggers()) {
logger->Flush();
}

Expand Down Expand Up @@ -452,7 +451,7 @@ String Application::GetExePath(const String& argv0)
boost::algorithm::split(paths, pathEnv, boost::is_any_of(":"));

bool foundPath = false;
BOOST_FOREACH(String& path, paths) {
for (const String& path : paths) {
String pathTest = path + "/" + argv0;

if (access(pathTest.CStr(), X_OK) == 0) {
Expand Down
9 changes: 4 additions & 5 deletions lib/base/array-script.cpp
Expand Up @@ -23,7 +23,6 @@
#include "base/scriptframe.hpp"
#include "base/objectlock.hpp"
#include "base/exception.hpp"
#include <boost/foreach.hpp>

using namespace icinga;

Expand Down Expand Up @@ -123,7 +122,7 @@ static Value ArrayJoin(const Value& separator)
bool first = true;

ObjectLock olock(self);
BOOST_FOREACH(const Value& item, self) {
for (const Value& item : self) {
if (first) {
first = false;
} else {
Expand Down Expand Up @@ -154,7 +153,7 @@ static Array::Ptr ArrayMap(const Function::Ptr& function)
Array::Ptr result = new Array();

ObjectLock olock(self);
BOOST_FOREACH(const Value& item, self) {
for (const Value& item : self) {
std::vector<Value> args;
args.push_back(item);
result->Add(function->Invoke(args));
Expand Down Expand Up @@ -198,7 +197,7 @@ static Array::Ptr ArrayFilter(const Function::Ptr& function)
Array::Ptr result = new Array();

ObjectLock olock(self);
BOOST_FOREACH(const Value& item, self) {
for (const Value& item : self) {
std::vector<Value> args;
args.push_back(item);
if (function->Invoke(args))
Expand All @@ -216,7 +215,7 @@ static Array::Ptr ArrayUnique(void)
std::set<Value> result;

ObjectLock olock(self);
BOOST_FOREACH(const Value& item, self) {
for (const Value& item : self) {
result.insert(item);
}

Expand Down
3 changes: 1 addition & 2 deletions lib/base/array.cpp
Expand Up @@ -25,7 +25,6 @@
#include "base/configwriter.hpp"
#include "base/convert.hpp"
#include "base/exception.hpp"
#include <boost/foreach.hpp>

using namespace icinga;

Expand Down Expand Up @@ -185,7 +184,7 @@ Object::Ptr Array::Clone(void) const
Array::Ptr arr = new Array();

ObjectLock olock(this);
BOOST_FOREACH(const Value& val, m_Data) {
for (const Value& val : m_Data) {
arr->Add(val.Clone());
}

Expand Down
21 changes: 2 additions & 19 deletions lib/base/array.hpp
Expand Up @@ -142,33 +142,16 @@ class I2_BASE_API Array : public Object
std::vector<Value> m_Data; /**< The data for the array. */
};

inline Array::Iterator range_begin(Array::Ptr x)
inline Array::Iterator begin(Array::Ptr x)
{
return x->Begin();
}

inline Array::Iterator range_end(Array::Ptr x)
inline Array::Iterator end(Array::Ptr x)
{
return x->End();
}

}

namespace boost
{

template<>
struct range_mutable_iterator<icinga::Array::Ptr>
{
typedef icinga::Array::Iterator type;
};

template<>
struct range_const_iterator<icinga::Array::Ptr>
{
typedef icinga::Array::Iterator type;
};

}

#endif /* ARRAY_H */
27 changes: 13 additions & 14 deletions lib/base/configobject.cpp
Expand Up @@ -34,7 +34,6 @@
#include "base/context.hpp"
#include "base/application.hpp"
#include <fstream>
#include <boost/foreach.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/exception/errinfo_api_function.hpp>
Expand Down Expand Up @@ -181,7 +180,7 @@ void ConfigObject::ModifyAttribute(const String& attr, const Value& value, bool
if (oldValue.IsObjectType<Dictionary>()) {
Dictionary::Ptr oldDict = oldValue;
ObjectLock olock(oldDict);
BOOST_FOREACH(const Dictionary::Pair& kv, oldDict) {
for (const auto& kv : oldDict) {
String key = prefix + "." + kv.first;
if (!original_attributes->Contains(key))
original_attributes->Set(key, kv.second);
Expand All @@ -191,7 +190,7 @@ void ConfigObject::ModifyAttribute(const String& attr, const Value& value, bool
if (value.IsObjectType<Dictionary>()) {
Dictionary::Ptr valueDict = value;
ObjectLock olock(valueDict);
BOOST_FOREACH(const Dictionary::Pair& kv, valueDict) {
for (const auto& kv : valueDict) {
String key = attr + "." + kv.first;
if (!original_attributes->Contains(key))
original_attributes->Set(key, Empty);
Expand Down Expand Up @@ -282,7 +281,7 @@ void ConfigObject::RestoreAttribute(const String& attr, bool updateVersion)

{
ObjectLock olock(original_attributes);
BOOST_FOREACH(const Dictionary::Pair& kv, original_attributes) {
for (const auto& kv : original_attributes) {
std::vector<String> originalTokens;
boost::algorithm::split(originalTokens, kv.first, boost::is_any_of("."));

Expand Down Expand Up @@ -325,7 +324,7 @@ void ConfigObject::RestoreAttribute(const String& attr, bool updateVersion)
}
}

BOOST_FOREACH(const String& attr, restoredAttrs)
for (const String& attr : restoredAttrs)
original_attributes->Remove(attr);


Expand Down Expand Up @@ -497,13 +496,13 @@ void ConfigObject::DumpObjects(const String& filename, int attributeTypes)

StdioStream::Ptr sfp = new StdioStream(&fp, false);

BOOST_FOREACH(const Type::Ptr& type, Type::GetAllTypes()) {
for (const Type::Ptr& type : Type::GetAllTypes()) {
ConfigType *dtype = dynamic_cast<ConfigType *>(type.get());

if (!dtype)
continue;

BOOST_FOREACH(const ConfigObject::Ptr& object, dtype->GetObjects()) {
for (const ConfigObject::Ptr& object : dtype->GetObjects()) {
Dictionary::Ptr persistentObject = new Dictionary();

persistentObject->Set("type", type->GetName());
Expand Down Expand Up @@ -599,13 +598,13 @@ void ConfigObject::RestoreObjects(const String& filename, int attributeTypes)

unsigned long no_state = 0;

BOOST_FOREACH(const Type::Ptr& type, Type::GetAllTypes()) {
for (const Type::Ptr& type : Type::GetAllTypes()) {
ConfigType *dtype = dynamic_cast<ConfigType *>(type.get());

if (!dtype)
continue;

BOOST_FOREACH(const ConfigObject::Ptr& object, dtype->GetObjects()) {
for (const ConfigObject::Ptr& object : dtype->GetObjects()) {
if (!object->GetStateLoaded()) {
object->OnStateLoaded();
object->SetStateLoaded(true);
Expand All @@ -621,34 +620,34 @@ void ConfigObject::RestoreObjects(const String& filename, int attributeTypes)

void ConfigObject::StopObjects(void)
{
BOOST_FOREACH(const Type::Ptr& type, Type::GetAllTypes()) {
for (const Type::Ptr& type : Type::GetAllTypes()) {
ConfigType *dtype = dynamic_cast<ConfigType *>(type.get());

if (!dtype)
continue;

BOOST_FOREACH(const ConfigObject::Ptr& object, dtype->GetObjects()) {
for (const ConfigObject::Ptr& object : dtype->GetObjects()) {
object->Deactivate();
}
}
}

void ConfigObject::DumpModifiedAttributes(const boost::function<void(const ConfigObject::Ptr&, const String&, const Value&)>& callback)
{
BOOST_FOREACH(const Type::Ptr& type, Type::GetAllTypes()) {
for (const Type::Ptr& type : Type::GetAllTypes()) {
ConfigType *dtype = dynamic_cast<ConfigType *>(type.get());

if (!dtype)
continue;

BOOST_FOREACH(const ConfigObject::Ptr& object, dtype->GetObjects()) {
for (const ConfigObject::Ptr& object : dtype->GetObjects()) {
Dictionary::Ptr originalAttributes = object->GetOriginalAttributes();

if (!originalAttributes)
continue;

ObjectLock olock(originalAttributes);
BOOST_FOREACH(const Dictionary::Pair& kv, originalAttributes) {
for (const Dictionary::Pair& kv : originalAttributes) {
String key = kv.first;

Type::Ptr type = object->GetReflectionType();
Expand Down
3 changes: 1 addition & 2 deletions lib/base/configtype.hpp
Expand Up @@ -24,7 +24,6 @@
#include "base/object.hpp"
#include "base/type.hpp"
#include "base/dictionary.hpp"
#include <boost/foreach.hpp>

namespace icinga
{
Expand Down Expand Up @@ -55,7 +54,7 @@ class I2_BASE_API ConfigType
{
std::vector<intrusive_ptr<ConfigObject> > objects = GetObjectsHelper(T::TypeInstance.get());
std::vector<intrusive_ptr<T> > result;
BOOST_FOREACH(const intrusive_ptr<ConfigObject>& object, objects) {
for (const auto& object : objects) {
result.push_back(static_pointer_cast<T>(object));
}
return result;
Expand Down
7 changes: 3 additions & 4 deletions lib/base/configwriter.cpp
Expand Up @@ -19,7 +19,6 @@

#include "base/configwriter.hpp"
#include "base/exception.hpp"
#include <boost/foreach.hpp>
#include <boost/regex.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/algorithm/string/split.hpp>
Expand Down Expand Up @@ -63,7 +62,7 @@ void ConfigWriter::EmitArrayItems(std::ostream& fp, int indentLevel, const Array
bool first = true;

ObjectLock olock(val);
BOOST_FOREACH(const Value& item, val) {
for (const Value& item : val) {
if (first)
first = false;
else
Expand All @@ -80,7 +79,7 @@ void ConfigWriter::EmitScope(std::ostream& fp, int indentLevel, const Dictionary

if (imports && imports->GetLength() > 0) {
ObjectLock xlock(imports);
BOOST_FOREACH(const Value& import, imports) {
for (const Value& import : imports) {
fp << "\n";
EmitIndent(fp, indentLevel);
fp << "import \"" << import << "\"";
Expand All @@ -91,7 +90,7 @@ void ConfigWriter::EmitScope(std::ostream& fp, int indentLevel, const Dictionary

if (val) {
ObjectLock olock(val);
BOOST_FOREACH(const Dictionary::Pair& kv, val) {
for (const Dictionary::Pair& kv : val) {
fp << "\n";
EmitIndent(fp, indentLevel);

Expand Down

0 comments on commit 34e3b6c

Please sign in to comment.