Debian Codegraph @

avogadro/core/variantmap.h

raw
1 /******************************************************************************
2 This source file is part of the Avogadro project.
3 This source code is released under the 3-Clause BSD License, (see "LICENSE").
4 ******************************************************************************/
5
6 #ifndef AVOGADRO_CORE_VARIANTMAP_H
7 #define AVOGADRO_CORE_VARIANTMAP_H
8
9 #include "avogadrocoreexport.h"
10
11 #include "variant.h"
12
13 #include <map>
14 #include <string>
15 #include <vector>
16
17 namespace Avogadro::Core {
18
19 /**
20 * @class VariantMap variantmap.h <avogadro/core/variantmap.h>
21 * @brief The VariantMap class provides a map between string keys and variant
22 * values.
23 */
24
25 class AVOGADROCORE_EXPORT VariantMap
26 {
27 public:
28 using iterator = std::map<std::string, Variant>::iterator;
29 using const_iterator = std::map<std::string, Variant>::const_iterator;
30
31 /** Creates a new variant map object. */
32 VariantMap() = default;
33
34 /** Destroys the variant map. */
35 ~VariantMap() = default;
36
37 /** Returns the size of the variant map. */
38 size_t size() const;
39
40 /** Returns \c true if the variant map is empty (i.e. size() == \c 0). */
41 bool isEmpty() const;
42
43 /** Returns the names of the entries in the map. */
44 std::vector<std::string> names() const;
45
46 /** Sets the value of @p name to @p v. */
47 void setValue(const std::string& name, const Variant& v);
48
49 /**
50 * Returns the value for @p name. If @p name is not found a null variant is
51 * returned.
52 */
53 Variant value(const std::string& name) const;
54
55 /**
56 * Returns true if the key exists in the map.
57 */
58 bool hasValue(const std::string& name) const;
59
60 /**
61 * Clears the map.
62 */
63 void clear() { m_map.clear(); }
64
65 /** Return an iterator pointing to the beginning of the map. */
66 iterator begin();
67
68 /** \overload */
69 const_iterator begin() const;
70
71 /** Return a const_iterator pointing to the beginning of the map. */
72 const_iterator constBegin() const;
73
74 /** Return an iterator pointing to the end of the map. */
75 iterator end();
76
77 /** \overload */
78 const_iterator end() const;
79
80 /** Return a const_iterator pointing to the end of the map. */
81 const_iterator constEnd() const;
82
83 private:
84 std::map<std::string, Variant> m_map;
85 };
86
87 } // namespace Avogadro::Core
88
89 #endif // AVOGADRO_CORE_VARIANTMAP_H