supertux
reader_iterator.hpp
1 // SuperTux
2 // Copyright (C) 2015 Ingo Ruhnke <grumbel@gmail.com>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef HEADER_SUPERTUX_UTIL_READER_ITERATOR_HPP
18 #define HEADER_SUPERTUX_UTIL_READER_ITERATOR_HPP
19 
20 #include <string>
21 #include <vector>
22 
23 namespace sexp {
24 class Value;
25 } // namespace sexp
26 
27 class ReaderMapping;
28 class ReaderDocument;
29 
33 class ReaderIterator final
34 {
35 public:
36  // sx should point to (section (name value)...)
37  ReaderIterator(const ReaderDocument& doc, const sexp::Value& sx);
38 
41  bool next();
42 
43  bool is_string();
44  bool is_pair();
45  std::string as_string_item();
46 
47  std::string get_key() const;
48 
49  void get(bool& value) const;
50  void get(int& value) const;
51  void get(float& value) const;
52  void get(std::string& value) const;
53 
54  ReaderMapping as_mapping() const;
55 
56  const sexp::Value& get_sexp() const;
57  const ReaderDocument& get_doc() const { return m_doc; }
58 
59 private:
60  const ReaderDocument& m_doc;
61  const std::vector<sexp::Value>& m_arr;
62  size_t m_idx;
63 };
64 
65 #endif
66 
67 /* EOF */
The ReaderIterator class is for backward compatibilty with old fileformats only, do not use it in new...
Definition: reader_iterator.hpp:33
Definition: object_option.hpp:39
Definition: reader_mapping.hpp:32
The ReaderDocument holds a parsed document in memory, access to it&#39;s content is provided by get_root(...
Definition: reader_document.hpp:27