meta_object.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 // Note: This header defines a simplication of Poco::MetaObject
31 // that allows us to tag MetaObjects with an associated library name.
32 
33 #ifndef CLASS_LOADER__META_OBJECT_H_
34 #define CLASS_LOADER__META_OBJECT_H_
35 
36 #include <console_bridge/console.h>
37 #include <typeinfo>
38 #include <string>
39 #include <vector>
40 
42 
43 namespace class_loader
44 {
45 
46 class ClassLoader; // Forward declaration
47 
48 namespace class_loader_private
49 {
50 
51 typedef std::vector<class_loader::ClassLoader *> ClassLoaderVector;
52 
58 {
59 public:
63  AbstractMetaObjectBase(const std::string & class_name, const std::string & base_class_name);
70 
75  std::string className() const;
76 
80  std::string baseClassName() const;
84  std::string typeidBaseClassName() const;
85 
90  std::string getAssociatedLibraryPath();
91 
95  void setAssociatedLibraryPath(std::string library_path);
96 
101  void addOwningClassLoader(ClassLoader * loader);
102 
107  void removeOwningClassLoader(const ClassLoader * loader);
108 
113  bool isOwnedBy(const ClassLoader * loader);
114 
118  bool isOwnedByAnybody();
119 
123  ClassLoaderVector getAssociatedClassLoaders();
124 
125 protected:
129  virtual void dummyMethod() {}
130 
131 protected:
132  ClassLoaderVector associated_class_loaders_;
134  std::string base_class_name_;
135  std::string class_name_;
137 };
138 
144 template<class B>
146 {
147 public:
152  AbstractMetaObject(const std::string & class_name, const std::string & base_class_name)
153  : AbstractMetaObjectBase(class_name, base_class_name)
154  {
155  AbstractMetaObjectBase::typeid_base_class_name_ = std::string(typeid(B).name());
156  }
157 
162  virtual B * create() const = 0;
165 
166 private:
169  AbstractMetaObject & operator=(const AbstractMetaObject &);
170 };
171 
178 template<class C, class B>
180 {
181 public:
185  MetaObject(const std::string & class_name, const std::string & base_class_name)
186  : AbstractMetaObject<B>(class_name, base_class_name)
187  {
188  }
189 
194  B * create() const
195  {
196  return new C;
197  }
198 };
199 
200 } // namespace class_loader_private
201 } // namespace class_loader
202 
203 #endif // CLASS_LOADER__META_OBJECT_H_
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.h:194
The actual factory. C The derived class (the actual plugin) B The base class interface for the plug...
Definition: meta_object.h:179
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.h:57
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...
Definition: class_loader.h:64
MetaObject(const std::string &class_name, const std::string &base_class_name)
Constructor for the class.
Definition: meta_object.h:185
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.
Definition: meta_object.h:152
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.h:51
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...
Definition: meta_object.h:145
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 Thu Dec 7 2017 03:43:35