FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
property_map.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
8// includes, FEAT
10#include <kernel/util/dist.hpp>
11
12// includes, system
13#include <iostream>
14#include <map>
15#include <memory>
16
17namespace FEAT
18{
48 {
49 public:
51 typedef std::map<String, String, String::NoCaseLess> EntryMap;
53 typedef std::map<String, std::shared_ptr<PropertyMap>, String::NoCaseLess> SectionMap;
54
56 typedef EntryMap::iterator EntryIterator;
58 typedef EntryMap::const_iterator ConstEntryIterator;
60 typedef SectionMap::iterator SectionIterator;
62 typedef SectionMap::const_iterator ConstSectionIterator;
63
64 protected:
67
70
73
74 public:
76 explicit PropertyMap(PropertyMap* parent = nullptr);
78 PropertyMap(const PropertyMap&) = delete;
81
83 virtual ~PropertyMap();
84
106 bool add_entry(String key, String value, bool replace = true);
107
125
135 bool erase_entry(String key);
136
146 bool erase_section(String name);
147
162 std::pair<String, bool> query(String key_path) const;
163
179 String query(String key_path, String default_value) const;
180
198
200 const PropertyMap* query_section(String sec_path) const;
201
217 std::pair<String, bool> get_entry(String key) const;
218
237
239 const PropertyMap* get_sub_section(String name) const;
240
261 template<typename T_>
262 bool parse_entry(const String& key, T_& x, bool rtn_non_exist = true) const
263 {
264 std::pair<String, bool> it = this->get_entry(key);
265 if(it.second)
266 return it.first.parse(x);
267 else
268 return rtn_non_exist;
269 }
270
278 {
279 return _parent;
280 }
281
283 const PropertyMap* get_parent() const
284 {
285 return _parent;
286 }
287
292 {
293 return (_parent != nullptr) ? _parent->get_root() : this;
294 }
295
297 const PropertyMap* get_root() const
298 {
299 return (_parent != nullptr) ? _parent->get_root() : this;
300 }
301
308 {
309 return _values;
310 }
311
313 const EntryMap& get_entry_map() const
314 {
315 return _values;
316 }
317
320 {
321 return _values.begin();
322 }
323
326 {
327 return _values.begin();
328 }
329
332 {
333 return _values.end();
334 }
335
338 {
339 return _values.end();
340 }
341
344 {
345 return _sections.begin();
346 }
347
350 {
351 return _sections.begin();
352 }
353
356 {
357 return _sections.end();
358 }
359
362 {
363 return _sections.end();
364 }
365
375 void merge(const PropertyMap& section, bool replace = true);
376
390 void read(String filename, bool replace = true)
391 {
393 read(comm, filename, replace);
394 }
395
409 void read(const Dist::Comm& comm, String filename, bool replace = true);
410
422 void read(std::istream& ifs, bool replace = true);
423
434 void write(String filename) const
435 {
437 write(comm, filename);
438 }
439
450 void write(const Dist::Comm& comm, String filename) const;
451
468 void write(std::ostream& os, String::size_type indent = 0) const;
469
483 std::unique_ptr<PropertyMap> treeify_structures() const;
484 }; // class PropertyMap
485} // namespace FEAT
Communicator class.
Definition: dist.hpp:1349
static Comm world()
Returns a copy of the world communicator.
Definition: dist.cpp:429
A class organizing a tree of key-value pairs.
PropertyMap * add_section(String name)
Adds a new sub-section to this map.
ConstSectionIterator begin_section() const
Returns the first section iterator.
EntryMap & get_entry_map()
Returns a reference to the entry map.
EntryIterator begin_entry()
Returns the first entry iterator.
const PropertyMap * get_root() const
Returns a pointer to the root section.
PropertyMap * _parent
pointer to the parent node
SectionIterator begin_section()
Returns the first section iterator.
const EntryMap & get_entry_map() const
Returns a reference to the entry map.
bool erase_section(String name)
Erases a sub-section.
SectionIterator end_section()
Returns the last section iterator.
const PropertyMap * get_parent() const
Returns a pointer to the parent section.
PropertyMap * get_parent()
Returns a pointer to the parent section.
ConstEntryIterator begin_entry() const
Returns the first entry iterator.
PropertyMap * get_root()
Returns a pointer to the root section.
std::unique_ptr< PropertyMap > treeify_structures() const
Builds a new property map by inserting subsection based on section names.
EntryMap::iterator EntryIterator
entry iterator type
ConstSectionIterator end_section() const
Returns the last section iterator.
std::map< String, std::shared_ptr< PropertyMap >, String::NoCaseLess > SectionMap
section-map type
PropertyMap * get_sub_section(String name)
Retrieves a sub-section by its name.
PropertyMap * query_section(String sec_path)
Queries a section by its section path.
SectionMap::iterator SectionIterator
section iterator type
PropertyMap(const PropertyMap &)=delete
Delete copy constructor.
EntryIterator end_entry()
Returns the last entry iterator.
std::pair< String, bool > query(String key_path) const
Queries a value by its key path.
std::map< String, String, String::NoCaseLess > EntryMap
entry-map type
EntryMap::const_iterator ConstEntryIterator
const entry iterator type
EntryMap _values
a map storing the key-value-pairs
PropertyMap & operator=(const PropertyMap &)=delete
Delete copy assignment operator.
SectionMap _sections
a map storing the sub-sections
virtual ~PropertyMap()
Virtual Destructor.
bool erase_entry(String key)
Erases a key-value pair.
bool add_entry(String key, String value, bool replace=true)
Adds a new key-value pair to this map.
void merge(const PropertyMap &section, bool replace=true)
Merges another PropertyMap into this.
std::pair< String, bool > get_entry(String key) const
Retrieves a value by its key.
SectionMap::const_iterator ConstSectionIterator
const section iterator type
void read(String filename, bool replace=true)
Parses a file in INI-format.
ConstEntryIterator end_entry() const
Returns the last entry iterator.
void write(String filename) const
Writes the property map into a file.
bool parse_entry(const String &key, T_ &x, bool rtn_non_exist=true) const
Parses an object from the value of an entry.
A class providing case-insensitive String comparison.
Definition: string.hpp:62
String class implementation.
Definition: string.hpp:46
FEAT namespace.
Definition: adjactor.hpp:12
@ value
specifies whether the space should supply basis function values