DynamicLibrary 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
  2. *
  3. * This library is open source and may be redistributed and/or modified under
  4. * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
  5. * (at your option) any later version. The full license is in LICENSE file
  6. * included with this distribution, and on the openscenegraph.org website.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * OpenSceneGraph Public License for more details.
  12. */
  13. #ifndef OSGDB_DYNAMICLIBRARY
  14. #define OSGDB_DYNAMICLIBRARY 1
  15. #include <osg/Referenced>
  16. #include <osgDB/Export>
  17. #include <string>
  18. namespace osgDB {
  19. /** DynamicLibrary - encapsulates the loading and unloading of dynamic libraries,
  20. typically used for loading ReaderWriter plug-ins.
  21. */
  22. class OSGDB_EXPORT DynamicLibrary : public osg::Referenced
  23. {
  24. public:
  25. typedef void* HANDLE;
  26. typedef void* PROC_ADDRESS;
  27. /** returns a pointer to a DynamicLibrary object on successfully
  28. * opening of library returns NULL on failure.
  29. */
  30. static DynamicLibrary* loadLibrary(const std::string& libraryName);
  31. /** return name of library stripped of path.*/
  32. const std::string& getName() const { return _name; }
  33. /** return name of library including full path to it.*/
  34. const std::string& getFullName() const { return _fullName; }
  35. /** return handle to .dso/.dll dynamic library itself.*/
  36. HANDLE getHandle() const { return _handle; }
  37. /** return address of function located in library.*/
  38. PROC_ADDRESS getProcAddress(const std::string& procName);
  39. protected:
  40. /** get handle to library file */
  41. static HANDLE getLibraryHandle( const std::string& libraryName);
  42. /** disallow default constructor.*/
  43. DynamicLibrary():osg::Referenced() {}
  44. /** disallow copy constructor.*/
  45. DynamicLibrary(const DynamicLibrary&):osg::Referenced() {}
  46. /** disallow copy operator.*/
  47. DynamicLibrary& operator = (const DynamicLibrary&) { return *this; }
  48. /** Disallow public construction so that users have to go
  49. * through loadLibrary() above which returns NULL on
  50. * failure, a valid DynamicLibrary object on success.
  51. */
  52. DynamicLibrary(const std::string& name,HANDLE handle);
  53. ~DynamicLibrary();
  54. HANDLE _handle;
  55. std::string _name;
  56. std::string _fullName;
  57. };
  58. }
  59. #endif // __DYNAMIC_LIBRARY_H