载入中...
搜索中...
未找到
LevelFormat.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
6#include "common/Result.h"
7
8#include <memory>
9#include <string>
10#include <vector>
11
12namespace eve::level_editing {
13class LevelDocument;
14
17public:
19 virtual ~LevelFormat() = default;
21 virtual std::string id() const = 0;
23 virtual std::vector<std::string> extensions() const = 0;
25 virtual bool canRead(const std::string& text) const = 0;
26
28 [[nodiscard]] virtual eve::Result<std::unique_ptr<LevelDocument>> read(const std::string& text) const = 0;
30 [[nodiscard]] virtual eve::Result<std::string> write(const LevelDocument& level) const = 0;
31};
32
43public:
46
47 // std::vector<std::unique_ptr<LevelFormat>> makes the implicit copy operations
48 // ill-formed (C2280) as soon as a class-level dllexport instantiates them;
49 // spell the four out so the export surface stays defined. Semantics unchanged:
50 // the registry was never copyable in practice.
57
59 [[nodiscard]] eve::Result<void> registerFormat(std::unique_ptr<LevelFormat> format);
61 int getFormatCount() const { return static_cast<int>(formats_.size()); }
63 std::string getFormatId(int index) const;
65 std::string detect(const std::string& path, const std::string& text) const;
66
68 [[nodiscard]] eve::Result<std::unique_ptr<LevelDocument>> decode(const std::string& format,
69 const std::string& text) const;
71 [[nodiscard]] eve::Result<std::string> encode(const std::string& format, const LevelDocument& level) const;
72
74 [[nodiscard]] eve::Result<std::unique_ptr<LevelDocument>> load(const std::string& path,
75 const std::string& format = {}) const;
83 [[nodiscard]] eve::Result<void> save(const std::string& path, const LevelDocument& level,
84 const std::string& format = {}) const;
85
86private:
87 [[nodiscard]] eve::OptionalRef<const LevelFormat> find(const std::string& id) const;
88 std::vector<std::unique_ptr<LevelFormat>> formats_;
89};
90} // namespace eve::level_editing
Vocabulary aliases for nullable and checked borrowed references.
#define EVENGINE_API_DOMAINS
Definition Export.h:110
std::string text
int level
std::string path
Definition PlayHost.cpp:110
Move-only, checked operation results for the common layer.
uint32_t index
Move-only operation result carrying either a value or Status.
Definition Result.h:155
Format-neutral, editable top-down level model.
Registry and conversion gateway for level formats.
Definition LevelFormat.h:42
int getFormatCount() const
Returns the format count.
Definition LevelFormat.h:61
LevelFormatRegistry & operator=(const LevelFormatRegistry &)=delete
LevelFormatRegistry(LevelFormatRegistry &&)=default
Level format registry.
LevelFormatRegistry & operator=(LevelFormatRegistry &&)=default
Operator =.
LevelFormatRegistry(const LevelFormatRegistry &)=delete
Plug-in contract for importing and exporting a level representation.
Definition LevelFormat.h:16
virtual eve::Result< std::string > write(const LevelDocument &level) const =0
Writes .
virtual ~LevelFormat()=default
Releases LevelFormat resources.
virtual bool canRead(const std::string &text) const =0
Can read.
virtual eve::Result< std::unique_ptr< LevelDocument > > read(const std::string &text) const =0
Reads .
virtual std::vector< std::string > extensions() const =0
Extensions.
virtual std::string id() const =0
Id.
std::optional< std::reference_wrapper< T > > OptionalRef
Optional borrowed reference; it does not extend T's lifetime.
Definition BorrowedRef.h:24