From 8240d477bda98412fe25d928c0262772f8afc638 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 27 Mar 2010 23:45:41 +0000 Subject: [PATCH] Documentation for ArraySizes. --- library/PolyVoxCore/CMakeLists.txt | 6 +- library/PolyVoxCore/include/Array.h | 2 + library/PolyVoxCore/include/ArraySizes.h | 83 +++++++++++++++++ library/PolyVoxCore/include/Dimensions.h | 92 ------------------- .../PolyVoxCore/source/SurfaceExtractor.cpp | 1 - 5 files changed, 89 insertions(+), 95 deletions(-) create mode 100644 library/PolyVoxCore/include/ArraySizes.h delete mode 100644 library/PolyVoxCore/include/Dimensions.h diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index 120f7455..52b22299 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -21,8 +21,8 @@ SET(CORE_SRC_FILES SET(CORE_INC_FILES include/Array.h include/Array.inl - include/Dimensions.h - include/Dimensions.inl + include/ArraySizes.h + include/ArraySizes.inl include/GradientEstimators.inl include/SurfaceMesh.h include/Log.h @@ -49,6 +49,8 @@ SET(IMPL_SRC_FILES ) SET(IMPL_INC_FILES + include/PolyVoxImpl/ArraySizesImpl.h + include/PolyVoxImpl/ArraySizesImpl.inl include/PolyVoxImpl/Block.h include/PolyVoxImpl/Block.inl include/PolyVoxImpl/CPlusPlusZeroXSupport.h diff --git a/library/PolyVoxCore/include/Array.h b/library/PolyVoxCore/include/Array.h index 4315a7a0..aa488009 100644 --- a/library/PolyVoxCore/include/Array.h +++ b/library/PolyVoxCore/include/Array.h @@ -27,6 +27,8 @@ freely, subject to the following restrictions: #define __PolyVox_Array_H__ #pragma region Headers +#include "ArraySizes.h" //Not strictly required, but convienient + #include "PolyVoxImpl/TypeDef.h" #include "PolyVoxImpl/CPlusPlusZeroXSupport.h" #pragma endregion diff --git a/library/PolyVoxCore/include/ArraySizes.h b/library/PolyVoxCore/include/ArraySizes.h new file mode 100644 index 00000000..aed3b58d --- /dev/null +++ b/library/PolyVoxCore/include/ArraySizes.h @@ -0,0 +1,83 @@ +#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_ArraySizes_H__ +#define __PolyVox_ArraySizes_H__ + +#pragma region Headers +#include "PolyVoxImpl/ArraySizesImpl.h" +#include "PolyVoxImpl/CPlusPlusZeroXSupport.h" +#pragma endregion + +namespace PolyVox +{ + ///The ArraySizes class provide a convienient way to specify the dimensions of an Array. + //////////////////////////////////////////////////////////////////////////////// + /// The Array class requires an array of integers to be passed to the constructor + /// to specify the dimensions of the Array to be built. C++ does not allow this to + /// be done in place, and so it typically requires an extra line of code - something + /// like this: + /// + /// \code + /// uint32_t dimensions[3] = {10, 20, 30}; // Array dimensions + /// Array<3,float> array(dimensions); + /// \endcode + /// + /// The ArraySizes class can be constructed in place, and also provides implicit + /// conversion to an array of integers. Hence it is now possible to declare the + /// above Array as follows: + /// + /// \code + /// Array<3,float> array(ArraySizes(10)(20)(30)); + /// \endcode + /// + /// Usage of this class is therefore very simple, although the template code + /// behind it may appear complex. For reference, it is based upon the article here: + /// http://www.drdobbs.com/cpp/184401319/ + //////////////////////////////////////////////////////////////////////////////// + class ArraySizes + { + typedef const uint32_t (&UIntArray1)[1]; + + public: + /// Constructor + explicit ArraySizes(uint32_t uSize); + + /// Duplicates this object but with an extra dimension + ArraySizesImpl<2> operator () (uint32_t uSize); + + /// Converts this object to an array of integers + operator UIntArray1 () const; + + private: + // This class is only one dimensional. Higher dimensions + // are implemented via the ArraySizesImpl class. + uint32_t m_pSizes[1]; + }; +}//namespace PolyVox + +#include "ArraySizes.inl" + +#endif //__PolyVox_ArraySizes_H__ \ No newline at end of file diff --git a/library/PolyVoxCore/include/Dimensions.h b/library/PolyVoxCore/include/Dimensions.h deleted file mode 100644 index 5b5a00d0..00000000 --- a/library/PolyVoxCore/include/Dimensions.h +++ /dev/null @@ -1,92 +0,0 @@ -#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_Dimensions_H__ -#define __PolyVox_Dimensions_H__ - -#pragma region Headers -#include "PolyVoxImpl/TypeDef.h" -#include "PolyVoxImpl/CPlusPlusZeroXSupport.h" -#pragma endregion - -namespace PolyVox -{ - template - class ArraySizesImpl - { - typedef const uint32_t (&UIntArrayN)[N]; - - friend class ArraySizes; - friend class ArraySizesImpl; - - public: - ArraySizesImpl operator () (uint32_t uSize) - { - return ArraySizesImpl(m_pSizes, uSize); - } - - operator UIntArrayN () const - { - return m_pSizes; - } - - private: - ArraySizesImpl(const uint32_t (&pSizes)[N-1], uint32_t uSize) - { - std::copy(&pSizes[0],&pSizes[N-1],m_pSizes); - m_pSizes[N-1]=uSize; - } - - uint32_t m_pSizes[N]; - }; - - class ArraySizes - { - typedef const uint32_t (&UIntArray1)[1]; - - public: - explicit ArraySizes(uint32_t uSize) - { - m_pSizes[0]=uSize; - } - - ArraySizesImpl<2> operator () (uint32_t uSize) - { - return ArraySizesImpl<2>(m_pSizes, uSize); - } - - operator UIntArray1 () const - { - return m_pSizes; - } - - private: - uint32_t m_pSizes[1]; - }; -}//namespace PolyVox - -#include "Array.inl" - -#endif //__PolyVox_Dimensions_H__ \ No newline at end of file diff --git a/library/PolyVoxCore/source/SurfaceExtractor.cpp b/library/PolyVoxCore/source/SurfaceExtractor.cpp index 85035a4f..29c6c43c 100644 --- a/library/PolyVoxCore/source/SurfaceExtractor.cpp +++ b/library/PolyVoxCore/source/SurfaceExtractor.cpp @@ -24,7 +24,6 @@ freely, subject to the following restrictions: #include "SurfaceExtractor.h" #include "Array.h" -#include "Dimensions.h" #include "SurfaceMesh.h" #include "PolyVoxImpl/MarchingCubesTables.h" #include "SurfaceVertex.h"