Image Component Library (ICL)
|
00001 /******************************************************************** 00002 ** Image Component Library (ICL) ** 00003 ** ** 00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld ** 00005 ** Neuroinformatics Group ** 00006 ** Website: www.iclcv.org and ** 00007 ** http://opensource.cit-ec.de/projects/icl ** 00008 ** ** 00009 ** File : ICLUtils/src/ICLUtils/ParamList.h ** 00010 ** Module : ICLUtils ** 00011 ** Authors: Christof Elbrechter ** 00012 ** ** 00013 ** ** 00014 ** GNU LESSER GENERAL PUBLIC LICENSE ** 00015 ** This file may be used under the terms of the GNU Lesser General ** 00016 ** Public License version 3.0 as published by the ** 00017 ** ** 00018 ** Free Software Foundation and appearing in the file LICENSE.GPL ** 00019 ** included in the packaging of this file. Please review the ** 00020 ** following information to ensure the license requirements will ** 00021 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt ** 00022 ** ** 00023 ** The development of this software was supported by the ** 00024 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. ** 00025 ** The Excellence Cluster EXC 277 is a grant of the Deutsche ** 00026 ** Forschungsgemeinschaft (DFG) in the context of the German ** 00027 ** Excellence Initiative. ** 00028 ** ** 00029 ********************************************************************/ 00030 00031 #pragma once 00032 00033 #include <ICLUtils/Any.h> 00034 #include <map> 00035 00036 namespace icl{ 00037 namespace utils{ 00038 00040 00043 struct ParamList : public std::map<std::string,Any>{ 00044 00046 typedef std::string Key; 00047 00049 typedef Any Value; 00050 00052 inline ParamList(){} 00053 00055 00057 inline ParamList(const std::string &commaSepKeyValueString) throw (ICLException){ 00058 init(commaSepKeyValueString); 00059 } 00060 00062 inline ParamList(const char *commaSepKeyValueString) throw (ICLException){ 00063 init(commaSepKeyValueString); 00064 } 00065 00066 inline void init(const std::string commaSepKeyValueString) throw (ICLException){ 00067 std::vector<std::string> ts = tok(commaSepKeyValueString,",",true,'\\'); 00068 for(size_t i=0;i<ts.size();++i){ 00069 std::vector<std::string> kv = tok(ts[i],"=",true,'\\'); 00070 ICLASSERT_THROW(kv.size() == 2, ICLException("ParamList(string): invalid token :'" 00071 + ts[i] + "'")); 00072 const_cast<ParamList*>(this)->operator[](kv[0]) = kv[1]; 00073 } 00074 } 00075 00076 00078 00079 inline ParamList(const Key &key0, const Value &value0, 00080 const Key &key1="", const Value &value1="", 00081 const Key &key2="", const Value &value2="", 00082 const Key &key3="", const Value &value3="", 00083 const Key &key4="", const Value &value4="", 00084 const Key &key5="", const Value &value5="", 00085 const Key &key6="", const Value &value6="", 00086 const Key &key7="", const Value &value7="", 00087 const Key &key8="", const Value &value8="", 00088 const Key &key9="", const Value &value9="" ){ 00089 if(key0.length()) operator[](key0) = value0; 00090 if(key1.length()) operator[](key1) = value1; 00091 if(key2.length()) operator[](key2) = value2; 00092 if(key3.length()) operator[](key3) = value3; 00093 if(key4.length()) operator[](key4) = value4; 00094 if(key5.length()) operator[](key5) = value5; 00095 if(key6.length()) operator[](key6) = value6; 00096 if(key7.length()) operator[](key7) = value7; 00097 if(key8.length()) operator[](key8) = value8; 00098 if(key9.length()) operator[](key9) = value9; 00099 } 00100 00102 00103 inline bool hasKey(const Key &key) const { return find(key) != end(); } 00104 00106 00107 inline void removeKey(const Key &key){ 00108 iterator it = find(key); 00109 if(it != end()) erase(it); 00110 } 00111 00113 inline const Any &operator[](const Key &key) const throw (ICLException){ 00114 const_iterator it = find(key); 00115 if(it == end()) throw ICLException("error in ParamList::operator[](key) with key=" + key + ": key not found!"); 00116 return it->second; 00117 } 00118 00120 using std::map<std::string,Any>::operator[]; 00121 }; 00122 00123 00124 } // namespace utils 00125 } 00126