X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2Fcml%2Fet%2Ftraits.h;fp=src%2FMoof%2Fcml%2Fet%2Ftraits.h;h=0e59e4b3e8e76d07269400e0f7f0e425a6282630;hp=0000000000000000000000000000000000000000;hb=c2321281bf12a7efaedde930422c7ddbc92080d4;hpb=87bc17e55b0c1dc73ecc66df856d3f08fd7a7724 diff --git a/src/Moof/cml/et/traits.h b/src/Moof/cml/et/traits.h new file mode 100644 index 0000000..0e59e4b --- /dev/null +++ b/src/Moof/cml/et/traits.h @@ -0,0 +1,143 @@ +/* -*- C++ -*- ------------------------------------------------------------ + +Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/ + +The Configurable Math Library (CML) is distributed under the terms of the +Boost Software License, v1.0 (see cml/LICENSE for details). + + *-----------------------------------------------------------------------*/ +/** @file + * @brief + */ + +#ifndef traits_h +#define traits_h + +#include + +/* XXX This is here temporarily, should be rolled into the traits classes + * once it's clear how to best specify scalar args + */ +//#define SCALAR_ARG_TYPE const ScalarT& +//#define ELEMENT_ARG_TYPE const Element& +#define SCALAR_ARG_TYPE ScalarT +#define ELEMENT_ARG_TYPE Element + +namespace cml { +namespace et { + +/** The expression traits class. + * + * The traits class is used to provide uniform access to expression + * objects, including scalars, when used in vector and matrix expressions. + * One especially useful property for scalars is that scalars are + * implicitly "promoted" to vectors or scalars as necessary via the + * ExprTraits's get() method. Without this functionality, a separate + * expression tree node would be needed to hold a scalar, which would + * adversely affect performance. + * + * @internal This is also currently used for determining traits of scalar + * types from the scalar operators (+,-,etc.). Really, a separate traits + * class should probably be used for this (e.g. ScalarTraits). + */ +template struct ExprTraits +#if defined(CML_NO_DEFAULT_EXPR_TRAITS) +/* For testing, don't default to scalar traits: */ +#else +{ + /* Standard: */ + typedef T expr_type; + typedef T value_type; + typedef T& reference; + typedef T const_reference; + typedef scalar_result_tag result_tag; + typedef fixed_memory_tag memory_tag; + typedef unit_size_tag size_tag; + typedef expr_type result_type; + typedef expr_leaf_tag node_tag; + + /** Vector-like access, just returns the value. */ + value_type get(const_reference v, size_t) const { return v; } + + /** Matrix-like access, just returns the value. */ + value_type get(const_reference v, size_t, size_t) const { return v; } + + /** Size is always 1. */ + size_t size(const_reference) const { return 1; } + + /** Size is always 1. */ + size_t rows(double) const { return 1; } + + /** Size is always 1. */ + size_t cols(double) const { return 1; } +} +#endif +; + +#if defined(CML_NO_DEFAULT_EXPR_TRAITS) +template<> struct ExprTraits +{ + /* Standard: */ + typedef double expr_type; + typedef double value_type; + typedef double& reference; + typedef double const_reference; + typedef scalar_result_tag result_tag; + typedef fixed_memory_tag memory_tag; + typedef unit_size_tag size_tag; + typedef double result_type; + typedef expr_leaf_tag node_tag; + + /** Vector-like access, just returns the value. */ + value_type get(double v, size_t) const { return v; } + + /** Matrix-like access, just returns the value. */ + value_type get(double v, size_t, size_t) const { return v; } + + /** Size is always 1. */ + size_t size(double) const { return 1; } + + /** Size is always 1. */ + size_t rows(double) const { return 1; } + + /** Size is always 1. */ + size_t cols(double) const { return 1; } +}; + +template<> struct ExprTraits +{ + /* Standard: */ + typedef float expr_type; + typedef float value_type; + typedef float& reference; + typedef float const_reference; + typedef scalar_result_tag result_tag; + typedef fixed_memory_tag memory_tag; + typedef unit_size_tag size_tag; + typedef float result_type; + typedef expr_leaf_tag node_tag; + + /** Vector-like access, just returns the value. */ + value_type get(float v, size_t) const { return v; } + + /** Matrix-like access, just returns the value. */ + value_type get(float v, size_t, size_t) const { return v; } + + /** Size is always 1. */ + size_t size(float) const { return 1; } + + /** Size is always 1. */ + size_t rows(float) const { return 1; } + + /** Size is always 1. */ + size_t cols(float) const { return 1; } +}; +#endif + +} // namespace et +} // namespace cml + +#endif + +// ------------------------------------------------------------------------- +// vim:ft=cpp