Improved FixedArray

This commit is contained in:
Jacob Støren 2013-12-06 14:22:01 +01:00
parent 819a2ab93e
commit 776ed7755e
2 changed files with 12 additions and 4 deletions

View File

@ -44,7 +44,7 @@ RigCell::RigCell() :
m_cellIndex(cvf::UNDEFINED_SIZE_T),
m_coarseningBoxIndex(cvf::UNDEFINED_SIZE_T)
{
memcpy(m_cornerIndices.m_array, undefinedCornersArray, 8*sizeof(size_t));
memcpy(m_cornerIndices.data(), undefinedCornersArray, 8*sizeof(size_t));
m_cellFaceFaults[0] = false;
m_cellFaceFaults[1] = false;

View File

@ -47,15 +47,23 @@ namespace caf
template < typename T, size_t size >
class FixedArray
{
public:
T m_array[size];
template<typename IndexType> T& operator[](const IndexType& index) { CVF_TIGHT_ASSERT(static_cast<size_t>(index) < size); return m_array[index]; }
template<typename IndexType> const T& operator[](const IndexType& index) const { CVF_TIGHT_ASSERT(static_cast<size_t>(index) < size); return m_array[index]; }
public:
const T* data() const { return m_array; }
T* data() { return m_array; }
FixedArray<T, size>& operator=(const T* ptr) { for (size_t i = 0; i < size ; ++i) m_array[i] = ptr[i]; return *this;}
template<typename IndexType> T& operator[](const IndexType& index) { CVF_TIGHT_ASSERT(static_cast<size_t>(index) < size); return m_array[index]; }
template<typename IndexType> const T& operator[](const IndexType& index) const { CVF_TIGHT_ASSERT(static_cast<size_t>(index) < size); return m_array[index]; }
};
typedef FixedArray<int, 3> IntArray3;
typedef FixedArray<int, 4> IntArray4;
typedef FixedArray<int, 8> IntArray8;
typedef FixedArray<unsigned int, 4> UintArray4;
typedef FixedArray<unsigned int, 8> UintArray8;
typedef FixedArray<size_t, 3> SizeTArray3;
typedef FixedArray<size_t, 4> SizeTArray4;
typedef FixedArray<size_t, 6> SizeTArray6;