}
return 0;
}
+
+string get_str_map_value(
+ const map<string,string> &str_map,
+ const string &key,
+ const string *def_val)
+{
+ map<string,string>::const_iterator p = str_map.find(key);
+
+ // key exists in str_map
+ if (p != str_map.end()) {
+ // but value is empty
+ if (p->second.empty())
+ return p->first;
+ // and value is not empty
+ return p->second;
+ }
+
+ // key DNE in str_map and def_val was specified
+ if (def_val != NULL)
+ return *def_val;
+
+ // key DNE in str_map, no def_val was specified
+ return string();
+}
+
+string get_str_map_key(
+ const map<string,string> &str_map,
+ const string &key,
+ const string *fallback_key)
+{
+ map<string,string>::const_iterator p = str_map.find(key);
+ if (p != str_map.end())
+ return p->second;
+
+ if (fallback_key != NULL) {
+ p = str_map.find(*fallback_key);
+ if (p != str_map.end())
+ return p->second;
+ }
+ return string();
+}
std::ostream &ss,
std::map<std::string,std::string> *str_map);
+/**
+ * Returns the value of **key** in **str_map** if available.
+ *
+ * If **key** is not available in **str_map**, and if **def_val** is
+ * not-NULL then returns **def_val**. Otherwise checks if the value of
+ * **key** is an empty string and if so will return **key**.
+ * If the map contains **key**, the function returns the value of **key**.
+ *
+ * @param[in] str_map Map to obtain **key** from
+ * @param[in] key The key to search for in the map
+ * @param[in] def_val The value to return in case **key** is not present
+ */
+extern std::string get_str_map_value(
+ const std::map<std::string,std::string> &str_map,
+ const std::string &key,
+ const std::string *def_val = NULL);
+
+/**
+ * Returns the value of **key** in **str_map** if available.
+ *
+ * If **key** is available in **str_map** returns the value of **key**.
+ *
+ * If **key** is not available in **str_map**, and if **def_key**
+ * is not-NULL and available in **str_map**, then returns the value
+ * of **def_key**.
+ *
+ * Otherwise returns an empty string.
+ *
+ * @param[in] str_map Map to obtain **key** or **def_key** from
+ * @param[in] key Key to obtain the value of from **str_map**
+ * @param[in] def_key Key to fallback to if **key** is not present
+ * in **str_map**
+ */
+extern std::string get_str_map_key(
+ const std::map<std::string,std::string> &str_map,
+ const std::string &key,
+ const std::string *fallback_key = NULL);
+
#endif