载入中...
搜索中...
未找到
ObjectRegistry.h
浏览该文件的文档.
1#pragma once
2
3#include "common/Export.h"
4#include "common/Result.h"
6
7#include <simplesquirrel/simplesquirrel.hpp>
8
9#include <cstddef>
10#include <cstdint>
11#include <map>
12#include <optional>
13#include <string>
14#include <vector>
15
16namespace eve::ui {
17
20
29
33 ObjectHandle handle = ObjectHandle::invalid();
35 std::string className;
37 std::string label;
39 ssq::Object object;
40};
41
57public:
62
64 static ObjectRegistry& instance();
65
72 [[nodiscard("retain ObjectHandle or explicitly inspect the failure")]]
73 eve::Result<ObjectHandle> create(const std::string& className);
82 [[nodiscard("retain ObjectHandle or explicitly inspect the failure")]]
83 eve::Result<ObjectHandle> registerObject(const std::string& className, const ssq::Object& object,
84 const std::string& label = {});
91 [[nodiscard]] eve::Result<void> unregister(ObjectHandle handle);
93 void clear(const std::string& className);
95 void clearAll();
96
98 std::vector<std::string> classNames() const;
100 std::vector<ObjectEntry> entries(const std::string& className) const;
110 [[nodiscard("inspect the borrowed entry or explicitly ignore it")]]
111 const ObjectEntry* entry(ObjectHandle handle) const noexcept;
116 [[nodiscard]] bool isStale(ObjectHandle handle) const noexcept;
118 size_t count(const std::string& className) const;
119
120private:
121 struct Slot {
122 std::uint32_t generation = 1;
123 bool retired = false;
124 std::optional<ObjectEntry> entry;
125 };
126
135 [[nodiscard]] Slot* slot(ObjectHandle handle) noexcept;
144 [[nodiscard]] const Slot* slot(ObjectHandle handle) const noexcept;
145
146 ObjectRegistry() = default;
147 std::vector<Slot> slots_;
148 std::vector<std::uint32_t> freeSlots_;
149 std::map<std::string, std::vector<ObjectHandle>> byClass_;
150};
151
152} // namespace eve::ui
std::unordered_map< std::string, QuestRuntime > entries
std::string label
#define EVENGINE_API_WORLD_INLINE
Definition Export.h:173
#define EVENGINE_API_WORLD
Definition Export.h:109
bool retired
std::uint32_t generation
PrimitiveHandle handle
Move-only, checked operation results for the common layer.
Strong generation-qualified handles for non-ECS runtime registries.
std::uint32_t count
Move-only operation result carrying either a value or Status.
Definition Result.h:155
Reflectable script-object registry backing the database panel.
ObjectRegistry(const ObjectRegistry &)=delete
ObjectRegistry & operator=(const ObjectRegistry &)=delete
One registered live script instance.
ssq::Object object
Rooted script instance owned by the registry while live.
std::string className
Reflected script class used to group this entry.
std::string label
Optional display label shown by the database panel.
Owner tag for UI database object handles.