PixelLightAPI  .
DynLib.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: DynLib.h                                       *
00003  *
00004  *  Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLCORE_DYNLIB_H__
00024 #define __PLCORE_DYNLIB_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include "PLCore/File/Url.h"
00032 
00033 
00034 //[-------------------------------------------------------]
00035 //[ Namespace                                             ]
00036 //[-------------------------------------------------------]
00037 namespace PLCore {
00038 
00039 
00040 //[-------------------------------------------------------]
00041 //[ Forward declarations                                  ]
00042 //[-------------------------------------------------------]
00043 class DynLibImpl;
00044 
00045 
00046 //[-------------------------------------------------------]
00047 //[ Classes                                               ]
00048 //[-------------------------------------------------------]
00049 /**
00050 *  @brief
00051 *    Dynamic library (aka "shared library") class
00052 *
00053 *  @note
00054 *    - Implementation of the bridge design pattern, this class is the abstraction
00055 */
00056 class DynLib {
00057 
00058 
00059     //[-------------------------------------------------------]
00060     //[ Public functions                                      ]
00061     //[-------------------------------------------------------]
00062     public:
00063         /**
00064         *  @brief
00065         *    Constructor
00066         */
00067         PLCORE_API DynLib();
00068 
00069         /**
00070         *  @brief
00071         *    Destructor
00072         *
00073         *  @note
00074         *    - The dynamic library is unloaded automatically
00075         */
00076         PLCORE_API ~DynLib();
00077 
00078         /**
00079         *  @brief
00080         *    Loads a dynamic library
00081         *
00082         *  @param[in] sPath
00083         *    Path to the dynamic library
00084         *
00085         *  @return
00086         *    'true' if the library could be loaded, else 'false'
00087         *
00088         *  @note
00089         *    - Dependent dynamic libraries are first searched within the same path as the given one
00090         *    - If the library has already been loaded, this function will fail
00091         */
00092         inline bool Load(const String &sPath);
00093 
00094         /**
00095         *  @brief
00096         *    Returns if the dynamic library has been loaded
00097         *
00098         *  @return
00099         *    'true' if loaded, else 'false'
00100         */
00101         inline bool IsLoaded() const;
00102 
00103         /**
00104         *  @brief
00105         *    Get the path (set within 'Load()') to the dynamic library
00106         *
00107         *  @return
00108         *    The path to the dynamic library (e.g. "file://C:/PixelLight/Runtime/x86/PLCore.dll" on Windows)
00109         */
00110         inline String GetPath() const;
00111 
00112         /**
00113         *  @brief
00114         *    Get the absolute path to the dynamic library
00115         *
00116         *  @return
00117         *    The absolute path to the dynamic library (native path style, e.g. "C:\PixelLight\Runtime\x86\PLCore.dll" on Windows)
00118         */
00119         inline String GetAbsPath() const;
00120 
00121         /**
00122         *  @brief
00123         *    Returns a pointer to a symbol in the library
00124         *
00125         *  @param[in] sSymbol
00126         *    Name of the symbol to retrieve
00127         *
00128         *  @return
00129         *    Pointer to the symbol, or a null pointer on error
00130         *
00131         *  @note
00132         *    - The pointer to the symbol only stays valid as long as this dynamic library instance is not unloaded
00133         */
00134         inline void *GetSymbol(const String &sSymbol) const;
00135 
00136         /**
00137         *  @brief
00138         *    Unloads the dynamic library
00139         *
00140         *  @return
00141         *    'true' if the library could be unloaded, else false
00142         */
00143         inline bool Unload();
00144 
00145 
00146     //[-------------------------------------------------------]
00147     //[ Private functions                                     ]
00148     //[-------------------------------------------------------]
00149     private:
00150         /**
00151         *  @brief
00152         *    Copy constructor
00153         *
00154         *  @param[in] cSource
00155         *    Source to copy from
00156         */
00157         DynLib(const DynLib &cSource);
00158 
00159         /**
00160         *  @brief
00161         *    Copy operator
00162         *
00163         *  @param[in] cSource
00164         *    Source to copy from
00165         *
00166         *  @return
00167         *    Reference to this instance
00168         */
00169         DynLib &operator =(const DynLib &cSource);
00170 
00171 
00172     //[-------------------------------------------------------]
00173     //[ Private data                                          ]
00174     //[-------------------------------------------------------]
00175     private:
00176         DynLibImpl *m_pDynLibImpl;  /**< Pointer to the system specific implementation (assumed to be never a null pointer!) */
00177         Url         m_cUrl;         /**< Url to the dynamic library */
00178 
00179 
00180 };
00181 
00182 
00183 //[-------------------------------------------------------]
00184 //[ Namespace                                             ]
00185 //[-------------------------------------------------------]
00186 } // PLCore
00187 
00188 
00189 //[-------------------------------------------------------]
00190 //[ Implementation                                        ]
00191 //[-------------------------------------------------------]
00192 #include "PLCore/System/DynLib.inl"
00193 
00194 
00195 #endif // __PLCORE_DYNLIB_H__


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:08:52
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported