PolyVox  0.2.1
Open source voxel management library
SubArray.inl
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 #include <cassert>
25 
26 namespace PolyVox
27 {
28  template <uint32_t noOfDims, typename ElementType>
29  SubArray<noOfDims-1, ElementType> SubArray<noOfDims, ElementType>::operator[](uint32_t uIndex)
30  {
31  assert(uIndex<m_pDimensions[0]);
32  return
33  SubArray<noOfDims-1, ElementType>(&m_pElements[uIndex*m_pOffsets[0]],
34  m_pDimensions+1, m_pOffsets+1);
35  }
36 
37  template <uint32_t noOfDims, typename ElementType>
38  const SubArray<noOfDims-1, ElementType> SubArray<noOfDims, ElementType>::operator[](uint32_t uIndex) const
39  {
40  assert(uIndex<m_pDimensions[0]);
41  return
42  SubArray<noOfDims-1, ElementType>(&m_pElements[uIndex*m_pOffsets[0]],
43  m_pDimensions+1, m_pOffsets+1);
44  }
45 
46  template <uint32_t noOfDims, typename ElementType>
47  SubArray<noOfDims, ElementType>::SubArray(ElementType * pElements, uint32_t * pDimensions, uint32_t * pOffsets)
48  :m_pDimensions(pDimensions)
49  ,m_pOffsets(pOffsets)
50  ,m_uNoOfElements(0)
51  ,m_pElements(pElements)
52  {
53  }
54 
55 
56  template <typename ElementType>
57  ElementType& SubArray<1, ElementType>::operator[] (uint32_t uIndex)
58  {
59  assert(uIndex<m_pDimensions[0]);
60  return m_pElements[uIndex];
61  }
62 
63  template <typename ElementType>
64  const ElementType& SubArray<1, ElementType>::operator[] (uint32_t uIndex) const
65  {
66  assert(uIndex<m_pDimensions[0]);
67  return m_pElements[uIndex];
68  }
69 
70  template <typename ElementType>
71  SubArray<1, ElementType>::SubArray(ElementType * pElements, uint32_t * pDimensions, uint32_t * /*pOffsets*/)
72  :m_pDimensions(pDimensions)
73  ,m_pElements(pElements)
74  {
75  }
76 }//namespace PolyVox