00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2012, Willow Garage, Inc. 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions are met: 00009 * 00010 * * Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * * Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in the 00014 * documentation and/or other materials provided with the distribution. 00015 * * Neither the name of the copyright holders nor the names of its 00016 * contributors may be used to endorse or promote products derived from 00017 * this software without specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00020 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00021 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00022 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00023 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00024 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00025 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00026 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00027 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00028 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00029 * POSSIBILITY OF SUCH DAMAGE. 00030 */ 00031 00032 // Note: This header defines a simplication of Poco::MetaObject 00033 // that allows us to tag MetaObjects with an associated library name. 00034 00035 #ifndef CLASS_LOADER__META_OBJECT_HPP_ 00036 #define CLASS_LOADER__META_OBJECT_HPP_ 00037 00038 #include <console_bridge/console.h> 00039 #include <typeinfo> 00040 #include <string> 00041 #include <vector> 00042 00043 #include "class_loader/console_bridge_compatibility.hpp" 00044 00045 namespace class_loader 00046 { 00047 00048 class ClassLoader; // Forward declaration 00049 00050 namespace class_loader_private 00051 { 00052 00053 typedef std::vector<class_loader::ClassLoader *> ClassLoaderVector; 00054 00059 class AbstractMetaObjectBase 00060 { 00061 public: 00065 AbstractMetaObjectBase(const std::string & class_name, const std::string & base_class_name); 00071 ~AbstractMetaObjectBase(); 00072 00077 std::string className() const; 00078 00082 std::string baseClassName() const; 00086 std::string typeidBaseClassName() const; 00087 00092 std::string getAssociatedLibraryPath(); 00093 00097 void setAssociatedLibraryPath(std::string library_path); 00098 00103 void addOwningClassLoader(ClassLoader * loader); 00104 00109 void removeOwningClassLoader(const ClassLoader * loader); 00110 00115 bool isOwnedBy(const ClassLoader * loader); 00116 00120 bool isOwnedByAnybody(); 00121 00125 ClassLoaderVector getAssociatedClassLoaders(); 00126 00127 protected: 00131 virtual void dummyMethod() {} 00132 00133 protected: 00134 ClassLoaderVector associated_class_loaders_; 00135 std::string associated_library_path_; 00136 std::string base_class_name_; 00137 std::string class_name_; 00138 std::string typeid_base_class_name_; 00139 }; 00140 00146 template<class B> 00147 class AbstractMetaObject : public AbstractMetaObjectBase 00148 { 00149 public: 00154 AbstractMetaObject(const std::string & class_name, const std::string & base_class_name) 00155 : AbstractMetaObjectBase(class_name, base_class_name) 00156 { 00157 AbstractMetaObjectBase::typeid_base_class_name_ = std::string(typeid(B).name()); 00158 } 00159 00164 virtual B * create() const = 0; 00167 00168 private: 00169 AbstractMetaObject(); 00170 AbstractMetaObject(const AbstractMetaObject &); 00171 AbstractMetaObject & operator=(const AbstractMetaObject &); 00172 }; 00173 00180 template<class C, class B> 00181 class MetaObject : public AbstractMetaObject<B> 00182 { 00183 public: 00187 MetaObject(const std::string & class_name, const std::string & base_class_name) 00188 : AbstractMetaObject<B>(class_name, base_class_name) 00189 { 00190 } 00191 00196 B * create() const 00197 { 00198 return new C; 00199 } 00200 }; 00201 00202 } // namespace class_loader_private 00203 } // namespace class_loader 00204 00205 #endif // CLASS_LOADER__META_OBJECT_HPP_