class_loader  master
The class_loader package is a ROS-independent package for loading plugins during runtime.
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 a shared library
33 
34 #ifndef CLASS_LOADER__META_OBJECT_HPP_
35 #define CLASS_LOADER__META_OBJECT_HPP_
36 
37 #include <string>
38 #include <typeinfo>
39 #include <vector>
40 
42 
43 namespace class_loader
44 {
45 
46 class ClassLoader; // Forward declaration
47 
48 namespace impl
49 {
50 
51 class AbstractMetaObjectBaseImpl;
52 
58 {
59 public:
64  const std::string & class_name,
65  const std::string & base_class_name,
66  const std::string & typeid_base_class_name = "UNSET");
73 
79  const std::string & className() const;
80 
84  const std::string & baseClassName() const;
88  const std::string & typeidBaseClassName() const;
89 
95  const std::string & getAssociatedLibraryPath() const;
96 
100  void setAssociatedLibraryPath(const std::string & library_path);
101 
107  void addOwningClassLoader(ClassLoader * loader);
108 
114  void removeOwningClassLoader(const ClassLoader * loader);
115 
122  bool isOwnedBy(const ClassLoader * loader) const;
123 
129  bool isOwnedByAnybody() const;
130 
136  size_t getAssociatedClassLoadersCount() const;
137 
144  ClassLoader * getAssociatedClassLoader(size_t index) const;
145 
146 protected:
150  virtual void dummyMethod() {}
151 
152  AbstractMetaObjectBaseImpl * impl_;
153 };
154 
162 template<class B>
164 {
165 public:
171  AbstractMetaObject(const std::string & class_name, const std::string & base_class_name)
172  : AbstractMetaObjectBase(class_name, base_class_name, typeid(B).name())
173  {
174  }
175 
181  virtual B * create() const = 0;
184 
185 private:
188  AbstractMetaObject & operator=(const AbstractMetaObject &);
189 };
190 
198 template<class C, class B>
200 {
201 public:
205  MetaObject(const std::string & class_name, const std::string & base_class_name)
206  : AbstractMetaObject<B>(class_name, base_class_name)
207  {
208  }
209 
216  B * create() const
217  {
218  return new C;
219  }
220 };
221 
222 } // namespace impl
223 } // namespace class_loader
224 
225 #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.
std::string
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:205
class_loader
Definition: class_loader.hpp:59
class_loader::impl::AbstractMetaObjectBase
A base class for MetaObjects that excludes a polymorphic type parameter. Subclasses are class templat...
Definition: meta_object.hpp:57
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:171
class_loader::impl::AbstractMetaObject
Abstract base class for factories where polymorphic type variable indicates base class for plugin int...
Definition: meta_object.hpp:163
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:216
class_loader::ClassLoader
This class allows loading and unloading of dynamically linked libraries which contain class definitio...
Definition: class_loader.hpp:79
CLASS_LOADER_PUBLIC
#define CLASS_LOADER_PUBLIC
Definition: visibility_control.hpp:58
class_loader::impl::MetaObject
The actual factory.
Definition: meta_object.hpp:199
visibility_control.hpp
class_loader::impl::AbstractMetaObjectBase::impl_
AbstractMetaObjectBaseImpl * impl_
Definition: meta_object.hpp:152
class_loader::impl::AbstractMetaObjectBase::dummyMethod
virtual void dummyMethod()
Definition: meta_object.hpp:150