PixelLightAPI  .
LoadableType.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: LoadableType.h                                 *
00003  *
00004  *  Copyright (C) 2002-2011 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_LOADABLETYPE_H__
00024 #define __PLCORE_LOADABLETYPE_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include "PLCore/String/String.h"
00032 #include "PLCore/Container/Array.h"
00033 #include "PLCore/Container/HashMap.h"
00034 
00035 
00036 //[-------------------------------------------------------]
00037 //[ Namespace                                             ]
00038 //[-------------------------------------------------------]
00039 namespace PLCore {
00040 
00041 
00042 //[-------------------------------------------------------]
00043 //[ Forward declarations                                  ]
00044 //[-------------------------------------------------------]
00045 class File;
00046 class Class;
00047 class Loader;
00048 
00049 
00050 //[-------------------------------------------------------]
00051 //[ Classes                                               ]
00052 //[-------------------------------------------------------]
00053 /**
00054 *  @brief
00055 *    Class describing a loadable type
00056 *
00057 *  @remarks
00058 *    This is used for managing search paths and loadable formats for a loadable type.
00059 */
00060 class LoadableType {
00061 
00062 
00063     //[-------------------------------------------------------]
00064     //[ Friends                                               ]
00065     //[-------------------------------------------------------]
00066     friend class LoadableManager;
00067 
00068 
00069     //[-------------------------------------------------------]
00070     //[ Public functions                                      ]
00071     //[-------------------------------------------------------]
00072     public:
00073         /**
00074         *  @brief
00075         *    Returns the name of the loadable type
00076         *
00077         *  @return
00078         *    Name of the loadable type
00079         */
00080         inline String GetName() const;
00081 
00082         /**
00083         *  @brief
00084         *    Returns the class of the loadable type
00085         *
00086         *  @return
00087         *    Class of the loadable type
00088         */
00089         inline const Class &GetClass() const;
00090 
00091         /**
00092         *  @brief
00093         *    Gets the relative version of an absolute file path
00094         *
00095         *  @param[in] sPath
00096         *    Absolute file path to get the relative version from
00097         *
00098         *  @return
00099         *    Relative file path, empty string on error
00100         *
00101         *  @note
00102         *    - The function will take the FS base directories into account, the first match
00103         *      will be used
00104         *    - MS Windows example: 'C:\test\test.bmp' -> 'test.bmp'
00105         */
00106         PLCORE_API String GetRelativeFilePath(const String &sPath) const;
00107 
00108         //[-------------------------------------------------------]
00109         //[ Formats & loaders                                     ]
00110         //[-------------------------------------------------------]
00111         /**
00112         *  @brief
00113         *    Returns the number of supported formats
00114         *
00115         *  @return
00116         *    The number of supported formats
00117         */
00118         inline uint32 GetNumOfFormats() const;
00119 
00120         /**
00121         *  @brief
00122         *    Returns a supported formats
00123         *
00124         *  @param[in] nIndex
00125         *    Format index
00126         *
00127         *  @return
00128         *    The requested supported format, empty string on error
00129         */
00130         inline String GetFormat(uint32 nIndex) const;
00131 
00132         /**
00133         *  @brief
00134         *    Returns the number of loaders
00135         *
00136         *  @return
00137         *    The number of loaders
00138         */
00139         inline uint32 GetNumOfLoaders() const;
00140 
00141         /**
00142         *  @brief
00143         *    Returns a loader by using an index
00144         *
00145         *  @param[in] nIndex
00146         *    Loader index
00147         *
00148         *  @return
00149         *    The requested loader, a null pointer on error
00150         */
00151         inline Loader *GetLoaderByIndex(uint32 nIndex) const;
00152 
00153         /**
00154         *  @brief
00155         *    Returns a loader by using a loadable extension
00156         *
00157         *  @param[in] sExtension
00158         *    Extension of loader
00159         *
00160         *  @return
00161         *    The requested loader (first found if there are multiple candidates), a null pointer on error (format is not supported)
00162         */
00163         inline Loader *GetLoaderByExtension(const String &sExtension) const;
00164 
00165         /**
00166         *  @brief
00167         *    Returns a loader for loading by using a loadable file
00168         *
00169         *  @param[in] cFile
00170         *    File to load from, must be opened and readable
00171         *
00172         *  @return
00173         *    The requested loader (first found if there are multiple candidates), a null pointer on error (format is not supported)
00174         */
00175         PLCORE_API Loader *GetLoaderForLoadingByFile(File &cFile) const;
00176 
00177 
00178     //[-------------------------------------------------------]
00179     //[ Private functions                                     ]
00180     //[-------------------------------------------------------]
00181     private:
00182         /**
00183         *  @brief
00184         *    Default constructor
00185         */
00186         LoadableType();
00187 
00188         /**
00189         *  @brief
00190         *    Constructor
00191         *
00192         *  @param[in] sName
00193         *    Name of the loadable type
00194         *  @param[in] cClass
00195         *    Class the loadable type
00196         */
00197         LoadableType(const String &sName, const Class &cClass);
00198 
00199         /**
00200         *  @brief
00201         *    Destructor
00202         */
00203         ~LoadableType();
00204 
00205         /**
00206         *  @brief
00207         *    Copy operator
00208         *
00209         *  @param[in] cSource
00210         *    Source to copy from
00211         *
00212         *  @return
00213         *    Reference to this instance
00214         */
00215         LoadableType &operator =(const LoadableType &cSource);
00216 
00217         /**
00218         *  @brief
00219         *    Adds loader to this loadable type
00220         *
00221         *  @param[in] cLoader
00222         *    Loader to add
00223         */
00224         void AddLoader(Loader &cLoader);
00225 
00226 
00227     //[-------------------------------------------------------]
00228     //[ Private data                                          ]
00229     //[-------------------------------------------------------]
00230     private:
00231         String                       m_sName;       /**< Name of the loadable type */
00232         const Class                 *m_pClass;      /**< Class the loadable type, always valid! */
00233         Array<Loader*>               m_lstLoaders;  /**< List of loaders */
00234         HashMap<String, Loader*>     m_mapLoaders;  /**< Map of loaders (key = extension) */
00235         Array<String>                m_lstFormats;  /**< List of loadable formats */
00236 
00237 
00238 };
00239 
00240 
00241 //[-------------------------------------------------------]
00242 //[ Namespace                                             ]
00243 //[-------------------------------------------------------]
00244 } // PLCore
00245 
00246 
00247 //[-------------------------------------------------------]
00248 //[ Implementation                                        ]
00249 //[-------------------------------------------------------]
00250 #include "PLCore/Tools/LoadableType.inl"
00251 
00252 
00253 #endif // __PLCORE_LOADABLETYPE_H__


PixelLight PixelLight 0.9.10-R1
Copyright (C) 2002-2011 by The PixelLight Team
Last modified Fri Dec 23 2011 15:50:57
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported