CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FunctionsIO.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_Utilities_interface_FunctionsIO_h
2 #define PhysicsTools_Utilities_interface_FunctionsIO_h
8 #include <ostream>
9 
10 namespace funct {
11 
12 template<int n>
13 std::ostream& operator<<(std::ostream& cout, const Numerical<n>&) {
14  return cout << n;
15 }
16 
17 template<int n, int m>
18 std::ostream& operator<<(std::ostream& cout, const funct::FractionStruct<n, m> &) {
19  return cout << n << "/" << m;
20 }
21 
22 template<int n, int m>
23 std::ostream& operator<<(std::ostream& cout,
25  return cout << "-" << n << "/" << m;
26 }
27 
28 #define PRINT_FUNCTION(FUN, NAME) \
29 template<typename T> \
30 std::ostream& operator<<(std::ostream& cout, const funct::FUN<T> & f) { \
31  return cout << NAME << "(" << f._ << ")"; \
32 } \
33  \
34 struct __useless_ignoreme
35 
44 
45 #undef PRINT_FUNCTION
46 
47 #define PRINT_BINARY_OPERATOR(TMPL, OP) \
48 template<typename A, typename B> \
49 std::ostream& operator<<(std::ostream& cout, const funct::TMPL <A, B> & f) \
50 { return cout << f._1 << OP << f._2; } \
51  \
52 struct __useless_ignoreme
53 
54 #define PRINT_UNARY_OPERATOR(TMPL, OP) \
55 template<typename A> \
56 std::ostream& operator<<(std::ostream& cout, const funct::TMPL <A> & f) \
57 { return cout << OP << f._; } \
58  \
59 struct __useless_ignoreme
60 
66 
67 #undef PRINT_BINARY_OPERATOR
68 #undef PRINT_UNARY_OPERATOR
69 
70 template<typename A, typename B>
71 std::ostream& operator<<(std::ostream& cout,
73  return cout << f._1 << " - " << f._2._;
74 }
75 
76 template<typename A, typename B>
77 std::ostream& operator<<(std::ostream& cout,
79  return cout << "- " << f._1._ << " - " << f._2._;
80 }
81 
82 template<typename A, typename B>
83 std::ostream& operator<<(std::ostream& cout,
85  return cout << "- " << f._1._ << " + " << f._2;
86 }
87 
88 template<typename A, int n>
89 std::ostream& operator<<(std::ostream& cout,
91  return cout << f._1 << (n >= 0 ? " + " : " - ") << ::abs(n);
92 }
93 
94 template<typename A, int n>
95 std::ostream& operator<<( std::ostream& cout,
97  return cout << "- " << f._1._ << (n >= 0 ? " + " : " - ") << ::abs(n);
98 }
99 
100 #define PARENTHESES(TMPL1, TMPL2, OP) \
101 template<typename A, typename B, typename C> \
102 std::ostream& operator<<(std::ostream& cout, \
103  const funct::TMPL1<funct::TMPL2<A, B>, C> & f) { \
104  return cout << "( " << f._1 << " )" << OP << f._2; \
105 } \
106  \
107 template<typename A, typename B, typename C> \
108 std::ostream& operator<<(std::ostream& cout, \
109  const funct::TMPL1<C, funct::TMPL2<A, B> > & f) { \
110  return cout << f._1 << OP << "( " << f._2 << " )"; \
111 } \
112  \
113 template<typename A, typename B, typename C, typename D> \
114 std::ostream& operator<<(std::ostream& cout, \
115  const funct::TMPL1<funct::TMPL2<A, B>, \
116  funct::TMPL2<C, D> > & f) { \
117  return cout << "( " << f._1 << " )" << OP << "( " << f._2 << " )"; \
118 } \
119  \
120 struct __useless_ignoreme
121 
122 #define PARENTHESES_FRACT(TMPL, OP) \
123 template<int n, int m, typename A> \
124 std::ostream& operator<<(std::ostream& cout, \
125  const funct::TMPL<funct::FractionStruct<n, m>, A> & f ) { \
126  return cout << "( " << f._1 << " )" << OP << f._2; \
127  } \
128  \
129 template<int n, int m, typename A> \
130 std::ostream& operator<<(std::ostream& cout, \
131  const funct::TMPL<A, funct::FractionStruct<n, m> > & f) { \
132  return cout << f._1 << OP << "( " << f._2 << " )"; } \
133  \
134 template<int n, int m, int k, int l> \
135 std::ostream& operator<<(std::ostream& cout, \
136  const funct::TMPL<funct::FractionStruct<n, m>, \
137  funct::FractionStruct<k, l> > & f) { \
138  return cout << "( " << f._1 << " )" << OP << "( " << f._2 << " )"; \
139 } \
140  \
141 template<int n, int m, typename A> \
142 std::ostream& operator<<(std::ostream& cout, \
143  const funct::TMPL<funct::MinusStruct<funct::FractionStruct<n, m> >, A> & f) { \
144  return cout << "( " << f._1 << " )" << OP << f._2; \
145 } \
146  \
147 template<int n, int m, typename A> \
148 std::ostream& operator<<(std::ostream& cout, \
149  const funct::TMPL<A, funct::MinusStruct<funct::FractionStruct<n, m> > > & f) { \
150  return cout << f._1 << OP << "( " << f._2 << " )"; \
151 } \
152 struct __useless_ignoreme
153 
154 #define PARENTHESES_1(TMPL1, TMPL2, OP) \
155 template<typename A, typename B> \
156 std::ostream& operator<<(std::ostream& cout, \
157  const funct::TMPL1<funct::TMPL2<A, B> > & f) { \
158  return cout << OP << "( " << f._ << " )"; \
159 } \
160 struct __useless_ignoreme
161 
167 
171 
172 //PARENTHESES_FRACT(ProductStruct, " ");
175 
177 //PARENTHESES_1(MinusStruct, RatioStruct, "-");
178 
179 #undef PARENTHESES
180 #undef PARENTHESES_FRACT
181 #undef PARENTHESES_1
182 
183 }
184 
185 #endif
#define PRINT_UNARY_OPERATOR(TMPL, OP)
Definition: FunctionsIO.h:54
#define PARENTHESES(TMPL1, TMPL2, OP)
Definition: FunctionsIO.h:100
#define PARENTHESES_FRACT(TMPL, OP)
Definition: FunctionsIO.h:122
#define PRINT_FUNCTION(FUN, NAME)
Definition: FunctionsIO.h:28
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
#define PARENTHESES_1(TMPL1, TMPL2, OP)
Definition: FunctionsIO.h:154
tuple cout
Definition: gather_cfg.py:121
std::ostream & operator<<(std::ostream &cout, const Expression &e)
Definition: Expression.h:39
#define PRINT_BINARY_OPERATOR(TMPL, OP)
Definition: FunctionsIO.h:47