PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: Chunk.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_CHUNK_H__ 00024 #define __PLCORE_CHUNK_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include "PLCore/Tools/Loadable.h" 00032 00033 00034 //[-------------------------------------------------------] 00035 //[ Namespace ] 00036 //[-------------------------------------------------------] 00037 namespace PLCore { 00038 00039 00040 //[-------------------------------------------------------] 00041 //[ Classes ] 00042 //[-------------------------------------------------------] 00043 /** 00044 * @brief 00045 * Chunk of data - one may also call it BLOB (binary large object) 00046 * 00047 * @remarks 00048 * This class encapsulates a chunk of data in a quite primitive way. The semantic of the chunk data can be provided, but 00049 * it's no requirement. A chunk consists of a bunch of elements, were each element consists of at least one component and 00050 * all components of all elements have the same data type. A chunk can for example be used to store keyframed positions for 00051 * animation purposes. 00052 */ 00053 class Chunk : public Loadable { 00054 00055 00056 //[-------------------------------------------------------] 00057 //[ Public definitions ] 00058 //[-------------------------------------------------------] 00059 public: 00060 /** 00061 * @brief 00062 * Semantic 00063 */ 00064 enum ESemantic { 00065 Unknown = 0, /**< Unknown */ 00066 Position = 1, /**< Position */ 00067 Rotation = 2, /**< Rotation */ 00068 Scale = 3 /**< Scale */ 00069 }; 00070 00071 /** 00072 * @brief 00073 * Element type 00074 */ 00075 enum EElementType { 00076 Int8 = 0, /**< Int8 */ 00077 Int16 = 1, /**< Int16 */ 00078 Int32 = 2, /**< Int32 */ 00079 UInt8 = 3, /**< UInt8 */ 00080 UInt16 = 4, /**< UInt16 */ 00081 UInt32 = 5, /**< UInt32 */ 00082 Float = 6, /**< Float */ 00083 Double = 7 /**< Double */ 00084 }; 00085 00086 00087 //[-------------------------------------------------------] 00088 //[ Public functions ] 00089 //[-------------------------------------------------------] 00090 public: 00091 /** 00092 * @brief 00093 * Constructor 00094 */ 00095 PLCORE_API Chunk(); 00096 00097 /** 00098 * @brief 00099 * Destructor 00100 */ 00101 PLCORE_API virtual ~Chunk(); 00102 00103 /** 00104 * @brief 00105 * Returns the semantic 00106 * 00107 * @return 00108 * The semantic 00109 */ 00110 inline ESemantic GetSemantic() const; 00111 00112 /** 00113 * @brief 00114 * Sets the semantic 00115 * 00116 * @param[in] nSemantic 00117 * The semantic 00118 */ 00119 inline void SetSemantic(ESemantic nSemantic); 00120 00121 /** 00122 * @brief 00123 * Allocates the chunk 00124 * 00125 * @param[in] nElementType 00126 * The element type 00127 * @param[in] nNumOfComponentsPerElement 00128 * The number of components per element 00129 * @param[in] nNumOfElements 00130 * The number of elements 00131 * 00132 * @return 00133 * 'true' if all went fine, else 'false' 00134 */ 00135 PLCORE_API bool Allocate(EElementType nElementType, uint32 nNumOfComponentsPerElement, uint32 nNumOfElements); 00136 00137 /** 00138 * @brief 00139 * Returns the chunk data 00140 * 00141 * @return 00142 * The chunk data, can be a null pointer - do NOT delete this memory! 00143 */ 00144 inline uint8 *GetData(); 00145 00146 /** 00147 * @brief 00148 * Returns the chunk data 00149 * 00150 * @return 00151 * The chunk data, can be a null pointer - do NOT delete this memory! 00152 */ 00153 inline const uint8 *GetData() const; 00154 00155 /** 00156 * @brief 00157 * Returns the chunk element component data 00158 * 00159 * @param[in] nElement 00160 * Element index to return the component data from (0 - GetNumOfElements()-1), must be valid! 00161 * @param[in] nComponent 00162 * Index of the element component to data from (0 - GetNumOfComponentsPerElement()-1), must be valid! 00163 * 00164 * @return 00165 * The chunk element component data, can be a null pointer - do NOT delete this memory! 00166 */ 00167 inline uint8 *GetElementComponentData(uint32 nElement, uint32 nComponent); 00168 00169 /** 00170 * @brief 00171 * Returns the chunk element component data 00172 * 00173 * @param[in] nElement 00174 * Element index to return the component data from (0 - GetNumOfElements()-1), must be valid! 00175 * @param[in] nComponent 00176 * Index of the element component to data from (0 - GetNumOfComponentsPerElement()-1), must be valid! 00177 * 00178 * @return 00179 * The chunk element component data, can be a null pointer - do NOT delete this memory! 00180 */ 00181 inline const uint8 *GetElementComponentData(uint32 nElement, uint32 nComponent) const; 00182 00183 /** 00184 * @brief 00185 * Clears the chunk 00186 */ 00187 PLCORE_API void Clear(); 00188 00189 /** 00190 * @brief 00191 * Returns the element type 00192 * 00193 * @return 00194 * The element type 00195 */ 00196 inline EElementType GetElementType() const; 00197 00198 /** 00199 * @brief 00200 * Returns the number of components per element 00201 * 00202 * @return 00203 * The number of components per element 00204 */ 00205 inline uint32 GetNumOfComponentsPerElement() const; 00206 00207 /** 00208 * @brief 00209 * Returns the number of elements 00210 * 00211 * @return 00212 * The number of elements 00213 */ 00214 inline uint32 GetNumOfElements() const; 00215 00216 /** 00217 * @brief 00218 * Returns the number of bytes per component of an element 00219 * 00220 * @return 00221 * The number of bytes per component of an element 00222 */ 00223 PLCORE_API uint32 GetNumOfBytesPerElementComponent() const; 00224 00225 /** 00226 * @brief 00227 * Returns the number of bytes per element 00228 * 00229 * @return 00230 * The number of bytes per element 00231 */ 00232 inline uint32 GetNumOfBytesPerElement() const; 00233 00234 /** 00235 * @brief 00236 * Returns the total number of bytes of the chunk data 00237 * 00238 * @return 00239 * The total number of bytes of the chunk data 00240 */ 00241 inline uint32 GetTotalNumOfBytes() const; 00242 00243 /** 00244 * @brief 00245 * Returns the total number of components (all elements summed up) within the chunk 00246 * 00247 * @return 00248 * The total number of components within the chunk 00249 */ 00250 inline uint32 GetTotalNumOfComponents() const; 00251 00252 00253 //[-------------------------------------------------------] 00254 //[ Private functions ] 00255 //[-------------------------------------------------------] 00256 private: 00257 /** 00258 * @brief 00259 * Copy constructor 00260 * 00261 * @param[in] cSource 00262 * Source to copy from 00263 */ 00264 Chunk(const Chunk &cSource); 00265 00266 /** 00267 * @brief 00268 * Copy operator 00269 * 00270 * @param[in] cSource 00271 * Source to copy from 00272 * 00273 * @return 00274 * Reference to this instance 00275 */ 00276 Chunk &operator =(const Chunk &cSource); 00277 00278 00279 //[-------------------------------------------------------] 00280 //[ Private data ] 00281 //[-------------------------------------------------------] 00282 private: 00283 ESemantic m_nSemantic; /**< Semantic */ 00284 EElementType m_nElementType; /**< Element type */ 00285 uint32 m_nNumOfComponentsPerElement; /**< Number of components per element */ 00286 uint32 m_nNumOfElements; /**< Number of elements */ 00287 uint8 *m_pData; /**< The data, can be a null pointer */ 00288 00289 00290 //[-------------------------------------------------------] 00291 //[ Public virtual Loadable functions ] 00292 //[-------------------------------------------------------] 00293 public: 00294 PLCORE_API virtual bool Unload() override; 00295 PLCORE_API virtual String GetLoadableTypeName() const override; 00296 00297 00298 }; 00299 00300 00301 //[-------------------------------------------------------] 00302 //[ Namespace ] 00303 //[-------------------------------------------------------] 00304 } // PLCore 00305 00306 00307 //[-------------------------------------------------------] 00308 //[ Implementation ] 00309 //[-------------------------------------------------------] 00310 #include "PLCore/Tools/Chunk.inl" 00311 00312 00313 #endif // __PLCORE_CHUNK_H__
|