using namespace icinga;
+struct DictionaryKeyLessComparer
+{
+ bool operator()(const pair<String, Value>& a, const char *b)
+ {
+ return a.first < b;
+ }
+
+ bool operator()(const char *a, const pair<String, Value>& b)
+ {
+ return a < b.first;
+ }
+};
+
/**
- * Retrieves a value from the dictionary.
+ * Restrieves a value from a dictionary.
*
* @param key The key whose value should be retrieved.
- * @returns The value or an empty value if the key was not found.
+ * @returns The value of an empty value if the key was not found.
*/
-Value Dictionary::Get(const String& key) const
+Value Dictionary::Get(const char *key) const
{
map<String, Value>::const_iterator it;
- it = m_Data.find(key);
- if (it == m_Data.end())
+ it = std::lower_bound(m_Data.begin(), m_Data.end(), key, DictionaryKeyLessComparer());
+
+ if (it == m_Data.end() || DictionaryKeyLessComparer()(key, *it))
return Empty;
return it->second;
}
+/**
+ * Retrieves a value from the dictionary.
+ *
+ * @param key The key whose value should be retrieved.
+ * @returns The value or an empty value if the key was not found.
+ */
+Value Dictionary::Get(const String& key) const
+{
+ return Get(key.CStr());
+}
+
/**
* Sets a value in the dictionary.
*
typedef map<String, Value>::iterator Iterator;
+ 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);
return lhs != static_cast<std::string>(rhs);
}
+bool icinga::operator<(const String& lhs, const char *rhs)
+{
+ return static_cast<std::string>(lhs) < rhs;
+}
+
+bool icinga::operator<(const char *lhs, const String& rhs)
+{
+ return lhs < static_cast<std::string>(rhs);
+}
+
+bool icinga::operator>(const String& lhs, const char *rhs)
+{
+ return static_cast<std::string>(lhs) > rhs;
+}
+
+bool icinga::operator>(const char *lhs, const String& rhs)
+{
+ return lhs > static_cast<std::string>(rhs);
+}
+
String::Iterator icinga::range_begin(String& x)
{
return x.Begin();
I2_BASE_API bool operator!=(const String& lhs, const char *rhs);
I2_BASE_API bool operator!=(const char *lhs, const String& rhs);
+I2_BASE_API bool operator<(const String& lhs, const char *rhs);
+I2_BASE_API bool operator<(const char *lhs, const String& rhs);
+I2_BASE_API bool operator>(const String& lhs, const char *rhs);
+I2_BASE_API bool operator>(const char *lhs, const String& rhs);
+
I2_BASE_API String::Iterator range_begin(String& x);
I2_BASE_API String::ConstIterator range_begin(const String& x);
I2_BASE_API String::Iterator range_end(String& x);