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>
39 #include <typeinfo>
40 #include <string>
41 #include <vector>
42 
44 
45 namespace class_loader
46 {
47 
48 class ClassLoader; // Forward declaration
49 
50 namespace class_loader_private
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 class_loader_private
203 } // namespace class_loader
204 
205 #endif // CLASS_LOADER__META_OBJECT_HPP_
B * create() const
The factory interface to generate an object. The object has type C in reality, though a pointer of th...
The actual factory. C The derived class (the actual plugin) B The base class interface for the plug...
std::string baseClassName() const
gets the base class for the class this factory represents
Definition: meta_object.cpp:69
~AbstractMetaObjectBase()
Destructor for the class. THIS MUST NOT BE VIRTUAL AND OVERRIDDEN BY TEMPLATE SUBCLASSES, OTHERWISE THEY WILL PULL IN A REDUNDANT METAOBJECT DESTRUCTOR OUTSIDE OF libclass_loader WITHIN THE PLUGIN LIBRARY! T.
Definition: meta_object.cpp:54
A base class for MetaObjects that excludes a polymorphic type parameter. Subclasses are class templat...
Definition: meta_object.hpp:59
bool isOwnedByAnybody()
Indicates if the factory is within the usable scope of any ClassLoader.
void removeOwningClassLoader(const ClassLoader *loader)
Removes a ClassLoader that is an owner of this factory.
This class allows loading and unloading of dynamically linked libraries which contain class definitio...
MetaObject(const std::string &class_name, const std::string &base_class_name)
Constructor for the class.
std::string className() const
Gets the literal name of the class.
Definition: meta_object.cpp:63
void addOwningClassLoader(ClassLoader *loader)
Associates a ClassLoader owner with this factory,.
Definition: meta_object.cpp:93
bool isOwnedBy(const ClassLoader *loader)
Indicates if the factory is within the usable scope of a ClassLoader.
AbstractMetaObject(const std::string &class_name, const std::string &base_class_name)
A constructor for this class.
AbstractMetaObjectBase(const std::string &class_name, const std::string &base_class_name)
Constructor for the class.
Definition: meta_object.cpp:40
std::vector< class_loader::ClassLoader * > ClassLoaderVector
Definition: meta_object.hpp:53
void setAssociatedLibraryPath(std::string library_path)
Sets the path to the library associated with this factory.
Definition: meta_object.cpp:87
Abstract base class for factories where polymorphic type variable indicates base class for plugin int...
std::string typeidBaseClassName() const
Gets the name of the class as typeid(BASE_CLASS).name() would return it.
Definition: meta_object.cpp:75
std::string getAssociatedLibraryPath()
Gets the path to the library associated with this factory.
Definition: meta_object.cpp:81


class_loader
Author(s): Mirza Shah
autogenerated on Mon Jun 10 2019 12:51:50