Show DynamicLibrary.h syntax highlighted
#ifndef __DYNAMICLIBRARY__
#define __DYNAMICLIBRARY__ 1
#include <osg/Referenced>
#include <string>
#ifdef __APPLE__
#if !defined(MAC_OS_X_VERSION_10_3) || (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_3)
#define APPLE_PRE_10_3
#endif
#endif
#if defined(WIN32) && !defined(__CYGWIN__)
#elif defined(__APPLE__) && defined(APPLE_PRE_10_3)
#else // all other unix
#include <unistd.h>
#ifdef __hpux__
// Although HP-UX has dlopen() it is broken! We therefore need to stick
// to shl_load()/shl_unload()/shl_findsym()
#include <dl.h>
#include <errno.h>
#else
#include <dlfcn.h>
#endif
#endif
namespace osgDesigner
{
/** DynamicLibrary - encapsulates the loading and unloading of dynamic libraries,
typically used for loading ReaderWriter plug-ins.
*/
class DynamicLibrary : public osg::Referenced
{
public:
typedef void* HANDLE;
typedef void* PROC_ADDRESS;
enum ResolutionFlag
{
#if defined(WIN32) && !defined(__CYGWIN__)
DEFERRED = 0,
IMMEDIATE = 0
#elif defined(__APPLE__) && defined(APPLE_PRE_10_3)
DEFERRED = 0,
IMMEDIATE = 0
#elif defined(__hpux__)
DEFERRED = BIND_DEFERRED,
IMMEDIATE = BIND_IMMEDIATE
#else
DEFERRED = RTLD_LAZY,
IMMEDIATE = RTLD_NOW
#endif
};
enum ScopeFlag
{
#if defined(WIN32) && !defined(__CYGWIN__)
GLOBAL = 0,
LOCAL = 0
#elif defined(__APPLE__) && defined(APPLE_PRE_10_3)
GLOBAL = 0,
LOCAL = 0
#elif defined(__hpux__)
GLOBAL = 0,
LOCAL = 0
#else
GLOBAL = RTLD_GLOBAL,
LOCAL = RTLD_LOCAL
#endif
};
/** returns a pointer to a DynamicLibrary object on successfully
* opening of library returns NULL on failure.
*/
static DynamicLibrary* loadLibrary(const std::string& libraryName);
static DynamicLibrary* loadPlugin(const std::string& libraryName);
/** return name of library stripped of path.*/
const std::string& getName() const { return _name; }
/** return name of library including full path to it.*/
const std::string& getFullName() const { return _fullName; }
/** return handle to .dso/.dll dynamic library itself.*/
HANDLE getHandle() const { return _handle; }
/** return address of function located in library.*/
PROC_ADDRESS getProcAddress(const std::string& procName);
protected:
/** get handle to library file */
static HANDLE getLibraryHandle(const std::string& libraryName, ResolutionFlag rf, ScopeFlag sf);
/** disallow default constructor.*/
DynamicLibrary():osg::Referenced() {}
/** disallow copy constructor.*/
DynamicLibrary(const DynamicLibrary&):osg::Referenced() {}
/** disallow copy operator.*/
DynamicLibrary& operator = (const DynamicLibrary&) { return *this; }
/** Disallow public construction so that users have to go
* through loadLibrary() above which returns NULL on
* failure, a valid DynamicLibrary object on success.
*/
DynamicLibrary(const std::string& name,HANDLE handle);
~DynamicLibrary();
HANDLE _handle;
std::string _name;
std::string _fullName;
};
}
#endif // __DYNAMIC_LIBRARY_H
See more files for this project here