• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

PolyVoxCore/include/PolyVoxCore/Array.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002 Copyright (c) 2005-2009 David Williams
00003 
00004 This software is provided 'as-is', without any express or implied
00005 warranty. In no event will the authors be held liable for any damages
00006 arising from the use of this software.
00007 
00008 Permission is granted to anyone to use this software for any purpose,
00009 including commercial applications, and to alter it and redistribute it
00010 freely, subject to the following restrictions:
00011 
00012     1. The origin of this software must not be misrepresented; you must not
00013     claim that you wrote the original software. If you use this software
00014     in a product, an acknowledgment in the product documentation would be
00015     appreciated but is not required.
00016 
00017     2. Altered source versions must be plainly marked as such, and must not be
00018     misrepresented as being the original software.
00019 
00020     3. This notice may not be removed or altered from any source
00021     distribution.
00022 *******************************************************************************/
00023 
00024 #ifndef __PolyVox_Array_H__
00025 #define __PolyVox_Array_H__
00026 
00027 #include "PolyVoxImpl/SubArray.h"
00028 
00029 #include "PolyVoxCore/ArraySizes.h" //Not strictly required, but convienient
00030 
00031 namespace PolyVox
00032 {
00075     template <uint32_t noOfDims, typename ElementType>
00076     class Array
00077     {
00078     public:
00080         Array<noOfDims, ElementType>();
00082         Array<noOfDims, ElementType>(const uint32_t (&pDimensions)[noOfDims]);
00084         ~Array<noOfDims, ElementType>();
00085 
00087         SubArray<noOfDims-1, ElementType> operator[](uint32_t uIndex);
00089         const SubArray<noOfDims-1, ElementType> operator[](uint32_t uIndex) const;
00090 
00092         uint32_t getNoOfElements(void) const;
00094         ElementType* getRawData(void) const;
00095 
00097         void resize(const uint32_t (&pDimensions)[noOfDims]);
00099         void swap(Array<noOfDims, ElementType>& rhs);
00101         uint32_t getDimension(uint32_t uDimension);
00102 
00103     private:
00104         Array<noOfDims, ElementType>(const Array<noOfDims, ElementType>& rhs);
00105 
00106         Array<noOfDims, ElementType>& operator=(const Array<noOfDims, ElementType>& rhs);
00107 
00108         void deallocate(void);
00109 
00110         uint32_t * m_pDimensions;
00111         uint32_t * m_pOffsets;
00112         uint32_t m_uNoOfElements;
00113         ElementType * m_pElements;
00114     };
00115 
00116     template <typename ElementType>
00117     class Array<1, ElementType>
00118     {
00119     public:
00120         Array<1, ElementType>();
00121 
00122         Array<1, ElementType>(const uint32_t (&pDimensions)[1]);
00123 
00124         ~Array<1, ElementType>();
00125 
00126         ElementType& operator[] (uint32_t uIndex);
00127 
00128         const ElementType& operator[] (uint32_t uIndex) const;
00129 
00130         uint32_t getNoOfElements(void) const;
00131 
00132         ElementType* getRawData(void) const;
00133 
00134         void resize(const uint32_t (&pDimensions)[1]);
00135 
00136         void swap(Array<1, ElementType>& rhs);
00137 
00138     private:
00139         Array<1, ElementType>(const Array<1, ElementType>& rhs);
00140 
00141         Array<1, ElementType>& operator=(const Array<1, ElementType>& rhs);
00142 
00143         void deallocate(void);
00144 
00145         uint32_t * m_pDimensions;
00146         ElementType * m_pElements;
00147     };
00148 
00149     template <typename ElementType>
00150     class Array<0, ElementType>
00151     {
00152         //Zero dimensional array is meaningless.
00153     };
00154 
00155     //Some handy typedefs
00157     typedef Array<1,float> Array1DFloat;
00159     typedef Array<1,double> Array1DDouble;
00161     typedef Array<1,int8_t> Array1DInt8;
00163     typedef Array<1,uint8_t> Array1DUint8;
00165     typedef Array<1,int16_t> Array1DInt16;
00167     typedef Array<1,uint16_t> Array1DUint16;
00169     typedef Array<1,int32_t> Array1DInt32;
00171     typedef Array<1,uint32_t> Array1DUint32;
00172 
00174     typedef Array<2,float> Array2DFloat;
00176     typedef Array<2,double> Array2DDouble;
00178     typedef Array<2,int8_t> Array2DInt8;
00180     typedef Array<2,uint8_t> Array2DUint8;
00182     typedef Array<2,int16_t> Array2DInt16;
00184     typedef Array<2,uint16_t> Array2DUint16;
00186     typedef Array<2,int32_t> Array2DInt32;
00188     typedef Array<2,uint32_t> Array2DUint32;
00189 
00191     typedef Array<3,float> Array3DFloat;
00193     typedef Array<3,double> Array3DDouble;
00195     typedef Array<3,int8_t> Array3DInt8;
00197     typedef Array<3,uint8_t> Array3DUint8;
00199     typedef Array<3,int16_t> Array3DInt16;
00201     typedef Array<3,uint16_t> Array3DUint16;
00203     typedef Array<3,int32_t> Array3DInt32;
00205     typedef Array<3,uint32_t> Array3DUint32;
00206 }//namespace PolyVox
00207 
00208 #include "PolyVoxCore/Array.inl"
00209 
00210 #endif

Generated on Sat Nov 19 2011 00:27:30 for PolyVox by  doxygen 1.7.1