1 /* -*- C++ -*- ------------------------------------------------------------
3 Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
5 The Configurable Math Library (CML) is distributed under the terms of the
6 Boost Software License, v1.0 (see cml/LICENSE for details).
8 *-----------------------------------------------------------------------*/
16 #include <cml/et/tags.h>
18 /* XXX This is here temporarily, should be rolled into the traits classes
19 * once it's clear how to best specify scalar args
21 //#define SCALAR_ARG_TYPE const ScalarT&
22 //#define ELEMENT_ARG_TYPE const Element&
23 #define SCALAR_ARG_TYPE ScalarT
24 #define ELEMENT_ARG_TYPE Element
29 /** The expression traits class.
31 * The traits class is used to provide uniform access to expression
32 * objects, including scalars, when used in vector and matrix expressions.
33 * One especially useful property for scalars is that scalars are
34 * implicitly "promoted" to vectors or scalars as necessary via the
35 * ExprTraits's get() method. Without this functionality, a separate
36 * expression tree node would be needed to hold a scalar, which would
37 * adversely affect performance.
39 * @internal This is also currently used for determining traits of scalar
40 * types from the scalar operators (+,-,etc.). Really, a separate traits
41 * class should probably be used for this (e.g. ScalarTraits).
43 template<typename T
> struct ExprTraits
44 #if defined(CML_NO_DEFAULT_EXPR_TRAITS)
45 /* For testing, don't default to scalar traits: */
52 typedef T const_reference
;
53 typedef scalar_result_tag result_tag
;
54 typedef fixed_memory_tag memory_tag
;
55 typedef unit_size_tag size_tag
;
56 typedef expr_type result_type
;
57 typedef expr_leaf_tag node_tag
;
59 /** Vector-like access, just returns the value. */
60 value_type
get(const_reference v
, size_t) const { return v
; }
62 /** Matrix-like access, just returns the value. */
63 value_type
get(const_reference v
, size_t, size_t) const { return v
; }
65 /** Size is always 1. */
66 size_t size(const_reference
) const { return 1; }
68 /** Size is always 1. */
69 size_t rows(double) const { return 1; }
71 /** Size is always 1. */
72 size_t cols(double) const { return 1; }
77 #if defined(CML_NO_DEFAULT_EXPR_TRAITS)
78 template<> struct ExprTraits
<double>
81 typedef double expr_type
;
82 typedef double value_type
;
83 typedef double& reference
;
84 typedef double const_reference
;
85 typedef scalar_result_tag result_tag
;
86 typedef fixed_memory_tag memory_tag
;
87 typedef unit_size_tag size_tag
;
88 typedef double result_type
;
89 typedef expr_leaf_tag node_tag
;
91 /** Vector-like access, just returns the value. */
92 value_type
get(double v
, size_t) const { return v
; }
94 /** Matrix-like access, just returns the value. */
95 value_type
get(double v
, size_t, size_t) const { return v
; }
97 /** Size is always 1. */
98 size_t size(double) const { return 1; }
100 /** Size is always 1. */
101 size_t rows(double) const { return 1; }
103 /** Size is always 1. */
104 size_t cols(double) const { return 1; }
107 template<> struct ExprTraits
<float>
110 typedef float expr_type
;
111 typedef float value_type
;
112 typedef float& reference
;
113 typedef float const_reference
;
114 typedef scalar_result_tag result_tag
;
115 typedef fixed_memory_tag memory_tag
;
116 typedef unit_size_tag size_tag
;
117 typedef float result_type
;
118 typedef expr_leaf_tag node_tag
;
120 /** Vector-like access, just returns the value. */
121 value_type
get(float v
, size_t) const { return v
; }
123 /** Matrix-like access, just returns the value. */
124 value_type
get(float v
, size_t, size_t) const { return v
; }
126 /** Size is always 1. */
127 size_t size(float) const { return 1; }
129 /** Size is always 1. */
130 size_t rows(float) const { return 1; }
132 /** Size is always 1. */
133 size_t cols(float) const { return 1; }
142 // -------------------------------------------------------------------------