PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: Loadable.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_LOADABLE_H__ 00024 #define __PLCORE_LOADABLE_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include "PLCore/String/String.h" 00032 00033 00034 //[-------------------------------------------------------] 00035 //[ Namespace ] 00036 //[-------------------------------------------------------] 00037 namespace PLCore { 00038 00039 00040 //[-------------------------------------------------------] 00041 //[ Forward declarations ] 00042 //[-------------------------------------------------------] 00043 class File; 00044 class Loader; 00045 class Parameters; 00046 00047 00048 //[-------------------------------------------------------] 00049 //[ Classes ] 00050 //[-------------------------------------------------------] 00051 /** 00052 * @brief 00053 * Abstract loadable (serialization) base class, derive your loadable classes from this class 00054 * 00055 * @note 00056 * - If your loadable has special parameters for loading/saving don't forget to document it within your class! 00057 */ 00058 class Loadable { 00059 00060 00061 //[-------------------------------------------------------] 00062 //[ Public functions ] 00063 //[-------------------------------------------------------] 00064 public: 00065 /** 00066 * @brief 00067 * Returns the filename this loadable was given to loaded from 00068 * 00069 * @return 00070 * The filename this loadable was given to loaded from 00071 */ 00072 inline String GetFilename() const; 00073 00074 /** 00075 * @brief 00076 * Returns the absolute filename this loadable was loaded from 00077 * 00078 * @return 00079 * The absolute filename this loadable was loaded from 00080 */ 00081 inline String GetUrl() const; 00082 00083 00084 //[-------------------------------------------------------] 00085 //[ Public virtual Loadable functions ] 00086 //[-------------------------------------------------------] 00087 public: 00088 /** 00089 * @brief 00090 * Loads the loadable from a file given by filename 00091 * 00092 * @param[in] sFilename 00093 * Loadable filename 00094 * @param[in] sParams 00095 * Optional load method parameters, can be an empty string 00096 * @param[in] sMethod 00097 * Optional name of the load method to use, can be an empty string 00098 * 00099 * @return 00100 * 'true' if all went fine, else 'false' 00101 * 00102 * @note 00103 * - If no method name was provided, 'Load' if sParams is empty, or 'LoadParams' if sParams is not empty is used automatically 00104 */ 00105 PLCORE_API virtual bool LoadByFilename(const String &sFilename, const String &sParams = "", const String &sMethod = ""); 00106 00107 /** 00108 * @brief 00109 * Loads the loadable from a file given by a reference 00110 * 00111 * @param[in] cFile 00112 * File to load from, must be opened and readable 00113 * @param[in] sParams 00114 * Optional load method parameters, can be an empty string 00115 * @param[in] sMethod 00116 * Optional name of the load method to use, can be an empty string 00117 * 00118 * @return 00119 * 'true' if all went fine, else 'false' 00120 * 00121 * @note 00122 * - If no method name was provided, 'Load' if sParams is empty, or 'LoadParams' if sParams is not empty is used automatically 00123 */ 00124 PLCORE_API virtual bool LoadByFile(File &cFile, const String &sParams = "", const String &sMethod = ""); 00125 00126 /** 00127 * @brief 00128 * Saves the loadable to a file given by filename 00129 * 00130 * @param[in] sFilename 00131 * Loadable filename 00132 * @param[in] sParams 00133 * Optional save method parameters, can be an empty string 00134 * @param[in] sMethod 00135 * Optional name of the save method to use, can be an empty string 00136 * 00137 * @return 00138 * 'true' if all went fine, else 'false' 00139 * 00140 * @note 00141 * - If no method name was provided, 'Save' if sParams is empty, or 'SaveParams' if sParams is not empty is used automatically 00142 */ 00143 PLCORE_API virtual bool SaveByFilename(const String &sFilename, const String &sParams = "", const String &sMethod = ""); 00144 00145 /** 00146 * @brief 00147 * Saves the loadable to a file given by reference 00148 * 00149 * @param[in] cFile 00150 * File to save into, must be opened and writable 00151 * @param[in] sParams 00152 * Optional save method parameters, can be an empty string 00153 * @param[in] sMethod 00154 * Optional name of the save method to use, can be an empty string 00155 * 00156 * @return 00157 * 'true' if all went fine, else 'false' 00158 * 00159 * @note 00160 * - If no method name was provided, 'Save' if sParams is empty, or 'SaveParams' if sParams is not empty is used automatically 00161 */ 00162 PLCORE_API virtual bool SaveByFile(File &cFile, const String &sParams = "", const String &sMethod = ""); 00163 00164 /** 00165 * @brief 00166 * Reloads the loadable 00167 * 00168 * @return 00169 * 'true' if all went fine, else 'false' (maybe there's nothing loaded?) 00170 * 00171 * @note 00172 * - Same as pLoadable->Load(pLoadable->GetAbsFilename()) 00173 */ 00174 PLCORE_API virtual bool Reload(); 00175 00176 /** 00177 * @brief 00178 * Unloads the loadable 00179 * 00180 * @return 00181 * 'true' if all went fine, else 'false' 00182 */ 00183 PLCORE_API virtual bool Unload(); 00184 00185 /** 00186 * @brief 00187 * Returns the loadable type name 00188 * 00189 * @return 00190 * The loadable type name 00191 */ 00192 PLCORE_API virtual String GetLoadableTypeName() const; 00193 00194 00195 //[-------------------------------------------------------] 00196 //[ Protected functions ] 00197 //[-------------------------------------------------------] 00198 protected: 00199 /** 00200 * @brief 00201 * Constructor 00202 */ 00203 PLCORE_API Loadable(); 00204 00205 /** 00206 * @brief 00207 * Destructor 00208 */ 00209 PLCORE_API virtual ~Loadable(); 00210 00211 00212 //[-------------------------------------------------------] 00213 //[ Protected virtual Loadable functions ] 00214 //[-------------------------------------------------------] 00215 protected: 00216 /** 00217 * @brief 00218 * Calls the loadable in order to load or save 00219 * 00220 * @param[in] cFile 00221 * File to load from, MUST be opened 00222 * @param[in] cLoader 00223 * Loader to use 00224 * @param[in] sMethod 00225 * Name of the method to use 00226 * @param[in] sParams 00227 * Method parameters 00228 * 00229 * @return 00230 * 'true' if all went fine, else 'false' 00231 * 00232 * @note 00233 * - The default implementation is empty and will return always 'false' 00234 */ 00235 PLCORE_API virtual bool CallLoadable(File &cFile, Loader &cLoader, const String &sMethod, const String &sParams); 00236 00237 00238 //[-------------------------------------------------------] 00239 //[ Protected data ] 00240 //[-------------------------------------------------------] 00241 protected: 00242 String m_sFilename; /**< The filename this loadable was given to loaded from */ 00243 String m_sUrl; /**< The absolute filename this loadable was loaded from */ 00244 00245 00246 }; 00247 00248 00249 //[-------------------------------------------------------] 00250 //[ Namespace ] 00251 //[-------------------------------------------------------] 00252 } // PLCore 00253 00254 00255 //[-------------------------------------------------------] 00256 //[ Implementation ] 00257 //[-------------------------------------------------------] 00258 #include "PLCore/Tools/Loadable.inl" 00259 00260 00261 #endif // __PLCORE_LOADABLE_H__
|