supertux
level_parser.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_SUPERTUX_LEVEL_PARSER_HPP
18 #define HEADER_SUPERTUX_SUPERTUX_LEVEL_PARSER_HPP
19 
20 #include <memory>
21 #include <string>
22 
23 class Level;
24 class ReaderDocument;
25 class ReaderMapping;
26 
27 class LevelParser final
28 {
29 public:
30  static std::unique_ptr<Level> from_stream(std::istream& stream, const std::string& context, bool worldmap, bool editable);
31  static std::unique_ptr<Level> from_file(const std::string& filename, bool worldmap, bool editable);
32  static std::unique_ptr<Level> from_nothing(const std::string& basedir);
33  static std::unique_ptr<Level> from_nothing_worldmap(const std::string& basedir, const std::string& name);
34 
35  static std::string get_level_name(const std::string& filename);
36 
37 private:
38  LevelParser(Level& level, bool worldmap, bool editable);
39 
40  void load(const ReaderDocument& doc);
41  void load(std::istream& stream, const std::string& context);
42  void load(const std::string& filepath);
43  void load_old_format(const ReaderMapping& reader);
44  void create(const std::string& filepath, const std::string& levelname);
45 
46 private:
47  Level& m_level;
48  bool m_worldmap;
49  bool m_editable;
50 
51 private:
52  LevelParser(const LevelParser&) = delete;
53  LevelParser& operator=(const LevelParser&) = delete;
54 };
55 
56 #endif
57 
58 /* EOF */
Definition: level_parser.hpp:27
Definition: object_settings.hpp:32
Represents a collection of Sectors running in a single GameSession.
Definition: level.hpp:30
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