meta_object.hpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2012, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  * * Neither the name of the copyright holders nor the names of its
16  * contributors may be used to endorse or promote products derived from
17  * this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 // Note: This header defines a simplication of Poco::MetaObject
33 // that allows us to tag MetaObjects with an associated library name.
34 
35 #ifndef CLASS_LOADER__META_OBJECT_HPP_
36 #define CLASS_LOADER__META_OBJECT_HPP_
37 
38 #include <console_bridge/console.h>
40 
41 #include <typeinfo>
42 #include <string>
43 #include <vector>
44 
45 namespace class_loader
46 {
47 
48 class ClassLoader; // Forward declaration
49 
50 namespace impl
51 {
52 
53 typedef std::vector<class_loader::ClassLoader *> ClassLoaderVector;
54 
60 {
61 public:
65  AbstractMetaObjectBase(const std::string & class_name, const std::string & base_class_name);
72 
77  std::string className() const;
78 
82  std::string baseClassName() const;
86  std::string typeidBaseClassName() const;
87 
92  std::string getAssociatedLibraryPath();
93 
97  void setAssociatedLibraryPath(std::string library_path);
98 
103  void addOwningClassLoader(ClassLoader * loader);
104 
109  void removeOwningClassLoader(const ClassLoader * loader);
110 
115  bool isOwnedBy(const ClassLoader * loader);
116 
120  bool isOwnedByAnybody();
121 
125  ClassLoaderVector getAssociatedClassLoaders();
126 
127 protected:
131  virtual void dummyMethod() {}
132 
133 protected:
134  ClassLoaderVector associated_class_loaders_;
136  std::string base_class_name_;
137  std::string class_name_;
139 };
140 
146 template<class B>
148 {
149 public:
154  AbstractMetaObject(const std::string & class_name, const std::string & base_class_name)
155  : AbstractMetaObjectBase(class_name, base_class_name)
156  {
157  AbstractMetaObjectBase::typeid_base_class_name_ = std::string(typeid(B).name());
158  }
159 
164  virtual B * create() const = 0;
167 
168 private:
171  AbstractMetaObject & operator=(const AbstractMetaObject &);
172 };
173 
180 template<class C, class B>
182 {
183 public:
187  MetaObject(const std::string & class_name, const std::string & base_class_name)
188  : AbstractMetaObject<B>(class_name, base_class_name)
189  {
190  }
191 
196  B * create() const
197  {
198  return new C;
199  }
200 };
201 
202 } // namespace impl
203 } // namespace class_loader
204 
205 #endif // CLASS_LOADER__META_OBJECT_HPP_
std::vector< class_loader::ClassLoader * > ClassLoaderVector
Definition: meta_object.hpp:53
A base class for MetaObjects that excludes a polymorphic type parameter. Subclasses are class templat...
Definition: meta_object.hpp:59
MetaObject(const std::string &class_name, const std::string &base_class_name)
Constructor for the class.
This class allows loading and unloading of dynamically linked libraries which contain class definitio...
The actual factory. C The derived class (the actual plugin) B The base class interface for the plug...
Abstract base class for factories where polymorphic type variable indicates base class for plugin int...
#define CLASS_LOADER_PUBLIC
AbstractMetaObject(const std::string &class_name, const std::string &base_class_name)
A constructor for this class.
B * create() const
The factory interface to generate an object. The object has type C in reality, though a pointer of th...


class_loader
Author(s): Mirza Shah, Steven! Ragnarök
autogenerated on Mon Feb 28 2022 22:02:03