Apollo 10.0
自动驾驶开放平台
class_factory.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16#ifndef CYBER_CLASS_LOADER_UTILITY_CLASS_FACTORY_H_
17#define CYBER_CLASS_LOADER_UTILITY_CLASS_FACTORY_H_
18
19#include <string>
20#include <typeinfo>
21#include <vector>
22
23namespace apollo {
24namespace cyber {
25namespace class_loader {
26
27class ClassLoader;
28
29namespace utility {
30
32 public:
33 AbstractClassFactoryBase(const std::string& class_name,
34 const std::string& base_class_name);
36
37 void SetRelativeLibraryPath(const std::string& library_path);
38 void AddOwnedClassLoader(ClassLoader* loader);
39 void RemoveOwnedClassLoader(const ClassLoader* loader);
40 bool IsOwnedBy(const ClassLoader* loader);
41 bool IsOwnedByAnybody();
42 std::vector<ClassLoader*> GetRelativeClassLoaders();
43 const std::string GetRelativeLibraryPath() const;
44 const std::string GetBaseClassName() const;
45 const std::string GetClassName() const;
46
47 protected:
48 std::vector<ClassLoader*> relative_class_loaders_;
50 std::string base_class_name_;
51 std::string class_name_;
52};
53
54template <typename Base>
56 public:
57 AbstractClassFactory(const std::string& class_name,
58 const std::string& base_class_name)
59 : AbstractClassFactoryBase(class_name, base_class_name) {}
60
61 virtual Base* CreateObj() const = 0;
62
63 private:
67};
68
69template <typename ClassObject, typename Base>
70class ClassFactory : public AbstractClassFactory<Base> {
71 public:
72 ClassFactory(const std::string& class_name,
73 const std::string& base_class_name)
74 : AbstractClassFactory<Base>(class_name, base_class_name) {}
75
76 Base* CreateObj() const { return new ClassObject; }
77};
78
79} // namespace utility
80} // namespace class_loader
81} // namespace cyber
82} // namespace apollo
83
84#endif // CYBER_CLASS_LOADER_UTILITY_CLASS_FACTORY_H_
Definition base.h:20
for library load,createclass object
void SetRelativeLibraryPath(const std::string &library_path)
AbstractClassFactory(const std::string &class_name, const std::string &base_class_name)
ClassFactory(const std::string &class_name, const std::string &base_class_name)
class register implement
Definition arena_queue.h:37