Moved some stuff from Array to SubArray.
This commit is contained in:
parent
9485706e52
commit
a9b8e5b0cf
@ -55,6 +55,8 @@ SET(IMPL_INC_FILES
|
|||||||
include/PolyVoxImpl/Block.inl
|
include/PolyVoxImpl/Block.inl
|
||||||
include/PolyVoxImpl/CPlusPlusZeroXSupport.h
|
include/PolyVoxImpl/CPlusPlusZeroXSupport.h
|
||||||
include/PolyVoxImpl/MarchingCubesTables.h
|
include/PolyVoxImpl/MarchingCubesTables.h
|
||||||
|
include/PolyVoxImpl/SubArray.h
|
||||||
|
include/PolyVoxImpl/SubArray.inl
|
||||||
include/PolyVoxImpl/TypeDef.h
|
include/PolyVoxImpl/TypeDef.h
|
||||||
include/PolyVoxImpl/Utility.h
|
include/PolyVoxImpl/Utility.h
|
||||||
)
|
)
|
||||||
|
@ -29,7 +29,7 @@ freely, subject to the following restrictions:
|
|||||||
#pragma region Headers
|
#pragma region Headers
|
||||||
#include "ArraySizes.h" //Not strictly required, but convienient
|
#include "ArraySizes.h" //Not strictly required, but convienient
|
||||||
|
|
||||||
#include "PolyVoxImpl/TypeDef.h"
|
#include "PolyVoxImpl/SubArray.h"
|
||||||
#include "PolyVoxImpl/CPlusPlusZeroXSupport.h"
|
#include "PolyVoxImpl/CPlusPlusZeroXSupport.h"
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
@ -38,10 +38,8 @@ namespace PolyVox
|
|||||||
template <uint32_t noOfDims, typename ElementType>
|
template <uint32_t noOfDims, typename ElementType>
|
||||||
class Array
|
class Array
|
||||||
{
|
{
|
||||||
friend class Array<noOfDims+1, ElementType>;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Array<noOfDims, ElementType>(const uint32_t (&Dimensions)[noOfDims])
|
Array<noOfDims, ElementType>(const uint32_t (&pDimensions)[noOfDims])
|
||||||
:m_pElements(0)
|
:m_pElements(0)
|
||||||
,m_pDimensions(0)
|
,m_pDimensions(0)
|
||||||
,m_pOffsets(0)
|
,m_pOffsets(0)
|
||||||
@ -54,33 +52,40 @@ namespace PolyVox
|
|||||||
m_uNoOfElements = 1;
|
m_uNoOfElements = 1;
|
||||||
for (uint32_t i = 0; i<noOfDims; i++)
|
for (uint32_t i = 0; i<noOfDims; i++)
|
||||||
{
|
{
|
||||||
assert(Dimensions[i] != 0);
|
assert(pDimensions[i] != 0);
|
||||||
|
|
||||||
m_uNoOfElements *= Dimensions[i];
|
m_uNoOfElements *= pDimensions[i];
|
||||||
m_pDimensions[i] = Dimensions[i];
|
m_pDimensions[i] = pDimensions[i];
|
||||||
m_pOffsets[i] = 1;
|
m_pOffsets[i] = 1;
|
||||||
for (int k=noOfDims-1; k>i; k--)
|
for (int k=noOfDims-1; k>i; k--)
|
||||||
{
|
{
|
||||||
m_pOffsets[i] *= Dimensions[k];
|
m_pOffsets[i] *= pDimensions[k];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Allocate new elements, let exception propagate
|
// Allocate new elements, let exception propagate
|
||||||
m_pElements = new ElementType[m_uNoOfElements];
|
m_pElements = new ElementType[m_uNoOfElements];
|
||||||
}
|
}
|
||||||
|
|
||||||
Array<noOfDims-1, ElementType> operator [](uint32_t uIndex)
|
~Array<noOfDims, ElementType>()
|
||||||
|
{
|
||||||
|
delete[] m_pDimensions;
|
||||||
|
delete[] m_pOffsets;
|
||||||
|
delete[] m_pElements;
|
||||||
|
}
|
||||||
|
|
||||||
|
SubArray<noOfDims-1, ElementType> operator [](uint32_t uIndex)
|
||||||
{
|
{
|
||||||
assert(uIndex<m_pDimensions[0]);
|
assert(uIndex<m_pDimensions[0]);
|
||||||
return
|
return
|
||||||
Array<noOfDims-1, ElementType>(&m_pElements[uIndex*m_pOffsets[0]],
|
SubArray<noOfDims-1, ElementType>(&m_pElements[uIndex*m_pOffsets[0]],
|
||||||
m_pDimensions+1, m_pOffsets+1);
|
m_pDimensions+1, m_pOffsets+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Array<noOfDims-1, ElementType> operator [](uint32_t uIndex) const
|
const SubArray<noOfDims-1, ElementType> operator [](uint32_t uIndex) const
|
||||||
{
|
{
|
||||||
assert(uIndex<m_pDimensions[0]);
|
assert(uIndex<m_pDimensions[0]);
|
||||||
return
|
return
|
||||||
Array<noOfDims-1, ElementType>(&m_pElements[uIndex*m_pOffsets[0]],
|
SubArray<noOfDims-1, ElementType>(&m_pElements[uIndex*m_pOffsets[0]],
|
||||||
m_pDimensions+1, m_pOffsets+1);
|
m_pDimensions+1, m_pOffsets+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,14 +100,6 @@ namespace PolyVox
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Array<noOfDims, ElementType>(ElementType * pElements, uint32_t * pDimensions, uint32_t * pOffsets)
|
|
||||||
:m_pElements(pElements)
|
|
||||||
,m_pDimensions(pDimensions)
|
|
||||||
,m_pOffsets(pOffsets)
|
|
||||||
,m_uNoOfElements(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t * m_pDimensions;
|
uint32_t * m_pDimensions;
|
||||||
uint32_t * m_pOffsets;
|
uint32_t * m_pOffsets;
|
||||||
uint32_t m_uNoOfElements;
|
uint32_t m_uNoOfElements;
|
||||||
@ -112,15 +109,13 @@ namespace PolyVox
|
|||||||
template <typename ElementType>
|
template <typename ElementType>
|
||||||
class Array<1, ElementType>
|
class Array<1, ElementType>
|
||||||
{
|
{
|
||||||
friend class Array<2, ElementType>;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Array<1, ElementType>(const uint32_t (&Dimensions)[1])
|
Array<1, ElementType>(const uint32_t (&pDimensions)[1])
|
||||||
: m_pElements(0)
|
: m_pElements(0)
|
||||||
,m_pDimensions(0)
|
,m_pDimensions(0)
|
||||||
{
|
{
|
||||||
m_pDimensions = new uint32_t[1];
|
m_pDimensions = new uint32_t[1];
|
||||||
m_pDimensions[0] = Dimensions[0];
|
m_pDimensions[0] = pDimensions[0];
|
||||||
|
|
||||||
// Allocate new elements, let exception propagate
|
// Allocate new elements, let exception propagate
|
||||||
m_pElements = new ElementType[m_pDimensions[0]];
|
m_pElements = new ElementType[m_pDimensions[0]];
|
||||||
@ -149,12 +144,6 @@ namespace PolyVox
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Array<1, ElementType>(ElementType * pElements, uint32_t * pDimensions, uint32_t * /*pOffsets*/)
|
|
||||||
:m_pDimensions(pDimensions)
|
|
||||||
,m_pElements(pElements)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t * m_pDimensions;
|
uint32_t * m_pDimensions;
|
||||||
ElementType * m_pElements;
|
ElementType * m_pElements;
|
||||||
};
|
};
|
||||||
|
114
library/PolyVoxCore/include/PolyVoxImpl/SubArray.h
Normal file
114
library/PolyVoxCore/include/PolyVoxImpl/SubArray.h
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
#pragma region License
|
||||||
|
/*******************************************************************************
|
||||||
|
Copyright (c) 2005-2009 David Williams
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
|
||||||
|
3. This notice may not be removed or altered from any source
|
||||||
|
distribution.
|
||||||
|
*******************************************************************************/
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
|
#ifndef __PolyVox_SubArray_H__
|
||||||
|
#define __PolyVox_SubArray_H__
|
||||||
|
|
||||||
|
#pragma region Headers
|
||||||
|
#include "PolyVoxImpl/CPlusPlusZeroXSupport.h"
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
|
namespace PolyVox
|
||||||
|
{
|
||||||
|
template <uint32_t noOfDims, typename ElementType> class Array;
|
||||||
|
|
||||||
|
template <uint32_t noOfDims, typename ElementType>
|
||||||
|
class SubArray
|
||||||
|
{
|
||||||
|
friend class Array<noOfDims+1, ElementType>;
|
||||||
|
friend class SubArray<noOfDims+1, ElementType>;
|
||||||
|
|
||||||
|
public:
|
||||||
|
SubArray<noOfDims-1, ElementType> operator [](uint32_t uIndex)
|
||||||
|
{
|
||||||
|
assert(uIndex<m_pDimensions[0]);
|
||||||
|
return
|
||||||
|
SubArray<noOfDims-1, ElementType>(&m_pElements[uIndex*m_pOffsets[0]],
|
||||||
|
m_pDimensions+1, m_pOffsets+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const SubArray<noOfDims-1, ElementType> operator [](uint32_t uIndex) const
|
||||||
|
{
|
||||||
|
assert(uIndex<m_pDimensions[0]);
|
||||||
|
return
|
||||||
|
SubArray<noOfDims-1, ElementType>(&m_pElements[uIndex*m_pOffsets[0]],
|
||||||
|
m_pDimensions+1, m_pOffsets+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
SubArray<noOfDims, ElementType>(ElementType * pElements, uint32_t * pDimensions, uint32_t * pOffsets)
|
||||||
|
:m_pElements(pElements)
|
||||||
|
,m_pDimensions(pDimensions)
|
||||||
|
,m_pOffsets(pOffsets)
|
||||||
|
,m_uNoOfElements(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t * m_pDimensions;
|
||||||
|
uint32_t * m_pOffsets;
|
||||||
|
uint32_t m_uNoOfElements;
|
||||||
|
ElementType * m_pElements;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename ElementType>
|
||||||
|
class SubArray<1, ElementType>
|
||||||
|
{
|
||||||
|
friend class Array<2, ElementType>;
|
||||||
|
friend class SubArray<2, ElementType>;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ElementType & operator [] (uint32_t uIndex)
|
||||||
|
{
|
||||||
|
assert(uIndex<m_pDimensions[0]);
|
||||||
|
return m_pElements[uIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
const ElementType & operator [] (uint32_t uIndex) const
|
||||||
|
{
|
||||||
|
assert(uIndex<m_pDimensions[0]);
|
||||||
|
return m_pElements[uIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
SubArray<1, ElementType>(ElementType * pElements, uint32_t * pDimensions, uint32_t * /*pOffsets*/)
|
||||||
|
:m_pDimensions(pDimensions)
|
||||||
|
,m_pElements(pElements)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t * m_pDimensions;
|
||||||
|
ElementType * m_pElements;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename ElementType>
|
||||||
|
class SubArray<0, ElementType>
|
||||||
|
{
|
||||||
|
//Zero dimensional subarray is meaningless.
|
||||||
|
};
|
||||||
|
}//namespace PolyVox
|
||||||
|
|
||||||
|
#include "SubArray.inl"
|
||||||
|
|
||||||
|
#endif //__PolyVox_SubArray_H__
|
Loading…
x
Reference in New Issue
Block a user