| 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 |
| 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 | |
| 30 | /** The ReaderIterator class is for backward compatibilty with old |
| 31 | fileformats only, do not use it in new code, use ReaderCollection |
| 32 | and ReaderMapping instead */ |
| 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 | |
| 39 | /** must be called once before any of the other function become |
| 40 | valid, i.e. ReaderIterator it; while(it.next()) { ... } */ |
| 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 */ |
| 68 | |