HoverRace  2.0
MapNode.h
Go to the documentation of this file.
1 
2 // MapNode.h
3 //
4 // Copyright (c) 2008, 2009, 2015 Michael Imamura.
5 //
6 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // A copy of the license should have been attached to the package from which
10 // you have taken this file. If you can not find the license you can not use
11 // this file.
12 //
13 //
14 // The author makes no representations about the suitability of
15 // this software for any purpose. It is provided "as is" "AS IS",
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17 // implied.
18 //
19 // See the License for the specific language governing permissions
20 // and limitations under the License.
21 
22 #pragma once
23 
24 #include <limits.h>
25 
26 #include "../OS.h"
27 
28 #include "Node.h"
29 
30 namespace HoverRace {
31 namespace Util {
32 namespace yaml {
33 
34 class MapNode : public Node
35 {
36  using SUPER = Node;
37 
38 public:
39  MapNode(yaml_document_t *doc, yaml_node_t *node);
40  virtual ~MapNode();
41 
42 private:
43  void Init() const;
44 
45  using children_t = std::map<std::string, Node*>;
46 
47 public:
48  Node *Get(const std::string &key) const;
49 
50  void ReadString(const std::string &key, std::string &dest) const;
51  void ReadBool(const std::string &key, bool &dest) const;
52  void ReadDouble(const std::string &key, double &dest,
53  double min, double max) const;
54  void ReadFloat(const std::string &key, float &dest,
55  float min, float max) const;
56  void ReadInt(const std::string &key, int &dest,
57  int min = INT_MIN, int max = INT_MAX) const;
58  void ReadPath(const std::string &key, OS::path_t &dest) const;
59 
60  // STL-like iteration, so we can use range-for on the node itself.
61  using iterator = children_t::iterator;
62  using const_iterator = children_t::const_iterator;
63  using value_type = children_t::value_type;
64  const_iterator begin() const;
65  iterator begin();
66  const_iterator end() const;
67  iterator end();
68 
69 private:
70  mutable children_t *children;
71 };
72 
73 } // namespace yaml
74 } // namespace Util
75 } // namespace HoverRace
MapNode(yaml_document_t *doc, yaml_node_t *node)
Constructor.
Definition: MapNode.cpp:36
Base class for LibYAML document nodes.
Definition: Node.h:31
Node * Get(const std::string &key) const
Retrieve the child node for a given key.
Definition: MapNode.cpp:90
boost::filesystem::path path_t
Definition: OS.h:57
void ReadInt(const std::string &key, int &dest, int min=INT_MIN, int max=INT_MAX) const
Definition: MapNode.cpp:143
void Init() const
Lazy initialization of the child nodes.
Definition: MapNode.cpp:55
void ReadFloat(const std::string &key, float &dest, float min, float max) const
Definition: MapNode.cpp:133
virtual ~MapNode()
Destructor.
Definition: MapNode.cpp:42
children_t::const_iterator const_iterator
Definition: MapNode.h:62
const_iterator end() const
Definition: MapNode.cpp:174
children_t * children
Definition: MapNode.h:70
void ReadBool(const std::string &key, bool &dest) const
Definition: MapNode.cpp:114
yaml_document_t * doc
Definition: Node.h:45
void ReadPath(const std::string &key, OS::path_t &dest) const
Definition: MapNode.cpp:153
children_t::value_type value_type
Definition: MapNode.h:63
Node()
Definition: Node.h:34
void ReadDouble(const std::string &key, double &dest, double min, double max) const
Definition: MapNode.cpp:123
const_iterator begin() const
Definition: MapNode.cpp:162
std::map< std::string, Node * > children_t
Definition: MapNode.h:45
yaml_node_t * node
Definition: Node.h:46
Definition: MapNode.h:34
children_t::iterator iterator
Definition: MapNode.h:61
Definition: Announcement.h:24
void ReadString(const std::string &key, std::string &dest) const
Retrieve an optional child node as a string.
Definition: MapNode.cpp:105