Apollo  6.0
Open source self driving car software
class_factory.h
Go to the documentation of this file.
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 
23 namespace apollo {
24 namespace cyber {
25 namespace class_loader {
26 
27 class ClassLoader;
28 
29 namespace utility {
30 
32  public:
33  AbstractClassFactoryBase(const std::string& class_name,
34  const std::string& base_class_name);
35  virtual ~AbstractClassFactoryBase();
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 
54 template <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:
66  AbstractClassFactory& operator=(const AbstractClassFactory&);
67 };
68 
69 template <typename ClassObject, typename Base>
70 class 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
std::vector< ClassLoader * > relative_class_loaders_
Definition: class_factory.h:48
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
void SetRelativeLibraryPath(const std::string &library_path)
std::string relative_library_path_
Definition: class_factory.h:49
AbstractClassFactory(const std::string &class_name, const std::string &base_class_name)
Definition: class_factory.h:57
Base * CreateObj() const
Definition: class_factory.h:76
std::string class_name_
Definition: class_factory.h:51
ClassFactory(const std::string &class_name, const std::string &base_class_name)
Definition: class_factory.h:72
std::string base_class_name_
Definition: class_factory.h:50
AbstractClassFactoryBase(const std::string &class_name, const std::string &base_class_name)
Definition: class_loader.h:35