Flow123d  release_2.2.0-914-gf1a3a4f
path_yaml.hh
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file path_yaml.hh
15  * @brief
16  */
17 
18 #ifndef PATH_YAML_HH_
19 #define PATH_YAML_HH_
20 
21 
22 #include <stdint.h> // for int64_t
23 #include <iosfwd> // for ostream, istream
24 #include <set> // for set
25 #include <string> // for string
26 #include <vector> // for vector
27 #include "yaml-cpp/node/detail/bool_type.h" // for Node::operator void (*)(...
28 #include "yaml-cpp/node/impl.h" // for Node::Node, Node::operat...
29 #include "yaml-cpp/node/node.h" // for Node
30 
31 #include "input/path_base.hh"
32 
33 
34 namespace Input {
35 
36 
37 
38 /**
39  * @brief Class used by ReaderToStorage class to iterate over the YAML tree provided by yaml-cpp library.
40  *
41  * This class keeps whole path from the root of the YAML tree to the current node. We store nodes along path in \p nodes_
42  * and address of the node in \p path_.
43  *
44  * The class also contains methods for processing of special tags for 'TYPE' key. Class doesn't need special methods
45  * for work with references. YAML tree used own native references.
46  */
47 class PathYAML : public PathBase {
48 public:
49  /// Definition of YAML-cpp node.
50  typedef YAML::Node Node;
51 
52  /// Constructor.
53  PathYAML(std::istream &in);
54 
55  /**
56  * @brief Destructor.
57  *
58  * Clean nodes_.
59  */
60  ~PathYAML() override;
61 
62  /**
63  * @brief Returns level of actual path.
64  *
65  * Root has level == 0.
66  */
67  inline int level() const
68  { return nodes_.size() - 1; }
69 
70  /**
71  * @brief Dive into yaml-cpp hierarchy.
72  *
73  * Implements @p PathBase::down(unsigned int)
74  */
75  bool down(unsigned int index) override;
76 
77  /**
78  * @brief Dive into yaml-cpp hierarchy.
79  *
80  * Implements @p PathBase::down(const std::string&)
81  */
82  bool down(const std::string& key, int index = -1) override;
83 
84  /// Return one level up in the hierarchy.
85  void up() override;
86 
87  // These methods are derived from PathBase
88  bool is_null_type() const override; ///< Implements @p PathBase::is_null_type
89  bool get_bool_value() const override; ///< Implements @p PathBase::get_bool_value
90  std::int64_t get_int_value() const override; ///< Implements @p PathBase::get_int_value
91  double get_double_value() const override; ///< Implements @p PathBase::get_double_value
92  std::string get_string_value() const override; ///< Implements @p PathBase::get_string_value
93  unsigned int get_node_type_index() const override; ///< Implements @p PathBase::get_node_type_index
94  bool get_record_key_set(std::set<std::string> &) const override; ///< Implements @p PathBase::get_record_key_set
95  bool is_effectively_null() const override; ///< Implements @p PathBase::is_effectively_null
96  int get_array_size() const override; ///< Implements @p PathBase::get_array_size
97  bool is_record_type() const override; ///< Implements @p PathBase::is_record_type
98  bool is_array_type() const override; ///< Implements @p PathBase::is_array_type
99  PathYAML * clone() const override; ///< Implements @p PathBase::clone
100 
101  /// Implements reading of reference keys, and check of cyclic references.
102  PathBase * find_ref_node() override;
103 
104  /// Implements @p PathBase::get_record_tag
105  std::string get_record_tag() const override;
106 
107 protected:
108 
109 
110  /// Pointer to YAML Value object at current path.
111  inline const Node &head() const
112  { return nodes_.back(); }
113 
114  // Pointers to all nodes from the root up to the current path.
116 };
117 
118 
119 /**
120  * @brief Output operator for PathYAML.
121  *
122  * Mainly for debugging purposes and error messages.
123  */
124 std::ostream& operator<<(std::ostream& stream, const PathYAML& path);
125 
126 
127 
128 } // namespace Input
129 
130 
131 
132 #endif /* PATH_YAML_HH_ */
unsigned int get_node_type_index() const override
Implements PathBase::get_node_type_index.
Definition: path_yaml.cc:145
Class used by ReaderToStorage class to iterate over the YAML tree provided by yaml-cpp library...
Definition: path_yaml.hh:47
YAML::Node Node
Definition of YAML-cpp node.
Definition: path_yaml.hh:50
int get_array_size() const override
Implements PathBase::get_array_size.
Definition: path_yaml.cc:168
std::ostream & operator<<(std::ostream &stream, const Address &address)
Definition: accessors.hh:253
Base abstract class used by ReaderToStorage class to iterate over the input tree. ...
Definition: path_base.hh:41
Abstract linear system class.
Definition: equation.hh:37
std::int64_t get_int_value() const override
Implements PathBase::get_int_value.
Definition: path_yaml.cc:103
bool is_null_type() const override
Implements PathBase::is_null_type.
Definition: path_yaml.cc:84
PathBase * find_ref_node() override
Implements reading of reference keys, and check of cyclic references.
Definition: path_yaml.cc:191
bool get_record_key_set(std::set< std::string > &) const override
Implements PathBase::get_record_key_set.
Definition: path_yaml.cc:156
bool is_array_type() const override
Implements PathBase::is_array_type.
Definition: path_yaml.cc:181
PathYAML(std::istream &in)
Constructor.
Definition: path_yaml.cc:30
~PathYAML() override
Destructor.
Definition: path_yaml.cc:46
const Node & head() const
Pointer to YAML Value object at current path.
Definition: path_yaml.hh:111
std::vector< Node > nodes_
Definition: path_yaml.hh:115
bool is_effectively_null() const override
Implements PathBase::is_effectively_null.
Definition: path_yaml.cc:209
bool is_record_type() const override
Implements PathBase::is_record_type.
Definition: path_yaml.cc:176
PathYAML * clone() const override
Implements PathBase::clone.
Definition: path_yaml.cc:186
int level() const
Returns level of actual path.
Definition: path_yaml.hh:67
double get_double_value() const override
Implements PathBase::get_double_value.
Definition: path_yaml.cc:117
bool get_bool_value() const override
Implements PathBase::get_bool_value.
Definition: path_yaml.cc:89
bool down(unsigned int index) override
Dive into yaml-cpp hierarchy.
Definition: path_yaml.cc:52
std::string get_string_value() const override
Implements PathBase::get_string_value.
Definition: path_yaml.cc:131
void up() override
Return one level up in the hierarchy.
Definition: path_yaml.cc:76
std::string get_record_tag() const override
Implements PathBase::get_record_tag.
Definition: path_yaml.cc:198