mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-23 13:45:04 +02:00
Remove support for anonymous dictionary items.
This commit is contained in:
parent
2a2e2ca4e6
commit
1ef7399cea
@ -120,38 +120,6 @@ void Dictionary::Set(const String& key, const Value& value)
|
|||||||
ret.first->second = value;
|
ret.first->second = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds an unnamed value to the dictionary.
|
|
||||||
*
|
|
||||||
* @param value The value.
|
|
||||||
* @returns The key that was used to add the new item.
|
|
||||||
* @threadsafety Always.
|
|
||||||
*/
|
|
||||||
String Dictionary::Add(const Value& value)
|
|
||||||
{
|
|
||||||
ASSERT(!OwnsLock());
|
|
||||||
ObjectLock olock(this);
|
|
||||||
|
|
||||||
Dictionary::Iterator it;
|
|
||||||
String key;
|
|
||||||
long index = m_Data.size();
|
|
||||||
do {
|
|
||||||
stringstream s;
|
|
||||||
s << "_" << std::hex << std::setw(8) << std::setfill('0') << index;
|
|
||||||
index++;
|
|
||||||
|
|
||||||
key = s.str();
|
|
||||||
it = m_Data.find(key);
|
|
||||||
} while (it != m_Data.end());
|
|
||||||
|
|
||||||
pair<map<String, Value>::iterator, bool> ret;
|
|
||||||
ret = m_Data.insert(make_pair(key, value));
|
|
||||||
if (!ret.second)
|
|
||||||
ret.first->second = value;
|
|
||||||
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an iterator to the beginning of the dictionary.
|
* Returns an iterator to the beginning of the dictionary.
|
||||||
*
|
*
|
||||||
|
@ -44,7 +44,6 @@ public:
|
|||||||
Value Get(const char *key) const;
|
Value Get(const char *key) const;
|
||||||
Value Get(const String& key) const;
|
Value Get(const String& key) const;
|
||||||
void Set(const String& key, const Value& value);
|
void Set(const String& key, const Value& value);
|
||||||
String Add(const Value& value);
|
|
||||||
bool Contains(const String& key) const;
|
bool Contains(const String& key) const;
|
||||||
|
|
||||||
void Seal(void);
|
void Seal(void);
|
||||||
|
@ -42,13 +42,12 @@ vector<String> Process::SplitCommand(const Value& command)
|
|||||||
{
|
{
|
||||||
vector<String> args;
|
vector<String> args;
|
||||||
|
|
||||||
if (command.IsObjectType<Dictionary>()) {
|
if (command.IsObjectType<Array>()) {
|
||||||
Dictionary::Ptr dict = command;
|
Array::Ptr arguments = command;
|
||||||
ObjectLock olock(dict);
|
|
||||||
|
|
||||||
Value arg;
|
ObjectLock olock(arguments);
|
||||||
BOOST_FOREACH(tie(tuples::ignore, arg), dict) {
|
BOOST_FOREACH(const Value& argument, arguments) {
|
||||||
args.push_back(arg);
|
args.push_back(argument);
|
||||||
}
|
}
|
||||||
|
|
||||||
return args;
|
return args;
|
||||||
|
@ -105,10 +105,7 @@ void Expression::Execute(const Dictionary::Ptr& dictionary) const
|
|||||||
BOOST_THROW_EXCEPTION(runtime_error("Not yet implemented."));
|
BOOST_THROW_EXCEPTION(runtime_error("Not yet implemented."));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_Key.IsEmpty())
|
dictionary->Set(m_Key, newValue);
|
||||||
dictionary->Add(newValue);
|
|
||||||
else
|
|
||||||
dictionary->Set(m_Key, newValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Expression::DumpValue(ostream& fp, int indent, const Value& value, bool inlineDict)
|
void Expression::DumpValue(ostream& fp, int indent, const Value& value, bool inlineDict)
|
||||||
|
@ -91,16 +91,6 @@ void MessagePart::Set(String key, const MessagePart& value)
|
|||||||
GetDictionary()->Set(key, value.GetDictionary());
|
GetDictionary()->Set(key, value.GetDictionary());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds an item to the message using an automatically generated property name.
|
|
||||||
*
|
|
||||||
* @param value The value.
|
|
||||||
*/
|
|
||||||
void MessagePart::Add(const MessagePart& value)
|
|
||||||
{
|
|
||||||
GetDictionary()->Add(value.GetDictionary());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an iterator that points to the first element of the dictionary
|
* Returns an iterator that points to the first element of the dictionary
|
||||||
* which holds the properties for the message.
|
* which holds the properties for the message.
|
||||||
|
@ -75,19 +75,6 @@ public:
|
|||||||
bool Get(String key, MessagePart *value) const;
|
bool Get(String key, MessagePart *value) const;
|
||||||
void Set(String key, const MessagePart& value);
|
void Set(String key, const MessagePart& value);
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds an item to the message using an automatically generated property name.
|
|
||||||
*
|
|
||||||
* @param value The value.
|
|
||||||
*/
|
|
||||||
template<typename T>
|
|
||||||
void Add(const T& value)
|
|
||||||
{
|
|
||||||
GetDictionary()->Add(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Add(const MessagePart& value);
|
|
||||||
|
|
||||||
bool Contains(const String& key) const;
|
bool Contains(const String& key) const;
|
||||||
|
|
||||||
Dictionary::Iterator Begin(void);
|
Dictionary::Iterator Begin(void);
|
||||||
|
@ -64,33 +64,4 @@ BOOST_AUTO_TEST_CASE(getproperty_dict)
|
|||||||
BOOST_CHECK(!test2);
|
BOOST_CHECK(!test2);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(unnamed)
|
|
||||||
{
|
|
||||||
Dictionary::Ptr dictionary = boost::make_shared<Dictionary>();
|
|
||||||
dictionary->Add("test1");
|
|
||||||
dictionary->Add("test2");
|
|
||||||
dictionary->Add("test3");
|
|
||||||
|
|
||||||
ObjectLock olock(dictionary);
|
|
||||||
BOOST_CHECK(distance(dictionary->Begin(), dictionary->End()) == 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(unnamed_order)
|
|
||||||
{
|
|
||||||
Dictionary::Ptr dictionary = boost::make_shared<Dictionary>();
|
|
||||||
|
|
||||||
for (int i = 0; i < 1000; i++)
|
|
||||||
dictionary->Add(i);
|
|
||||||
|
|
||||||
/* unnamed items are guaranteed to be in whatever order they were
|
|
||||||
* inserted in. */
|
|
||||||
Value value;
|
|
||||||
int i = 0;
|
|
||||||
ObjectLock olock(dictionary);
|
|
||||||
BOOST_FOREACH(tie(tuples::ignore, value), dictionary) {
|
|
||||||
BOOST_CHECK(value == i);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user