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.
*
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);
{
vector<String> args;
- if (command.IsObjectType<Dictionary>()) {
- Dictionary::Ptr dict = command;
- ObjectLock olock(dict);
+ if (command.IsObjectType<Array>()) {
+ 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;
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)
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.
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<typename T>
- void Add(const T& value)
- {
- GetDictionary()->Add(value);
- }
-
- void Add(const MessagePart& value);
-
bool Contains(const String& key) const;
Dictionary::Iterator Begin(void);
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()