r3308 - in trunk/libmutil: include/libmutil source
erik at minisip.org
erik at minisip.org
Wed Jun 13 17:20:06 CEST 2007
Author: erik
Date: 2007-06-13 17:20:05 +0200 (Wed, 13 Jun 2007)
New Revision: 3308
Modified:
trunk/libmutil/include/libmutil/CommandString.h
trunk/libmutil/source/CommandString.cxx
Log:
* You always got an exception when doing CommandString::get() for a key
that does not exist. Here another method is added where you can
supply a default value.
The implementation is a bit ugly since it uses a special default value
constant which can not be used in the code. Note how ever that it's only
a forbidden _default_, and not a forbidden key or value, and that
forbidden default is a string containing random characters.
Modified: trunk/libmutil/include/libmutil/CommandString.h
===================================================================
--- trunk/libmutil/include/libmutil/CommandString.h 2007-06-13 07:55:57 UTC (rev 3307)
+++ trunk/libmutil/include/libmutil/CommandString.h 2007-06-13 15:20:05 UTC (rev 3308)
@@ -31,6 +31,8 @@
#include<string>
#include<map>
+#define LIBMUTIL_DEFAULT "LIBMUTIL_DEFAULT_RVAL_7D1PPX9Q"
+
class LIBMUTIL_API CommandString : public virtual MObject{
public:
CommandString();
@@ -63,7 +65,7 @@
std::string &operator[](std::string key);
- std::string get(const std::string &key) const;
+ std::string get(const std::string &key, const std::string &dfltval=LIBMUTIL_DEFAULT) const;
private:
std::map<std::string, std::string> keys;
Modified: trunk/libmutil/source/CommandString.cxx
===================================================================
--- trunk/libmutil/source/CommandString.cxx 2007-06-13 07:55:57 UTC (rev 3307)
+++ trunk/libmutil/source/CommandString.cxx 2007-06-13 15:20:05 UTC (rev 3308)
@@ -107,10 +107,13 @@
return keys[key];
}
-string CommandString::get(const string &key) const{
+string CommandString::get(const string &key, const string &dfltval) const{
map<string,string>::const_iterator it = keys.find(key);
if( it == keys.end() ){
- throw Exception("Key not found: "+key);
+ if (dfltval==LIBMUTIL_DEFAULT)
+ throw Exception(("Key not found ("+key+")").c_str());
+ else
+ return dfltval;
}
return it->second;
}
More information about the Minisip-devel
mailing list