00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*- 00002 00003 // -- BEGIN LICENSE BLOCK ---------------------------------------------- 00004 // This file is part of FZIs ic_workspace. 00005 // 00006 // This program is free software licensed under the LGPL 00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3). 00008 // You can find a copy of this license in LICENSE folder in the top 00009 // directory of the source code. 00010 // 00011 // © Copyright 2014 FZI Forschungszentrum Informatik, Karlsruhe, Germany 00012 // 00013 // -- END LICENSE BLOCK ------------------------------------------------ 00014 00015 //---------------------------------------------------------------------- 00026 //---------------------------------------------------------------------- 00027 #ifndef ICL_CORE_KEY_VALUE_DIRECTORY_H_INCLUDED 00028 #define ICL_CORE_KEY_VALUE_DIRECTORY_H_INCLUDED 00029 00030 #include <boost/regex.hpp> 00031 00032 #include "icl_core/BaseTypes.h" 00033 #include "icl_core/Map.h" 00034 #include "icl_core/TemplateHelper.h" 00035 00036 #ifdef _IC_BUILDER_DEPRECATED_STYLE_ 00037 # include "icl_core/Deprecate.h" 00038 #endif 00039 00040 namespace icl_core { 00041 00042 template <typename T> 00043 class KeyValueDirectoryIterator; 00044 00047 template <typename T> 00048 class KeyValueDirectory 00049 { 00050 friend class KeyValueDirectoryIterator<T>; 00051 public: 00052 00059 KeyValueDirectoryIterator<T> find(const String& query) const; 00060 00066 bool get(const String& key, typename ConvertToRef<T>::ToRef value) const; 00067 00070 bool hasKey(const String& key) const; 00071 00077 bool insert(const String& key, typename ConvertToRef<T>::ToConstRef value); 00078 00080 #ifdef _IC_BUILDER_DEPRECATED_STYLE_ 00081 00085 KeyValueDirectoryIterator<T> ICL_CORE_VC_DEPRECATE_STYLE 00086 Find(const String& query) const ICL_CORE_GCC_DEPRECATE_STYLE; 00087 00091 bool ICL_CORE_VC_DEPRECATE_STYLE 00092 Get(const String& key, typename ConvertToRef<T>::ToRef value) const ICL_CORE_GCC_DEPRECATE_STYLE; 00093 00097 bool ICL_CORE_VC_DEPRECATE_STYLE HasKey(const String& key) const ICL_CORE_GCC_DEPRECATE_STYLE; 00098 00102 bool ICL_CORE_VC_DEPRECATE_STYLE 00103 Insert(const String& key, typename ConvertToRef<T>::ToConstRef value) ICL_CORE_GCC_DEPRECATE_STYLE; 00104 00105 #endif 00106 00107 00108 private: 00109 typedef Map<String, T> KeyValueMap; 00110 KeyValueMap m_items; 00111 }; 00112 00117 template <typename T> 00118 class KeyValueDirectoryIterator 00119 { 00120 public: 00124 KeyValueDirectoryIterator(const String& query, const KeyValueDirectory<T> *directory); 00125 00129 String key() const; 00130 00137 String matchGroup(size_t index) const; 00138 00144 bool next(); 00145 00150 void reset(); 00151 00155 typename ConvertToRef<T>::ToConstRef value() const; 00156 00158 #ifdef _IC_BUILDER_DEPRECATED_STYLE_ 00159 00163 ICL_CORE_VC_DEPRECATE_STYLE String Key() const ICL_CORE_GCC_DEPRECATE_STYLE; 00164 00172 ICL_CORE_VC_DEPRECATE_STYLE String MatchGroup(size_t index) const ICL_CORE_GCC_DEPRECATE_STYLE; 00173 00180 ICL_CORE_VC_DEPRECATE_STYLE bool Next() ICL_CORE_GCC_DEPRECATE_STYLE; 00181 00187 ICL_CORE_VC_DEPRECATE_STYLE void Reset() ICL_CORE_GCC_DEPRECATE_STYLE; 00188 00193 ICL_CORE_VC_DEPRECATE_STYLE typename ConvertToRef<T>::ToConstRef Value() const ICL_CORE_GCC_DEPRECATE_STYLE; 00194 00195 #endif 00196 00197 00198 private: 00199 const KeyValueDirectory<T> *m_directory; 00200 boost::regex m_query; 00201 boost::match_results<icl_core::String::const_iterator> m_current_results; 00202 00203 typename KeyValueDirectory<T>::KeyValueMap::const_iterator m_current_entry; 00204 bool m_reset; 00205 }; 00206 00207 } 00208 00209 #include "icl_core/KeyValueDirectory.hpp" 00210 00211 #endif