Sese Framework  x.y.z
A cross-platform framework
载入中...
搜索中...
未找到
ClassFactory.h
浏览该文件的文档.
1// Copyright 2024 libsese
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
22#pragma once
23
25#include "sese/util/Result.h"
26
27#include <map>
28#include <string>
29#include <typeinfo>
30#include <functional>
31
32namespace sese::plugin {
33
34// GCOVR_EXCL_START
35
38public:
40 struct RegisterInfo {
41 const std::type_info *info;
42 std::function<std::shared_ptr<BaseClass>()> builder;
43 };
44 using RegisterInfoMapType = std::map<std::string, RegisterInfo>;
45
46 ClassFactory() noexcept = default;
47 ClassFactory(ClassFactory &&class_factory) = delete;
48 ClassFactory(const ClassFactory &class_factory) = delete;
49 virtual ~ClassFactory() = default;
50
51 virtual void init() = 0;
52
55 BaseClass::Ptr createClassWithName(const std::string &id) noexcept;
56
57 Result<BaseClass::Ptr> createClassWithNameEx(const std::string &id) noexcept;
58
62
63protected:
65};
66
67// GCOVR_EXCL_STOP
68
69} // namespace sese::plugin