mirror of https://github.com/Icinga/icinga2.git
Implement support for "." in attributes when creating objects
refs #9082
This commit is contained in:
parent
5a72eaa768
commit
71dc682924
|
@ -23,6 +23,8 @@
|
|||
#include <boost/foreach.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
#include <boost/algorithm/string/classification.hpp>
|
||||
#include <set>
|
||||
#include <iterator>
|
||||
|
||||
|
@ -93,7 +95,18 @@ void ConfigWriter::EmitScope(int indentLevel, const Dictionary::Ptr& val, const
|
|||
BOOST_FOREACH(const Dictionary::Pair& kv, val) {
|
||||
m_FP << "\n";
|
||||
EmitIndent(indentLevel);
|
||||
EmitIdentifier(kv.first, true);
|
||||
|
||||
std::vector<String> tokens;
|
||||
boost::algorithm::split(tokens, kv.first, boost::is_any_of("."));
|
||||
|
||||
EmitIdentifier(tokens[0], true);
|
||||
|
||||
for (std::vector<String>::size_type i = 1; i < tokens.size(); i++) {
|
||||
m_FP << "[";
|
||||
EmitString(tokens[i]);
|
||||
m_FP << "]";
|
||||
}
|
||||
|
||||
m_FP << " = ";
|
||||
EmitValue(indentLevel + 1, kv.second);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
#include "config/configwriter.hpp"
|
||||
#include "base/exception.hpp"
|
||||
#include "base/serializer.hpp"
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
#include <boost/algorithm/string/classification.hpp>
|
||||
#include <boost/algorithm/string/case_conv.hpp>
|
||||
|
||||
using namespace icinga;
|
||||
|
@ -77,8 +79,17 @@ bool ConfigObjectUtility::CreateObject(const Type::Ptr& type, const String& full
|
|||
if (attrs) {
|
||||
ObjectLock olock(attrs);
|
||||
BOOST_FOREACH(const Dictionary::Pair& kv, attrs) {
|
||||
SetExpression *expr = new SetExpression(MakeIndexer(ScopeThis, kv.first), OpSetLiteral, MakeLiteral(kv.second));
|
||||
builder->AddExpression(expr);
|
||||
std::vector<String> tokens;
|
||||
boost::algorithm::split(tokens, kv.first, boost::is_any_of("."));
|
||||
|
||||
Expression *expr = new GetScopeExpression(ScopeThis);
|
||||
|
||||
BOOST_FOREACH(const String& val, tokens) {
|
||||
expr = new IndexerExpression(expr, MakeLiteral(val));
|
||||
}
|
||||
|
||||
SetExpression *aexpr = new SetExpression(expr, OpSetLiteral, MakeLiteral(kv.second));
|
||||
builder->AddExpression(aexpr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue