library.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2008 by Kutumov Alexey                                  *
00003  *   ru.pixel@gmail.com                                                    *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00035 #ifndef __library__header__
00036 #define __library__header__
00037 
00038 #include "gpucalc/object.h"
00039 
00040 #if PLATFORM == PLATFORM_LINUX
00041 
00042 #define LIBRARY_HANDLE void *
00043 #define LIBRARY_LOAD(a) dlopen(a, RTLD_LAZY | RTLD_GLOBAL)
00044 #define LIBRARY_GETSYM(a, b) dlsym(a, b)
00045 #define LIBRARY_UNLOAD(a) dlclose(a)
00046 
00047 #elif PLATFORM == PLATFORM_WIN32
00048 
00049 #define LIBRARY_HANDLE hInstance
00050 #define LIBRARY_LOAD( a ) LoadLibraryA( a )
00051 #define LIBRARY_GETSYM( a, b ) GetProcAddress( a, b )
00052 #define LIBRARY_UNLOAD( a ) !FreeLibrary( a )
00053 
00054 struct HINSTANCE__;
00055 typedef struct HINSTANCE__* hInstance;
00056 
00057 #elif PLATFORM == PLATFORM_APPLE
00058 
00059 #define LIBRARY_HANDLE CFBundleRef
00060 #define LIBRARY_LOAD( a ) mac_loadExeBundle( a )
00061 #define LIBRARY_GETSYM( a, b ) mac_getBundleSym( a, b )
00062 #define LIBRARY_UNLOAD( a ) mac_unloadExeBundle( a )
00063 
00064 #endif
00065 
00066 namespace gpucalc
00067 {
00068 
00069 
00070  const char _LibraryClassName [] = "Library";
00071 
00072 
00078  class _GpuCalcExport Library: public Object
00079  {
00080 
00081 
00082   OBJ_DISABLE_COPY(Library)
00083   
00084   
00085   public:
00091    Library(const std::string & LibraryName):
00092     Object(_LibraryClassName, LibraryName), mhInst(0), mIsLoaded(false)
00093    {
00094    }
00095 
00096 
00097    ~Library()
00098    {
00099     if (mIsLoaded)
00100     {
00101      unload();
00102     }
00103    }
00104 
00105 
00111    void load();
00112 
00113 
00119    void unload();
00120 
00121 
00122    bool isLoaded() const
00123    {
00124     return mIsLoaded;
00125    }
00126 
00127 
00133    LIBRARY_HANDLE getSymbol(const std::string & SymbolName) const;
00134 
00135   
00136   private:
00137    LIBRARY_HANDLE mhInst;
00138 
00139 
00140    std::string libraryError() const;
00141 
00142 
00143    bool mIsLoaded;
00144  };
00145 }
00146 
00147 #endif

Generated on Thu Mar 5 22:36:42 2009 for gpucalc by  doxygen 1.5.6