KeyValueDirectory.hpp
Go to the documentation of this file.
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 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 //
00013 // -- END LICENSE BLOCK ------------------------------------------------
00014 
00015 //----------------------------------------------------------------------
00026 //----------------------------------------------------------------------
00027 #ifndef ICL_CORE_KEY_VALUE_DIRECTORY_HPP_INCLUDED
00028 #define ICL_CORE_KEY_VALUE_DIRECTORY_HPP_INCLUDED
00029 
00030 #include "icl_core/KeyValueDirectory.h"
00031 
00032 namespace icl_core {
00033 
00034 template <typename T>
00035 KeyValueDirectoryIterator<T> KeyValueDirectory<T>::find(const String& query) const
00036 {
00037   return KeyValueDirectoryIterator<T> (query, this);
00038 }
00039 
00040 template <typename T>
00041 bool KeyValueDirectory<T>::get(const String& key, typename ConvertToRef<T>::ToRef value) const
00042 {
00043   typename KeyValueMap::const_iterator find_it = m_items.find(key);
00044   if (find_it != m_items.end())
00045   {
00046     value = find_it->second;
00047     return true;
00048   }
00049   else
00050   {
00051     return false;
00052   }
00053 }
00054 
00055 template <typename T>
00056 bool KeyValueDirectory<T>::hasKey(const String &key) const
00057 {
00058   typename KeyValueMap::const_iterator find_it = m_items.find(key);
00059   return find_it != m_items.end();
00060 }
00061 
00062 template <typename T>
00063 bool KeyValueDirectory<T>::insert(const String& key, typename ConvertToRef<T>::ToConstRef value)
00064 {
00065   typename KeyValueMap::const_iterator find_it = m_items.find(key);
00066   m_items[key] = value;
00067   return find_it == m_items.end();
00068 }
00069 
00070 template <typename T>
00071 KeyValueDirectoryIterator<T>::KeyValueDirectoryIterator(const String& query,
00072                                                         const KeyValueDirectory<T> *directory)
00073   : m_directory(directory),
00074     m_query(query)
00075 {
00076   reset();
00077 }
00078 
00079 template <typename T>
00080 String KeyValueDirectoryIterator<T>::key() const
00081 {
00082   return m_current_entry->first;
00083 }
00084 
00085 template <typename T>
00086 String KeyValueDirectoryIterator<T>::matchGroup(size_t index) const
00087 {
00088   if (index < m_current_results.size())
00089   {
00090     return m_current_results[int(index)];
00091   }
00092   else
00093   {
00094     return "";
00095   }
00096 }
00097 
00098 template <typename T>
00099 bool KeyValueDirectoryIterator<T>::next()
00100 {
00101   // If the iterator has been reset (or has just been initialized)
00102   // we move to the first element.
00103   if (m_reset == true)
00104   {
00105     m_reset = false;
00106     m_current_entry = m_directory->m_items.begin();
00107   }
00108   // Otherwise move to the next iterator position.
00109   else
00110   {
00111     ++m_current_entry;
00112   }
00113 
00114   // Check if the current iterator position matches the query.
00115   while (m_current_entry != m_directory->m_items.end() &&
00116          !::boost::regex_match(m_current_entry->first, m_current_results, m_query))
00117   {
00118     ++m_current_entry;
00119   }
00120 
00121   // Check if there is an element left.
00122   return m_current_entry != m_directory->m_items.end();
00123 }
00124 
00125 template <typename T>
00126 void KeyValueDirectoryIterator<T>::reset()
00127 {
00128   m_reset = true;
00129 }
00130 
00131 template <typename T>
00132 typename ConvertToRef<T>::ToConstRef KeyValueDirectoryIterator<T>::value() const
00133 {
00134   return m_current_entry->second;
00135 }
00136 
00138 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
00139 
00140 template <typename T>
00141 ICL_CORE_VC_DEPRECATE_STYLE KeyValueDirectoryIterator<T> KeyValueDirectory<T>::Find(const String& query) const
00142 {
00143   return find(query);
00144 }
00145 
00146 template <typename T>
00147 ICL_CORE_VC_DEPRECATE_STYLE bool KeyValueDirectory<T>::Get(const String& key,
00148                                                            typename ConvertToRef<T>::ToRef value) const
00149 {
00150   return get(key, value);
00151 }
00152 
00153 template <typename T>
00154 ICL_CORE_VC_DEPRECATE_STYLE bool KeyValueDirectory<T>::HasKey(const String &key) const
00155 {
00156   return hasKey(key);
00157 }
00158 
00159 template <typename T>
00160 ICL_CORE_VC_DEPRECATE_STYLE bool KeyValueDirectory<T>::Insert(const String& key,
00161                                                               typename ConvertToRef<T>::ToConstRef value)
00162 {
00163   return insert(key, value);
00164 }
00165 
00166 template <typename T>
00167 ICL_CORE_VC_DEPRECATE_STYLE String KeyValueDirectoryIterator<T>::Key() const
00168 {
00169   return key();
00170 }
00171 
00172 template <typename T>
00173 ICL_CORE_VC_DEPRECATE_STYLE String KeyValueDirectoryIterator<T>::MatchGroup(size_t index) const
00174 {
00175   return matchGroup(index);
00176 }
00177 
00178 template <typename T>
00179 ICL_CORE_VC_DEPRECATE_STYLE bool KeyValueDirectoryIterator<T>::Next()
00180 {
00181   return next();
00182 }
00183 
00184 template <typename T>
00185 ICL_CORE_VC_DEPRECATE_STYLE void KeyValueDirectoryIterator<T>::Reset()
00186 {
00187   reset();
00188 }
00189 
00190 template <typename T>
00191 ICL_CORE_VC_DEPRECATE_STYLE typename ConvertToRef<T>::ToConstRef KeyValueDirectoryIterator<T>::Value() const
00192 {
00193   return value();
00194 }
00195 
00196 #endif
00197 
00198 
00199 }
00200 
00201 #endif


fzi_icl_core
Author(s):
autogenerated on Thu Jun 6 2019 20:22:24