]> Dogcows Code - chaz/yoink/blob - src/moof/cml/et/traits.h
bugfix: win32 packaging script temp directories
[chaz/yoink] / src / moof / cml / et / traits.h
1 /* -*- C++ -*- ------------------------------------------------------------
2
3 Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
4
5 The Configurable Math Library (CML) is distributed under the terms of the
6 Boost Software License, v1.0 (see cml/LICENSE for details).
7
8 *-----------------------------------------------------------------------*/
9 /** @file
10 * @brief
11 */
12
13 #ifndef traits_h
14 #define traits_h
15
16 #include <cml/et/tags.h>
17
18 /* XXX This is here temporarily, should be rolled into the traits classes
19 * once it's clear how to best specify scalar args
20 */
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
25
26 namespace cml {
27 namespace et {
28
29 /** The expression traits class.
30 *
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.
38 *
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).
42 */
43 template<typename T> struct ExprTraits
44 #if defined(CML_NO_DEFAULT_EXPR_TRAITS)
45 /* For testing, don't default to scalar traits: */
46 #else
47 {
48 /* Standard: */
49 typedef T expr_type;
50 typedef T value_type;
51 typedef T& reference;
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;
58
59 /** Vector-like access, just returns the value. */
60 value_type get(const_reference v, size_t) const { return v; }
61
62 /** Matrix-like access, just returns the value. */
63 value_type get(const_reference v, size_t, size_t) const { return v; }
64
65 /** Size is always 1. */
66 size_t size(const_reference) const { return 1; }
67
68 /** Size is always 1. */
69 size_t rows(double) const { return 1; }
70
71 /** Size is always 1. */
72 size_t cols(double) const { return 1; }
73 }
74 #endif
75 ;
76
77 #if defined(CML_NO_DEFAULT_EXPR_TRAITS)
78 template<> struct ExprTraits<double>
79 {
80 /* Standard: */
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;
90
91 /** Vector-like access, just returns the value. */
92 value_type get(double v, size_t) const { return v; }
93
94 /** Matrix-like access, just returns the value. */
95 value_type get(double v, size_t, size_t) const { return v; }
96
97 /** Size is always 1. */
98 size_t size(double) const { return 1; }
99
100 /** Size is always 1. */
101 size_t rows(double) const { return 1; }
102
103 /** Size is always 1. */
104 size_t cols(double) const { return 1; }
105 };
106
107 template<> struct ExprTraits<float>
108 {
109 /* Standard: */
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;
119
120 /** Vector-like access, just returns the value. */
121 value_type get(float v, size_t) const { return v; }
122
123 /** Matrix-like access, just returns the value. */
124 value_type get(float v, size_t, size_t) const { return v; }
125
126 /** Size is always 1. */
127 size_t size(float) const { return 1; }
128
129 /** Size is always 1. */
130 size_t rows(float) const { return 1; }
131
132 /** Size is always 1. */
133 size_t cols(float) const { return 1; }
134 };
135 #endif
136
137 } // namespace et
138 } // namespace cml
139
140 #endif
141
142 // -------------------------------------------------------------------------
143 // vim:ft=cpp
This page took 0.034968 seconds and 4 git commands to generate.