PolyVox  0.2.1
Open source voxel management library
Array.h
Go to the documentation of this file.
1 /*******************************************************************************
2 Copyright (c) 2005-2009 David Williams
3 
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
7 
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
10 freely, subject to the following restrictions:
11 
12  1. The origin of this software must not be misrepresented; you must not
13  claim that you wrote the original software. If you use this software
14  in a product, an acknowledgment in the product documentation would be
15  appreciated but is not required.
16 
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19 
20  3. This notice may not be removed or altered from any source
21  distribution.
22 *******************************************************************************/
23 
24 #ifndef __PolyVox_Array_H__
25 #define __PolyVox_Array_H__
26 
27 #include "Impl/SubArray.h"
28 
29 #include "PolyVoxCore/ArraySizes.h" //Not strictly required, but convienient
30 
31 namespace PolyVox
32 {
75  template <uint32_t noOfDims, typename ElementType>
76  class Array
77  {
78  public:
82  Array<noOfDims, ElementType>(const uint32_t (&pDimensions)[noOfDims]);
85 
87  SubArray<noOfDims-1, ElementType> operator[](uint32_t uIndex);
89  const SubArray<noOfDims-1, ElementType> operator[](uint32_t uIndex) const;
90 
92  uint32_t getNoOfElements(void) const;
94  ElementType* getRawData(void) const;
95 
97  void resize(const uint32_t (&pDimensions)[noOfDims]);
101  uint32_t getDimension(uint32_t uDimension);
102 
103  private:
105 
107 
108  void deallocate(void);
109 
110  uint32_t * m_pDimensions;
111  uint32_t * m_pOffsets;
112  uint32_t m_uNoOfElements;
113  ElementType * m_pElements;
114  };
115 
116  template <typename ElementType>
117  class Array<1, ElementType>
118  {
119  public:
121 
122  Array<1, ElementType>(const uint32_t (&pDimensions)[1]);
123 
125 
126  ElementType& operator[] (uint32_t uIndex);
127 
128  const ElementType& operator[] (uint32_t uIndex) const;
129 
130  uint32_t getNoOfElements(void) const;
131 
132  ElementType* getRawData(void) const;
133 
134  void resize(const uint32_t (&pDimensions)[1]);
135 
136  void swap(Array<1, ElementType>& rhs);
137 
138  private:
140 
141  Array<1, ElementType>& operator=(const Array<1, ElementType>& rhs);
142 
143  void deallocate(void);
144 
145  uint32_t * m_pDimensions;
146  ElementType * m_pElements;
147  };
148 
149  template <typename ElementType>
150  class Array<0, ElementType>
151  {
152  //Zero dimensional array is meaningless.
153  };
154 
155  //Some handy typedefs
172 
189 
206 }//namespace PolyVox
207 
208 #include "PolyVoxCore/Array.inl"
209 
210 #endif