Skip to content
Snippets Groups Projects
Commit 81440870 authored by Markus Blatt's avatar Markus Blatt
Browse files

* Hide the TMPs in an anonymous namespace

* More documentation

BTW: all these calculation look damn complicated and suspicious

[[Imported from SVN: r5448]]
parent 894602b2
Branches
Tags
No related merge requests found
......@@ -24,24 +24,33 @@ namespace Dune
* @author Markus Blatt
*/
/** \todo Please doc me! */
template<class T>
struct AlignmentStruct
namespace
{
char c;
T t;
void hack();
};
/** \todo Please doc me! */
template<class T, std::size_t N>
struct AlignmentHelper
{
enum { N2 = sizeof(AlignmentStruct<T>) - sizeof(T) - N };
char padding1[N];
T t;
char padding2[N2];
};
/**
* @brief Helper class to meassure alignment requirement.
* @tparam T The type we want to meassure the alignment requirement for.
*/
template<class T>
struct AlignmentStruct
{
char c;
T t;
void hack();
};
/**
* @brief Helper class to meassure alignment requirement.
* @tparam T The type we want to meassure the alignment requirement for.
*/
template<class T, std::size_t N>
struct AlignmentHelper
{
enum { N2 = sizeof(AlignmentStruct<T>) - sizeof(T) - N };
char padding1[N];
T t;
char padding2[N2];
};
#define ALIGNMENT_MODULO(a, b) (a % b == 0 ? \
static_cast<std::size_t>(b) : \
......@@ -50,33 +59,39 @@ namespace Dune
static_cast<std::size_t>(b) ? \
static_cast<std::size_t>(a) : \
static_cast<std::size_t>(b))
template <class T, std::size_t N>
struct AlignmentTester
{
typedef AlignmentStruct<T> s;
typedef AlignmentHelper<T, N> h;
typedef AlignmentTester<T, N - 1> next;
enum
/** @brief does the actual calculations. */
template <class T, std::size_t N>
struct AlignmentTester
{
a1 = ALIGNMENT_MODULO(N , sizeof(T)),
a2 = ALIGNMENT_MODULO(h::N2 , sizeof(T)),
a3 = ALIGNMENT_MODULO(sizeof(h), sizeof(T)),
a = sizeof(h) == sizeof(s) ? ALIGNMENT_MIN(a1, a2) : a3,
result = ALIGNMENT_MIN(a, next::result)
typedef AlignmentStruct<T> s;
typedef AlignmentHelper<T, N> h;
typedef AlignmentTester<T, N - 1> next;
enum
{
a1 = ALIGNMENT_MODULO(N , sizeof(T)),
a2 = ALIGNMENT_MODULO(h::N2 , sizeof(T)),
a3 = ALIGNMENT_MODULO(sizeof(h), sizeof(T)),
a = sizeof(h) == sizeof(s) ? ALIGNMENT_MIN(a1, a2) : a3,
result = ALIGNMENT_MIN(a, next::result)
};
};
};
template <class T>
struct AlignmentTester<T, 0>
{
enum
/** @brief does the actual calculations. */
template <class T>
struct AlignmentTester<T, 0>
{
result = ALIGNMENT_MODULO(sizeof(AlignmentStruct<T>), sizeof(T))
enum
{
result = ALIGNMENT_MODULO(sizeof(AlignmentStruct<T>), sizeof(T))
};
};
};
} //end anonymous namspace
/**
* @brief Calculates the alignment properties of a type.
* @brief Calculates the alignment requirement of a type.
*
* This will be a safe value and not an optimal one.
* If TR1 is available it falls back to std::alignment_of.
*/
template <class T>
struct AlignmentOf
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment