KeyValueDirectory.hpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of FZIs ic_workspace.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 //
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
26 //----------------------------------------------------------------------
27 #ifndef ICL_CORE_KEY_VALUE_DIRECTORY_HPP_INCLUDED
28 #define ICL_CORE_KEY_VALUE_DIRECTORY_HPP_INCLUDED
29 
31 
32 namespace icl_core {
33 
34 template <typename T>
36 {
37  return KeyValueDirectoryIterator<T> (query, this);
38 }
39 
40 template <typename T>
41 bool KeyValueDirectory<T>::get(const String& key, typename ConvertToRef<T>::ToRef value) const
42 {
43  typename KeyValueMap::const_iterator find_it = m_items.find(key);
44  if (find_it != m_items.end())
45  {
46  value = find_it->second;
47  return true;
48  }
49  else
50  {
51  return false;
52  }
53 }
54 
55 template <typename T>
56 bool KeyValueDirectory<T>::hasKey(const String &key) const
57 {
58  typename KeyValueMap::const_iterator find_it = m_items.find(key);
59  return find_it != m_items.end();
60 }
61 
62 template <typename T>
64 {
65  typename KeyValueMap::const_iterator find_it = m_items.find(key);
66  m_items[key] = value;
67  return find_it == m_items.end();
68 }
69 
70 template <typename T>
72  const KeyValueDirectory<T> *directory)
73  : m_directory(directory),
74  m_query(query)
75 {
76  reset();
77 }
78 
79 template <typename T>
81 {
82  return m_current_entry->first;
83 }
84 
85 template <typename T>
87 {
88  if (index < m_current_results.size())
89  {
90  return m_current_results[int(index)];
91  }
92  else
93  {
94  return "";
95  }
96 }
97 
98 template <typename T>
100 {
101  // If the iterator has been reset (or has just been initialized)
102  // we move to the first element.
103  if (m_reset == true)
104  {
105  m_reset = false;
106  m_current_entry = m_directory->m_items.begin();
107  }
108  // Otherwise move to the next iterator position.
109  else
110  {
111  ++m_current_entry;
112  }
113 
114  // Check if the current iterator position matches the query.
115  while (m_current_entry != m_directory->m_items.end() &&
116  !::boost::regex_match(m_current_entry->first, m_current_results, m_query))
117  {
118  ++m_current_entry;
119  }
120 
121  // Check if there is an element left.
122  return m_current_entry != m_directory->m_items.end();
123 }
124 
125 template <typename T>
127 {
128  m_reset = true;
129 }
130 
131 template <typename T>
133 {
134  return m_current_entry->second;
135 }
136 
138 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
139 
140 template <typename T>
142 {
143  return find(query);
144 }
145 
146 template <typename T>
148  typename ConvertToRef<T>::ToRef value) const
149 {
150  return get(key, value);
151 }
152 
153 template <typename T>
155 {
156  return hasKey(key);
157 }
158 
159 template <typename T>
161  typename ConvertToRef<T>::ToConstRef value)
162 {
163  return insert(key, value);
164 }
165 
166 template <typename T>
168 {
169  return key();
170 }
171 
172 template <typename T>
174 {
175  return matchGroup(index);
176 }
177 
178 template <typename T>
180 {
181  return next();
182 }
183 
184 template <typename T>
186 {
187  reset();
188 }
189 
190 template <typename T>
192 {
193  return value();
194 }
195 
196 #endif
197 
199 }
200 
201 #endif
KeyValueDirectory< T >::KeyValueMap::const_iterator m_current_entry
#define ICL_CORE_VC_DEPRECATE_STYLE
Definition: Deprecate.h:53
bool insert(const String &key, typename ConvertToRef< T >::ToConstRef value)
bool hasKey(const String &key) const
KeyValueDirectoryIterator(const String &query, const KeyValueDirectory< T > *directory)
KeyValueDirectoryIterator< T > find(const String &query) const
const KeyValueDirectory< T > * m_directory
ConfigIterator find(const ::icl_core::String &query)
Definition: Config.cpp:45
bool get(const String &key, typename ConvertToRef< T >::ToRef value) const
String matchGroup(size_t index) const
std::string String
Definition: BaseTypes.h:43
boost::match_results< icl_core::String::const_iterator > m_current_results
Contains KeyValueDirectory.
ConvertToRef< T >::ToConstRef value() const
ICL_CORE_VC_DEPRECATE_STYLE ConfigIterator Find(const icl_core::String &query) ICL_CORE_GCC_DEPRECATE_STYLE
Definition: Config.h:621
bool Get(const icl_core::String &key, typename icl_core::ConvertToRef< T >::ToRef value) ICL_CORE_GCC_DEPRECATE_STYLE
Definition: Config.h:648


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:58