48 std::transform(str.begin(), str.end(), str.begin(), toUpper);
54 std::transform(upper.begin(), upper.end(), upper.begin(),
123 using storage_type = std::vector<std::pair<std::string, T>>;
124 using index_type = std::unordered_map<std::string,
typename storage_type::size_type,
127 using iter_type =
typename storage_type::iterator;
128 using const_iter_type =
typename storage_type::const_iterator;
132 storage_type m_vector;
138 OrderedMap(
const index_type& index,
const storage_type& storage)
144 const index_type& getIndex()
const {
return m_map; }
146 const storage_type& getStorage()
const {
return m_vector; }
148 std::size_t count(
const std::string& key)
const {
149 return this->m_map.count(key);
154 T& operator[](
const std::string& key) {
155 if (this->count(key) == 0)
156 this->insert( std::make_pair(key, T()));
158 return this->at(key);
162 std::size_t erase(
const std::string& key) {
163 if (this->count(key) == 0)
166 std::size_t index = this->m_map.at(key);
167 this->m_map.erase(key);
168 this->m_vector.erase(this->m_vector.begin() + index);
170 for (
const auto& index_pair : this->m_map) {
171 auto target_index = index_pair.second;
172 if (target_index > index)
175 this->m_map[index_pair.first] = target_index;
181 void insert(std::pair<std::string,T> key_value_pair) {
182 if (this->count(key_value_pair.first) > 0) {
183 auto iter = m_map.find( key_value_pair.first );
184 size_t index = iter->second;
185 m_vector[index] = key_value_pair;
187 size_t index = m_vector.size();
188 this->m_map.emplace(key_value_pair.first, index);
189 this->m_vector.push_back( std::move( key_value_pair ) );
194 T& get(
const std::string& key) {
195 auto iter = m_map.find( key );
196 if (iter == m_map.end())
198 using namespace std::string_literals;
199 auto startsWithSame = OrderedMapDetail::findSimilarStrings(key, m_vector);
200 if (!startsWithSame.empty())
202 startsWithSame =
" Similar entries are "s +
203 startsWithSame +
"."s;
205 throw std::invalid_argument(
"Key "s + key +
" not found."s
209 size_t index = iter->second;
215 T& iget(
size_t index) {
216 if (index >= m_vector.size())
217 throw std::invalid_argument(
"Invalid index");
218 return m_vector[index].second;
221 const T& get(
const std::string& key)
const {
222 const auto& iter = this->m_map.find( key );
223 if (iter == m_map.end())
225 auto startsWithSame = OrderedMapDetail::findSimilarStrings(key, m_vector);
226 if (!startsWithSame.empty())
228 startsWithSame = std::string(
" Similar entries are ") +
229 startsWithSame + std::string(
".");
231 using namespace std::string_literals;
232 throw std::invalid_argument(
"Key "s + key +
" not found."s
236 size_t index = iter->second;
242 const T& iget(
size_t index)
const {
243 if (index >= m_vector.size())
245 using namespace std::string_literals;
246 throw std::invalid_argument(
"Invalid index "s +
247 std::to_string(index) +
248 " is larger than container size"s);
250 return m_vector[index].second;
253 const T& at(
size_t index)
const {
254 return this->iget(index);
257 const T& at(
const std::string& key)
const {
258 return this->get(key);
261 T& at(
size_t index) {
262 return this->iget(index);
265 T& at(
const std::string& key) {
266 return this->get(key);
269 size_t size()
const {
270 return m_vector.size();
274 const_iter_type begin()
const {
275 return m_vector.begin();
279 const_iter_type end()
const {
280 return m_vector.end();
284 return m_vector.begin();
288 return m_vector.end();
291 iter_type find(
const std::string& key) {
292 const auto map_iter = this->m_map.find(key);
293 if (map_iter == this->m_map.end())
294 return this->m_vector.end();
296 return std::next(this->m_vector.begin(), map_iter->second);
299 const_iter_type find(
const std::string& key)
const {
300 const auto map_iter = this->m_map.find(key);
301 if (map_iter == this->m_map.end())
302 return this->m_vector.end();
304 return std::next(this->m_vector.begin(), map_iter->second);
309 return this->getIndex() == data.getIndex() &&
310 this->getStorage() == data.getStorage();
313 template<
class Serializer>
317 serializer(m_vector);
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30