PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: LoadableType.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_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 loaders by using a loadable extension 00168 * 00169 * @param[in] sExtension 00170 * Extension of loadable 00171 * @param[out] lstLoaders 00172 * Receives the list of matching loaders (list is not cleared before new entries are added), there can be multiple candidates 00173 */ 00174 PLCORE_API void GetLoadersByExtension(const String &sExtension, Array<Loader*> &lstLoaders); 00175 00176 /** 00177 * @brief 00178 * Returns a loader for loading by using a loadable file 00179 * 00180 * @param[in] cFile 00181 * File to load from, must be opened and readable 00182 * 00183 * @return 00184 * The requested loader (first found if there are multiple candidates), a null pointer on error (format is not supported) 00185 */ 00186 PLCORE_API Loader *GetLoaderForLoadingByFile(File &cFile) const; 00187 00188 00189 //[-------------------------------------------------------] 00190 //[ Private functions ] 00191 //[-------------------------------------------------------] 00192 private: 00193 /** 00194 * @brief 00195 * Default constructor 00196 */ 00197 LoadableType(); 00198 00199 /** 00200 * @brief 00201 * Constructor 00202 * 00203 * @param[in] sName 00204 * Name of the loadable type 00205 * @param[in] cClass 00206 * Class the loadable type 00207 */ 00208 LoadableType(const String &sName, const Class &cClass); 00209 00210 /** 00211 * @brief 00212 * Destructor 00213 */ 00214 ~LoadableType(); 00215 00216 /** 00217 * @brief 00218 * Copy operator 00219 * 00220 * @param[in] cSource 00221 * Source to copy from 00222 * 00223 * @return 00224 * Reference to this instance 00225 */ 00226 LoadableType &operator =(const LoadableType &cSource); 00227 00228 /** 00229 * @brief 00230 * Adds a loader to this loadable type 00231 * 00232 * @param[in] cLoader 00233 * Loader to add, this loadable type takes over the memory control 00234 */ 00235 void AddLoader(Loader &cLoader); 00236 00237 /** 00238 * @brief 00239 * Removes a loader from this loadable type 00240 * 00241 * @param[in] cLoader 00242 * Loader to remove, when all went fine then the given reference is no longer valid after this method was successfully called 00243 * 00244 * @return 00245 * 'true' if all went fine, else 'false' 00246 */ 00247 bool RemoveLoader(Loader &cLoader); 00248 00249 00250 //[-------------------------------------------------------] 00251 //[ Private data ] 00252 //[-------------------------------------------------------] 00253 private: 00254 String m_sName; /**< Name of the loadable type */ 00255 const Class *m_pClass; /**< Class the loadable type, always valid! */ 00256 Array<Loader*> m_lstLoaders; /**< List of loaders */ 00257 HashMap<String, Loader*> m_mapLoaders; /**< Map of loaders (key = extension) */ 00258 Array<String> m_lstFormats; /**< List of loadable formats */ 00259 00260 00261 }; 00262 00263 00264 //[-------------------------------------------------------] 00265 //[ Namespace ] 00266 //[-------------------------------------------------------] 00267 } // PLCore 00268 00269 00270 //[-------------------------------------------------------] 00271 //[ Implementation ] 00272 //[-------------------------------------------------------] 00273 #include "PLCore/Tools/LoadableType.inl" 00274 00275 00276 #endif // __PLCORE_LOADABLETYPE_H__
|