From 64c714ed37d66d2f2b1ba1f6f6091415101bbbec Mon Sep 17 00:00:00 2001 From: Guillaume Bittoun Date: Wed, 9 Jul 2014 20:53:44 +0000 Subject: [PATCH] Adding arraynd skeleton --- src/lol/math/arraynd.h | 93 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 src/lol/math/arraynd.h diff --git a/src/lol/math/arraynd.h b/src/lol/math/arraynd.h new file mode 100644 index 00000000..eb153fce --- /dev/null +++ b/src/lol/math/arraynd.h @@ -0,0 +1,93 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2014 Sam Hocevar +// (c) 2013-2014 Benjamin "Touky" Huet +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://www.wtfpl.net/ for more details. +// + +// +// The arrayNd class +// ----------------- +// A N-Dimensional array class allowing var[i][j][k]... indexing, +// + +// +// FIXME: This file is in lol/math/ instead of lol/base/ because it +// uses ivec3. +// + +#if !defined __LOL_MATH_ARRAYND_H__ +#define __LOL_MATH_ARRAYND_H__ + +#include +#include + +namespace lol +{ + +template +class arraynd : protected array +{ +public: + typedef array super; + typedef typename super::element_t element_t; + + inline arraynd() : + m_sizes() + { + } + + inline arraynd(vec_t sizes, element_t e = element_t()) : + m_sizes(sizes) + { + SetSize(m_sizes, e); + } + + /* Access elements directly using an ivec3 index */ + inline element_t const &operator [](ivec3 pos) const + { + return element_t(); // TODO + } + + inline size_t ComputeTotalSize(vec_t sizes) + { + size_t total_size = 1; + + for (auto size : sizes) + total_size *= size; + + return total_size; + } + + /* Resize the array. + * FIXME: data gets scrambled; should we care? */ + inline void SetSize(vec_t sizes, element_t e = element_t()) + { + this->Resize(ComputeTotalSize(sizes), e); + } + + inline vec_t GetSize() const + { + return ComputeTotalSize(this->m_sizes); + } + +public: + inline element_t *Data() { return super::Data(); } + inline element_t const *Data() const { return super::Data(); } + inline int Count() const { return super::Count(); } + inline int Bytes() const { return super::Bytes(); } + +private: + vec_t m_sizes; +}; + +} /* namespace lol */ + +#endif // __LOL_MATH_ARRAYND_H__ +