From: Gunnar Beutner Date: Thu, 14 Mar 2013 11:40:02 +0000 (+0100) Subject: Remove support for anonymous dictionary items. X-Git-Tag: v0.0.2~253 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1ef7399ceaf1c8c0cec2d7fc5ee83f0c9319ae58;p=icinga2 Remove support for anonymous dictionary items. --- diff --git a/lib/base/dictionary.cpp b/lib/base/dictionary.cpp index de0a5f21d..0914fa65e 100644 --- a/lib/base/dictionary.cpp +++ b/lib/base/dictionary.cpp @@ -120,38 +120,6 @@ void Dictionary::Set(const String& key, const Value& 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::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. * diff --git a/lib/base/dictionary.h b/lib/base/dictionary.h index ffe6c49ad..cd933dd78 100644 --- a/lib/base/dictionary.h +++ b/lib/base/dictionary.h @@ -44,7 +44,6 @@ public: Value Get(const char *key) const; Value Get(const String& key) const; void Set(const String& key, const Value& value); - String Add(const Value& value); bool Contains(const String& key) const; void Seal(void); diff --git a/lib/base/process.cpp b/lib/base/process.cpp index 4b2df758a..70a55354a 100644 --- a/lib/base/process.cpp +++ b/lib/base/process.cpp @@ -42,13 +42,12 @@ vector Process::SplitCommand(const Value& command) { vector args; - if (command.IsObjectType()) { - Dictionary::Ptr dict = command; - ObjectLock olock(dict); + if (command.IsObjectType()) { + Array::Ptr arguments = command; - Value arg; - BOOST_FOREACH(tie(tuples::ignore, arg), dict) { - args.push_back(arg); + ObjectLock olock(arguments); + BOOST_FOREACH(const Value& argument, arguments) { + args.push_back(argument); } return args; diff --git a/lib/config/expression.cpp b/lib/config/expression.cpp index d7d249e51..f3815bb61 100644 --- a/lib/config/expression.cpp +++ b/lib/config/expression.cpp @@ -105,10 +105,7 @@ void Expression::Execute(const Dictionary::Ptr& dictionary) const BOOST_THROW_EXCEPTION(runtime_error("Not yet implemented.")); } - if (m_Key.IsEmpty()) - dictionary->Add(newValue); - else - dictionary->Set(m_Key, newValue); + dictionary->Set(m_Key, newValue); } void Expression::DumpValue(ostream& fp, int indent, const Value& value, bool inlineDict) diff --git a/lib/remoting/messagepart.cpp b/lib/remoting/messagepart.cpp index f5a5280da..7975881a0 100644 --- a/lib/remoting/messagepart.cpp +++ b/lib/remoting/messagepart.cpp @@ -91,16 +91,6 @@ void MessagePart::Set(String key, const MessagePart& value) 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 * which holds the properties for the message. diff --git a/lib/remoting/messagepart.h b/lib/remoting/messagepart.h index 56c1e2f7f..1d0b3da72 100644 --- a/lib/remoting/messagepart.h +++ b/lib/remoting/messagepart.h @@ -75,19 +75,6 @@ public: bool Get(String key, MessagePart *value) const; void Set(String key, const MessagePart& value); - /** - * Adds an item to the message using an automatically generated property name. - * - * @param value The value. - */ - template - void Add(const T& value) - { - GetDictionary()->Add(value); - } - - void Add(const MessagePart& value); - bool Contains(const String& key) const; Dictionary::Iterator Begin(void); diff --git a/test/base-dictionary.cpp b/test/base-dictionary.cpp index d12d8fb80..486e70429 100644 --- a/test/base-dictionary.cpp +++ b/test/base-dictionary.cpp @@ -64,33 +64,4 @@ BOOST_AUTO_TEST_CASE(getproperty_dict) BOOST_CHECK(!test2); } -BOOST_AUTO_TEST_CASE(unnamed) -{ - Dictionary::Ptr dictionary = boost::make_shared(); - 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(); - - 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()