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:
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:
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_
class_loader::impl::AbstractMetaObject::create
virtual B * create() const =0
Defines the factory interface that the MetaObject must implement.
class_loader::impl::MetaObject::MetaObject
MetaObject(const std::string &class_name, const std::string &base_class_name)
Constructor for the class.
Definition: meta_object.hpp:187
class_loader::impl::AbstractMetaObjectBase::class_name_
std::string class_name_
Definition: meta_object.hpp:137
class_loader
Definition: class_loader.hpp:50
class_loader::impl::AbstractMetaObjectBase
A base class for MetaObjects that excludes a polymorphic type parameter. Subclasses are class templat...
Definition: meta_object.hpp:59
class_loader::impl::AbstractMetaObject::AbstractMetaObject
AbstractMetaObject(const std::string &class_name, const std::string &base_class_name)
A constructor for this class.
Definition: meta_object.hpp:154
class_loader::impl::AbstractMetaObjectBase::associated_class_loaders_
ClassLoaderVector associated_class_loaders_
Definition: meta_object.hpp:134
class_loader::impl::AbstractMetaObject
Abstract base class for factories where polymorphic type variable indicates base class for plugin int...
Definition: meta_object.hpp:147
class_loader::impl::AbstractMetaObjectBase::associated_library_path_
std::string associated_library_path_
Definition: meta_object.hpp:135
class_loader::impl::MetaObject::create
B * create() const
The factory interface to generate an object. The object has type C in reality, though a pointer of th...
Definition: meta_object.hpp:196
class_loader::impl::AbstractMetaObject::AbstractMetaObject
AbstractMetaObject()
class_loader::impl::AbstractMetaObjectBase::typeid_base_class_name_
std::string typeid_base_class_name_
Definition: meta_object.hpp:138
class_loader::ClassLoader
This class allows loading and unloading of dynamically linked libraries which contain class definitio...
Definition: class_loader.hpp:78
CLASS_LOADER_PUBLIC
#define CLASS_LOADER_PUBLIC
Definition: visibility_control.hpp:58
class_loader::impl::MetaObject
The actual factory. @parm C The derived class (the actual plugin) @parm B The base class interface fo...
Definition: meta_object.hpp:181
class_loader::impl::ClassLoaderVector
std::vector< class_loader::ClassLoader * > ClassLoaderVector
Definition: meta_object.hpp:53
visibility_control.hpp
class_loader::impl::AbstractMetaObject::operator=
AbstractMetaObject & operator=(const AbstractMetaObject &)
class_loader::impl::AbstractMetaObjectBase::dummyMethod
virtual void dummyMethod()
Definition: meta_object.hpp:131
class_loader::impl::AbstractMetaObjectBase::base_class_name_
std::string base_class_name_
Definition: meta_object.hpp:136


class_loader
Author(s): Mirza Shah, Steven! Ragnarök
autogenerated on Mon Oct 12 2020 04:02:13