Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ParamList.h
Go to the documentation of this file.
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.LGPL **
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/Macros.h>
00034 #include <ICLUtils/Any.h>
00035 #include <map>
00036 
00037 namespace icl{
00038   namespace utils{
00039   
00041 
00044     struct ParamList : public std::map<std::string, Any>{
00045   
00047       typedef std::string Key;
00048       
00050       typedef Any Value;
00051   
00053       inline ParamList(){}
00054   
00056 
00058       inline ParamList(const std::string &commaSepKeyValueString) throw (ICLException){
00059         init(commaSepKeyValueString);
00060       }
00061   
00063       inline ParamList(const char *commaSepKeyValueString) throw (ICLException){
00064         init(commaSepKeyValueString);
00065       }
00066   
00067       inline void init(const std::string commaSepKeyValueString) throw (ICLException){
00068         std::vector<std::string> ts = tok(commaSepKeyValueString,",",true,'\\');
00069         for(size_t i=0;i<ts.size();++i){
00070           std::vector<std::string> kv = tok(ts[i],"=",true,'\\');
00071           ICLASSERT_THROW(kv.size() == 2, ICLException("ParamList(string): invalid token :'" 
00072                                                       + ts[i] + "'"));
00073           const_cast<ParamList*>(this)->operator[](kv[0]) = kv[1];
00074         }
00075       }
00076   
00077       
00079 
00080       inline ParamList(const Key &key0, const Value &value0,
00081                        const Key &key1="", const Value &value1="",
00082                        const Key &key2="", const Value &value2="",
00083                        const Key &key3="", const Value &value3="",
00084                        const Key &key4="", const Value &value4="",
00085                        const Key &key5="", const Value &value5="",
00086                        const Key &key6="", const Value &value6="",
00087                        const Key &key7="", const Value &value7="",
00088                        const Key &key8="", const Value &value8="",
00089                        const Key &key9="", const Value &value9="" ){
00090         if(key0.length()) operator[](key0) = value0;
00091         if(key1.length()) operator[](key1) = value1;
00092         if(key2.length()) operator[](key2) = value2;
00093         if(key3.length()) operator[](key3) = value3;
00094         if(key4.length()) operator[](key4) = value4;
00095         if(key5.length()) operator[](key5) = value5;
00096         if(key6.length()) operator[](key6) = value6;
00097         if(key7.length()) operator[](key7) = value7;
00098         if(key8.length()) operator[](key8) = value8;
00099         if(key9.length()) operator[](key9) = value9;
00100       }
00101       
00103 
00104       inline bool hasKey(const Key &key) const { return find(key) != end(); }
00105   
00107 
00108       inline void removeKey(const Key &key){
00109         iterator it = find(key);
00110         if(it != end()) erase(it);
00111       }
00112       
00114       inline const Any &operator[](const Key &key) const throw (ICLException){
00115         const_iterator it = find(key);
00116         if(it == end()) throw ICLException("error in ParamList::operator[](key) with key=" + key + ": key not found!");
00117         return it->second;
00118       }
00119   
00121       using std::map<std::string,Any>::operator[];
00122     };
00123   
00124     
00125   } // namespace utils
00126 }
00127 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines