level_parser.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. #ifndef HEADER_SUPERTUX_SUPERTUX_LEVEL_PARSER_HPP
  17. #define HEADER_SUPERTUX_SUPERTUX_LEVEL_PARSER_HPP
  18. #include <memory>
  19. #include <string>
  20. class Level;
  21. class ReaderDocument;
  22. class ReaderMapping;
  23. class LevelParser final
  24. {
  25. public:
  26. static std::unique_ptr<Level> from_stream(std::istream& stream, const std::string& context, bool worldmap, bool editable);
  27. static std::unique_ptr<Level> from_file(const std::string& filename, bool worldmap, bool editable);
  28. static std::unique_ptr<Level> from_nothing(const std::string& basedir);
  29. static std::unique_ptr<Level> from_nothing_worldmap(const std::string& basedir, const std::string& name);
  30. static std::string get_level_name(const std::string& filename);
  31. private:
  32. LevelParser(Level& level, bool worldmap, bool editable);
  33. void load(const ReaderDocument& doc);
  34. void load(std::istream& stream, const std::string& context);
  35. void load(const std::string& filepath);
  36. void load_old_format(const ReaderMapping& reader);
  37. void create(const std::string& filepath, const std::string& levelname);
  38. private:
  39. Level& m_level;
  40. bool m_worldmap;
  41. bool m_editable;
  42. private:
  43. LevelParser(const LevelParser&) = delete;
  44. LevelParser& operator=(const LevelParser&) = delete;
  45. };
  46. #endif
  47. /* EOF */