PluginLoader.h++

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------
00002    commonc++ - A C++ Common Class Library
00003    Copyright (C) 2005-2012  Mark A Lindner
00004 
00005    This file is part of commonc++.
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public
00018    License along with this library; if not, write to the Free
00019    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00020    ---------------------------------------------------------------------------
00021 */
00022 
00023 #ifndef __ccxx_PluginLoader_hxx
00024 #define __ccxx_PluginLoader_hxx
00025 
00026 #include <commonc++/LoadableModule.h++>
00027 
00028 namespace ccxx {
00029 
00030 class COMMONCPP_API Plugin;
00031 
00038 class COMMONCPP_API PluginLoader
00039 {
00040   public:
00041 
00047   PluginLoader(const String& path = String::null);
00048 
00050   ~PluginLoader();
00051 
00055   inline void setPath(const String& path)
00056   { _module.setPath(path); }
00057 
00059   inline String getPath() const
00060   { return(_module.getPath()); }
00061 
00068   void load() throw(IOException)
00069   { _module.open(); }
00070 
00074   inline void unload() throw()
00075   { _module.close(); }
00076 
00078   inline bool isLoaded() const
00079   { return(_module.isOpen()); }
00080 
00087   String getName();
00088 
00095   String getVersion();
00096 
00103   String getAuthor();
00104 
00111   String getClassName();
00112 
00119   String getBuildDate();
00120 
00128   template<class T> T *newInstance()
00129   {
00130     Plugin *p;
00131     try
00132     {
00133       p = _newInstance();
00134     }
00135     catch(...) { }
00136 
00137     if(! p)
00138       return(NULL);
00139 
00140     T* plugin = NULL;
00141     plugin = dynamic_cast<T *>(p);
00142     if(! plugin)
00143       delete p;
00144 
00145     return plugin;
00146   }
00147 
00148   private:
00149 
00150   String _fetchString(const char *symbol);
00151   Plugin *_newInstance();
00152 
00153   LoadableModule _module;
00154 
00155   CCXX_COPY_DECLS(PluginLoader);
00156 };
00157 
00158 } // namespace ccxx
00159 
00160 #endif // __ccxx_PluginLoader_hxx
00161 
00162 /* end of header file */
Generated on Sat Nov 26 16:49:07 2011 for libcommonc++ by  doxygen 1.6.3