traits.h

Go to the documentation of this file.
00001 /* -*- C++ -*- ------------------------------------------------------------
00002  
00003 Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
00004 
00005 The Configurable Math Library (CML) is distributed under the terms of the
00006 Boost Software License, v1.0 (see cml/LICENSE for details).
00007 
00008  *-----------------------------------------------------------------------*/
00013 #ifndef traits_h
00014 #define traits_h
00015 
00016 #include <cml/et/tags.h>
00017 
00018 /* XXX This is here temporarily, should be rolled into the traits classes
00019  * once it's clear how to best specify scalar args
00020  */
00021 //#define SCALAR_ARG_TYPE const ScalarT&
00022 //#define ELEMENT_ARG_TYPE const Element&
00023 #define SCALAR_ARG_TYPE ScalarT
00024 #define ELEMENT_ARG_TYPE Element
00025 
00026 namespace cml {
00027 namespace et {
00028 
00043 template<typename T> struct ExprTraits
00044 #if defined(CML_NO_DEFAULT_EXPR_TRAITS)
00045 /* For testing, don't default to scalar traits: */
00046 #else
00047 {
00048     /* Standard: */
00049     typedef T expr_type;
00050     typedef T value_type;
00051     typedef T& reference;
00052     typedef T const_reference;
00053     typedef scalar_result_tag result_tag;
00054     typedef fixed_memory_tag memory_tag;
00055     typedef unit_size_tag size_tag;
00056     typedef expr_type result_type;
00057     typedef expr_leaf_tag node_tag;
00058 
00060     value_type get(const_reference v, size_t) const { return v; }
00061 
00063     value_type get(const_reference v, size_t, size_t) const { return v; }
00064 
00066     size_t size(const_reference) const { return 1; }
00067 
00069     size_t rows(double) const { return 1; }
00070 
00072     size_t cols(double) const { return 1; }
00073 }
00074 #endif
00075 ;
00076 
00077 #if defined(CML_NO_DEFAULT_EXPR_TRAITS)
00078 template<> struct ExprTraits<double>
00079 {
00080     /* Standard: */
00081     typedef double expr_type;
00082     typedef double value_type;
00083     typedef double& reference;
00084     typedef double const_reference;
00085     typedef scalar_result_tag result_tag;
00086     typedef fixed_memory_tag memory_tag;
00087     typedef unit_size_tag size_tag;
00088     typedef double result_type;
00089     typedef expr_leaf_tag node_tag;
00090 
00092     value_type get(double v, size_t) const { return v; }
00093 
00095     value_type get(double v, size_t, size_t) const { return v; }
00096 
00098     size_t size(double) const { return 1; }
00099 
00101     size_t rows(double) const { return 1; }
00102 
00104     size_t cols(double) const { return 1; }
00105 };
00106 
00107 template<> struct ExprTraits<float>
00108 {
00109     /* Standard: */
00110     typedef float expr_type;
00111     typedef float value_type;
00112     typedef float& reference;
00113     typedef float const_reference;
00114     typedef scalar_result_tag result_tag;
00115     typedef fixed_memory_tag memory_tag;
00116     typedef unit_size_tag size_tag;
00117     typedef float result_type;
00118     typedef expr_leaf_tag node_tag;
00119 
00121     value_type get(float v, size_t) const { return v; }
00122 
00124     value_type get(float v, size_t, size_t) const { return v; }
00125 
00127     size_t size(float) const { return 1; }
00128 
00130     size_t rows(float) const { return 1; }
00131 
00133     size_t cols(float) const { return 1; }
00134 };
00135 #endif
00136 
00137 } // namespace et
00138 } // namespace cml
00139 
00140 #endif
00141 
00142 // -------------------------------------------------------------------------
00143 // vim:ft=cpp

Generated on Sat Jul 18 19:35:20 2009 for CML 1.0 by  doxygen 1.5.9