cheshirekow  v0.1.0
ostream.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Josh Bialkowski (jbialk@mit.edu)
3  *
4  * This file is part of mpblocks.
5  *
6  * mpblocks is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * mpblocks is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with mpblocks. If not, see <http://www.gnu.org/licenses/>.
18  */
27 #ifndef MPBLOCKS_CUDA_POLYNOMIAL_OSTREAM_H_
28 #define MPBLOCKS_CUDA_POLYNOMIAL_OSTREAM_H_
29 
30 #include <iostream>
31 #include <cstdio>
32 #include <iomanip>
33 #include <sstream>
34 #include <vector>
35 
37 
38 namespace mpblocks {
39 namespace cuda {
40 namespace polynomial {
41 
42 
43 
44 template < typename Scalar, class Exp, class Spec >
45 struct PolyPrinter{};
46 
47 template < class Scalar, class Exp, int Head, class Tail >
48 struct PolyPrinter< Scalar, Exp, IntList<Head,Tail> >
49 {
50  static void print( std::ostream& out, const Exp& exp)
51  {
52  Scalar val = get<Head>(exp);
53  if( val != 0 )
54  out << val << " s^" << Head << " + ";
56  }
57 };
58 
59 template < class Scalar, class Exp, class Tail >
60 struct PolyPrinter< Scalar, Exp, IntList<1,Tail> >
61 {
62  static void print( std::ostream& out, const Exp& exp)
63  {
64  Scalar val = get<1>(exp);
65  if( val != 0 )
66  out << val << " s + ";
68  }
69 };
70 
71 template < class Scalar, class Exp, class Tail >
72 struct PolyPrinter< Scalar, Exp, IntList<0,Tail> >
73 {
74  static void print( std::ostream& out, const Exp& exp)
75  {
76  Scalar val = get<0>(exp);
77  if( val != 0 )
78  out << val << " + ";
80  }
81 };
82 
83 
84 template < class Scalar, class Exp>
85 struct PolyPrinter< Scalar, Exp, intlist::Terminal >
86 {
87  static void print( std::ostream& out, const Exp& exp )
88  {}
89 };
90 
91 
92 template < class Scalar, class Exp, class Spec>
93 std::ostream& operator<<( std::ostream& out,
94  const RValue<Scalar,Exp,Spec>& exp )
95 {
96  PolyPrinter<Scalar,Exp,Spec>::print(out, static_cast<const Exp&>(exp) );
97  return out;
98 }
99 
100 
101 
102 
103 } // polynomial
104 } // cuda
105 } // mpblocks
106 
107 
108 
109 
110 
111 
112 
113 
114 
115 #endif // IOSTREAM_H_
std::ostream & operator<<(std::ostream &out, const RValue< Scalar, Exp, Spec > &exp)
Definition: ostream.h:93
static void print(std::ostream &out, const Exp &exp)
Definition: ostream.h:74
std::ostream & print(std::ostream &out, SturmSequence< Scalar > const &seq, const std::string &var="x")
Definition: ostream.h:110
expression template for rvalues
Definition: RValue.h:40
static void print(std::ostream &out, const Exp &exp)
Definition: ostream.h:50
static void print(std::ostream &out, const Exp &exp)
Definition: ostream.h:62
compile time integer list (because cuda doesn't understand variadic templates )
Definition: IntList.h:50
static void print(std::ostream &out, const Exp &exp)
Definition: ostream.h:87