CMS 3D CMS Logo

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, const funct::MinusStruct<funct::FractionStruct<n, m> >&) {
24  return cout << "-" << n << "/" << m;
25  }
26 
27 #define PRINT_FUNCTION(FUN, NAME) \
28  template <typename T> \
29  std::ostream& operator<<(std::ostream& cout, const funct::FUN<T>& f) { \
30  return cout << NAME << "(" << f._ << ")"; \
31  } \
32  \
33  struct __useless_ignoreme
34 
43 
44 #undef PRINT_FUNCTION
45 
46 #define PRINT_BINARY_OPERATOR(TMPL, OP) \
47  template <typename A, typename B> \
48  std::ostream& operator<<(std::ostream& cout, const funct::TMPL<A, B>& f) { \
49  return cout << f._1 << OP << f._2; \
50  } \
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  \
60  struct __useless_ignoreme
61 
67 
68 #undef PRINT_BINARY_OPERATOR
69 #undef PRINT_UNARY_OPERATOR
70 
71  template <typename A, typename B>
72  std::ostream& operator<<(std::ostream& cout, const funct::SumStruct<A, funct::MinusStruct<B> >& f) {
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, const funct::SumStruct<funct::MinusStruct<A>, B>& f) {
84  return cout << "- " << f._1._ << " + " << f._2;
85  }
86 
87  template <typename A, int n>
88  std::ostream& operator<<(std::ostream& cout, const funct::SumStruct<A, funct::Numerical<n> >& f) {
89  return cout << f._1 << (n >= 0 ? " + " : " - ") << ::abs(n);
90  }
91 
92  template <typename A, int n>
93  std::ostream& operator<<(std::ostream& cout, const funct::SumStruct<funct::MinusStruct<A>, funct::Numerical<n> >& f) {
94  return cout << "- " << f._1._ << (n >= 0 ? " + " : " - ") << ::abs(n);
95  }
96 
97 #define PARENTHESES(TMPL1, TMPL2, OP) \
98  template <typename A, typename B, typename C> \
99  std::ostream& operator<<(std::ostream& cout, const funct::TMPL1<funct::TMPL2<A, B>, C>& f) { \
100  return cout << "( " << f._1 << " )" << OP << f._2; \
101  } \
102  \
103  template <typename A, typename B, typename C> \
104  std::ostream& operator<<(std::ostream& cout, const funct::TMPL1<C, funct::TMPL2<A, B> >& f) { \
105  return cout << f._1 << OP << "( " << f._2 << " )"; \
106  } \
107  \
108  template <typename A, typename B, typename C, typename D> \
109  std::ostream& operator<<(std::ostream& cout, const funct::TMPL1<funct::TMPL2<A, B>, funct::TMPL2<C, D> >& f) { \
110  return cout << "( " << f._1 << " )" << OP << "( " << f._2 << " )"; \
111  } \
112  \
113  struct __useless_ignoreme
114 
115 #define PARENTHESES_FRACT(TMPL, OP) \
116  template <int n, int m, typename A> \
117  std::ostream& operator<<(std::ostream& cout, const funct::TMPL<funct::FractionStruct<n, m>, A>& f) { \
118  return cout << "( " << f._1 << " )" << OP << f._2; \
119  } \
120  \
121  template <int n, int m, typename A> \
122  std::ostream& operator<<(std::ostream& cout, const funct::TMPL<A, funct::FractionStruct<n, m> >& f) { \
123  return cout << f._1 << OP << "( " << f._2 << " )"; \
124  } \
125  \
126  template <int n, int m, int k, int l> \
127  std::ostream& operator<<(std::ostream& cout, \
128  const funct::TMPL<funct::FractionStruct<n, m>, funct::FractionStruct<k, l> >& f) { \
129  return cout << "( " << f._1 << " )" << OP << "( " << f._2 << " )"; \
130  } \
131  \
132  template <int n, int m, typename A> \
133  std::ostream& operator<<(std::ostream& cout, \
134  const funct::TMPL<funct::MinusStruct<funct::FractionStruct<n, m> >, A>& f) { \
135  return cout << "( " << f._1 << " )" << OP << f._2; \
136  } \
137  \
138  template <int n, int m, typename A> \
139  std::ostream& operator<<(std::ostream& cout, \
140  const funct::TMPL<A, funct::MinusStruct<funct::FractionStruct<n, m> > >& f) { \
141  return cout << f._1 << OP << "( " << f._2 << " )"; \
142  } \
143  struct __useless_ignoreme
144 
145 #define PARENTHESES_1(TMPL1, TMPL2, OP) \
146  template <typename A, typename B> \
147  std::ostream& operator<<(std::ostream& cout, const funct::TMPL1<funct::TMPL2<A, B> >& f) { \
148  return cout << OP << "( " << f._ << " )"; \
149  } \
150  struct __useless_ignoreme
151 
157 
161 
162  //PARENTHESES_FRACT(ProductStruct, " ");
165 
167  //PARENTHESES_1(MinusStruct, RatioStruct, "-");
168 
169 #undef PARENTHESES
170 #undef PARENTHESES_FRACT
171 #undef PARENTHESES_1
172 
173 } // namespace funct
174 
175 #endif
#define PRINT_UNARY_OPERATOR(TMPL, OP)
Definition: FunctionsIO.h:54
Definition: Abs.h:5
#define PARENTHESES(TMPL1, TMPL2, OP)
Definition: FunctionsIO.h:97
TEMPL(T2) struct Divides B
Definition: Factorize.h:24
#define PARENTHESES_FRACT(TMPL, OP)
Definition: FunctionsIO.h:115
#define PRINT_FUNCTION(FUN, NAME)
Definition: FunctionsIO.h:27
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
#define PARENTHESES_1(TMPL1, TMPL2, OP)
Definition: FunctionsIO.h:145
std::ostream & operator<<(std::ostream &cout, const Expression &e)
Definition: Expression.h:44
#define PRINT_BINARY_OPERATOR(TMPL, OP)
Definition: FunctionsIO.h:46