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
23class Level;
24class ReaderDocument;
25class ReaderMapping;
26
27class LevelParser final
28{
29public:
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
37private:
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
46private:
47 Level& m_level;
48 bool m_worldmap;
49 bool m_editable;
50
51private:
52 LevelParser(const LevelParser&) = delete;
53 LevelParser& operator=(const LevelParser&) = delete;
54};
55
56#endif
57
58/* EOF */
59