Flow123d  master-f44eb46
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/impl.h" // for Node::Node, Node::operat...
28 #include "yaml-cpp/node/node.h" // for Node
29 
30 #include "input/path_base.hh"
31 
32 
33 namespace Input {
34 
35 
36 
37 /**
38  * @brief Class used by ReaderToStorage class to iterate over the YAML tree provided by yaml-cpp library.
39  *
40  * This class keeps whole path from the root of the YAML tree to the current node. We store nodes along path in \p nodes_
41  * and address of the node in \p path_.
42  *
43  * The class also contains methods for processing of special tags for 'TYPE' key. Class doesn't need special methods
44  * for work with references. YAML tree used own native references.
45  */
46 class PathYAML : public PathBase {
47 public:
48  /// Definition of YAML-cpp node.
49  typedef YAML::Node Node;
50 
51  /// Constructor.
52  PathYAML(std::istream &in);
53 
54  /**
55  * @brief Destructor.
56  *
57  * Clean nodes_.
58  */
59  ~PathYAML() override;
60 
61  /**
62  * @brief Returns level of actual path.
63  *
64  * Root has level == 0.
65  */
66  inline int level() const
67  { return nodes_.size() - 1; }
68 
69  /**
70  * @brief Dive into yaml-cpp hierarchy.
71  *
72  * Implements @p PathBase::down(unsigned int)
73  */
74  bool down(unsigned int index) override;
75 
76  /**
77  * @brief Dive into yaml-cpp hierarchy.
78  *
79  * Implements @p PathBase::down(const std::string&)
80  */
81  bool down(const std::string& key, int index = -1) override;
82 
83  /// Return one level up in the hierarchy.
84  void up() override;
85 
86  // These methods are derived from PathBase
87  bool is_null_type() const override; ///< Implements @p PathBase::is_null_type
88  bool get_bool_value() const override; ///< Implements @p PathBase::get_bool_value
89  std::int64_t get_int_value() const override; ///< Implements @p PathBase::get_int_value
90  double get_double_value() const override; ///< Implements @p PathBase::get_double_value
91  std::string get_string_value() const override; ///< Implements @p PathBase::get_string_value
92  unsigned int get_node_type_index() const override; ///< Implements @p PathBase::get_node_type_index
93  bool get_record_key_set(std::set<std::string> &) const override; ///< Implements @p PathBase::get_record_key_set
94  bool is_effectively_null() const override; ///< Implements @p PathBase::is_effectively_null
95  int get_array_size() const override; ///< Implements @p PathBase::get_array_size
96  bool is_record_type() const override; ///< Implements @p PathBase::is_record_type
97  bool is_array_type() const override; ///< Implements @p PathBase::is_array_type
98  PathYAML * clone() const override; ///< Implements @p PathBase::clone
99 
100  /// Implements reading of reference keys, and check of cyclic references.
101  PathBase * find_ref_node() override;
102 
103  /// Implements @p PathBase::get_record_tag
104  std::string get_record_tag() const override;
105 
106 protected:
107 
108 
109  /// Pointer to YAML Value object at current path.
110  inline const Node &head() const
111  { return nodes_.back(); }
112 
113  // Pointers to all nodes from the root up to the current path.
115 };
116 
117 
118 /**
119  * @brief Output operator for PathYAML.
120  *
121  * Mainly for debugging purposes and error messages.
122  */
123 std::ostream& operator<<(std::ostream& stream, const PathYAML& path);
124 
125 
126 
127 } // namespace Input
128 
129 
130 
131 #endif /* PATH_YAML_HH_ */
Base abstract class used by ReaderToStorage class to iterate over the input tree.
Definition: path_base.hh:41
Class used by ReaderToStorage class to iterate over the YAML tree provided by yaml-cpp library.
Definition: path_yaml.hh:46
~PathYAML() override
Destructor.
Definition: path_yaml.cc:46
bool is_null_type() const override
Implements PathBase::is_null_type.
Definition: path_yaml.cc:88
int get_array_size() const override
Implements PathBase::get_array_size.
Definition: path_yaml.cc:179
std::string get_string_value() const override
Implements PathBase::get_string_value.
Definition: path_yaml.cc:135
bool down(unsigned int index) override
Dive into yaml-cpp hierarchy.
Definition: path_yaml.cc:52
YAML::Node Node
Definition of YAML-cpp node.
Definition: path_yaml.hh:49
const Node & head() const
Pointer to YAML Value object at current path.
Definition: path_yaml.hh:110
bool down(const std::string &key, int index=-1) override
Dive into yaml-cpp hierarchy.
double get_double_value() const override
Implements PathBase::get_double_value.
Definition: path_yaml.cc:121
std::int64_t get_int_value() const override
Implements PathBase::get_int_value.
Definition: path_yaml.cc:107
void up() override
Return one level up in the hierarchy.
Definition: path_yaml.cc:80
PathBase * find_ref_node() override
Implements reading of reference keys, and check of cyclic references.
Definition: path_yaml.cc:202
bool is_effectively_null() const override
Implements PathBase::is_effectively_null.
Definition: path_yaml.cc:220
bool get_record_key_set(std::set< std::string > &) const override
Implements PathBase::get_record_key_set.
Definition: path_yaml.cc:160
bool get_bool_value() const override
Implements PathBase::get_bool_value.
Definition: path_yaml.cc:93
bool is_record_type() const override
Implements PathBase::is_record_type.
Definition: path_yaml.cc:187
PathYAML(std::istream &in)
Constructor.
Definition: path_yaml.cc:30
bool is_array_type() const override
Implements PathBase::is_array_type.
Definition: path_yaml.cc:192
int level() const
Returns level of actual path.
Definition: path_yaml.hh:66
PathYAML * clone() const override
Implements PathBase::clone.
Definition: path_yaml.cc:197
std::string get_record_tag() const override
Implements PathBase::get_record_tag.
Definition: path_yaml.cc:209
unsigned int get_node_type_index() const override
Implements PathBase::get_node_type_index.
Definition: path_yaml.cc:149
std::vector< Node > nodes_
Definition: path_yaml.hh:114
Abstract linear system class.
Definition: balance.hh:40
std::ostream & operator<<(std::ostream &stream, const Address &address)
Definition: accessors.hh:252