CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/PhysicsTools/Utilities/interface/FunctionsIO.h

Go to the documentation of this file.
00001 #ifndef PhysicsTools_Utilities_interface_FunctionsIO_h
00002 #define PhysicsTools_Utilities_interface_FunctionsIO_h
00003 #include "PhysicsTools/Utilities/interface/Variables.h"
00004 #include "PhysicsTools/Utilities/interface/Numerical.h"
00005 #include "PhysicsTools/Utilities/interface/Fraction.h"
00006 #include "PhysicsTools/Utilities/interface/Functions.h"
00007 #include "PhysicsTools/Utilities/interface/Operations.h"
00008 #include <ostream>
00009 
00010 namespace funct {
00011 
00012 template<int n>
00013 std::ostream& operator<<(std::ostream& cout, const Numerical<n>&) {
00014   return cout << n;
00015 }
00016 
00017 template<int n, int m>
00018 std::ostream& operator<<(std::ostream& cout, const funct::FractionStruct<n, m> &) { 
00019   return cout << n << "/" << m; 
00020 }
00021 
00022 template<int n, int m>
00023 std::ostream& operator<<(std::ostream& cout, 
00024                          const funct::MinusStruct<funct::FractionStruct<n, m> >&) {
00025   return cout << "-" << n << "/" << m; 
00026 }
00027 
00028 #define PRINT_FUNCTION(FUN, NAME) \
00029 template<typename T> \
00030 std::ostream& operator<<(std::ostream& cout, const funct::FUN<T> & f) { \
00031   return cout << NAME << "(" << f._ << ")"; \
00032 } \
00033  \
00034 struct __useless_ignoreme
00035 
00036 PRINT_FUNCTION(SqrtStruct, "sqrt");
00037 PRINT_FUNCTION(ExpStruct, "exp");
00038 PRINT_FUNCTION(LogStruct, "log");
00039 PRINT_FUNCTION(SinStruct, "sin");
00040 PRINT_FUNCTION(CosStruct, "cos");
00041 PRINT_FUNCTION(TanStruct, "tan");
00042 PRINT_FUNCTION(SgnStruct, "sgn");
00043 PRINT_FUNCTION(AbsStruct, "abs");
00044 
00045 #undef PRINT_FUNCTION
00046 
00047 #define PRINT_BINARY_OPERATOR(TMPL, OP) \
00048 template<typename A, typename B> \
00049 std::ostream& operator<<(std::ostream& cout, const funct::TMPL <A, B> & f) \
00050 { return cout << f._1 << OP << f._2; } \
00051  \
00052 struct __useless_ignoreme
00053 
00054 #define PRINT_UNARY_OPERATOR(TMPL, OP) \
00055 template<typename A> \
00056 std::ostream& operator<<(std::ostream& cout, const funct::TMPL <A> & f) \
00057 { return cout << OP << f._; } \
00058  \
00059 struct __useless_ignoreme
00060 
00061 PRINT_BINARY_OPERATOR(SumStruct, " + ");
00062 PRINT_BINARY_OPERATOR(ProductStruct, " ");
00063 PRINT_BINARY_OPERATOR(RatioStruct, "/");
00064 PRINT_BINARY_OPERATOR(PowerStruct, "^");
00065 PRINT_UNARY_OPERATOR(MinusStruct, "-");
00066 
00067 #undef PRINT_BINARY_OPERATOR
00068 #undef PRINT_UNARY_OPERATOR
00069 
00070 template<typename A, typename B>
00071 std::ostream& operator<<(std::ostream& cout, 
00072                          const funct::SumStruct<A, funct::MinusStruct<B> > & f) { 
00073   return cout << f._1 << " - " << f._2._; 
00074 }
00075 
00076 template<typename A, typename B>
00077 std::ostream& operator<<(std::ostream& cout, 
00078                          const funct::SumStruct<funct::MinusStruct<A>, funct::MinusStruct<B> > & f) { 
00079   return cout << "- " << f._1._ << " - " << f._2._; 
00080 }
00081 
00082 template<typename A, typename B>
00083 std::ostream& operator<<(std::ostream& cout, 
00084                          const funct::SumStruct<funct::MinusStruct<A>, B> & f) { 
00085   return cout << "- " << f._1._ << " + " << f._2; 
00086 }
00087 
00088 template<typename A, int n>
00089 std::ostream& operator<<(std::ostream& cout, 
00090                          const funct::SumStruct<A, funct::Numerical<n> > & f) { 
00091   return cout << f._1 << (n >= 0 ? " + " : " - ") << ::abs(n); 
00092 }
00093 
00094 template<typename A, int n>
00095 std::ostream& operator<<( std::ostream& cout, 
00096                           const funct::SumStruct<funct::MinusStruct<A>, funct::Numerical<n> > & f) { 
00097   return cout << "- " << f._1._ << (n >= 0 ? " + " : " - ") << ::abs(n); 
00098 }
00099 
00100 #define PARENTHESES(TMPL1, TMPL2, OP) \
00101 template<typename A, typename B, typename C> \
00102 std::ostream& operator<<(std::ostream& cout, \
00103                          const funct::TMPL1<funct::TMPL2<A, B>, C> & f) { \
00104   return cout << "( " << f._1 << " )" << OP << f._2; \
00105 } \
00106  \
00107 template<typename A, typename B, typename C> \
00108 std::ostream& operator<<(std::ostream& cout, \
00109                          const funct::TMPL1<C, funct::TMPL2<A, B> > & f) { \
00110   return cout << f._1 << OP << "( " << f._2 << " )"; \
00111 } \
00112  \
00113 template<typename A, typename B, typename C, typename D> \
00114 std::ostream& operator<<(std::ostream& cout, \
00115                         const funct::TMPL1<funct::TMPL2<A, B>, \
00116                                            funct::TMPL2<C, D> > & f) { \
00117   return cout << "( " << f._1 << " )" << OP << "( " << f._2 << " )"; \
00118 } \
00119  \
00120 struct __useless_ignoreme
00121 
00122 #define PARENTHESES_FRACT(TMPL, OP) \
00123 template<int n, int m, typename A> \
00124 std::ostream& operator<<(std::ostream& cout, \
00125                          const funct::TMPL<funct::FractionStruct<n, m>, A> & f ) { \
00126   return cout << "( " << f._1 << " )" << OP << f._2; \
00127  } \
00128  \
00129 template<int n, int m, typename A> \
00130 std::ostream& operator<<(std::ostream& cout, \
00131                          const funct::TMPL<A, funct::FractionStruct<n, m> > & f) { \
00132   return cout << f._1 << OP << "( " << f._2 << " )"; } \
00133  \
00134 template<int n, int m, int k, int l> \
00135 std::ostream& operator<<(std::ostream& cout, \
00136                          const funct::TMPL<funct::FractionStruct<n, m>, \
00137                                            funct::FractionStruct<k, l> > & f) { \
00138   return cout << "( " << f._1 << " )" << OP << "( " << f._2 << " )"; \
00139 } \
00140  \
00141 template<int n, int m, typename A> \
00142 std::ostream& operator<<(std::ostream& cout, \
00143                          const funct::TMPL<funct::MinusStruct<funct::FractionStruct<n, m> >, A> & f) { \
00144   return cout << "( " << f._1 << " )" << OP << f._2; \
00145 } \
00146  \
00147 template<int n, int m, typename A> \
00148 std::ostream& operator<<(std::ostream& cout, \
00149                          const funct::TMPL<A, funct::MinusStruct<funct::FractionStruct<n, m> > > & f) { \
00150   return cout << f._1 << OP << "( " << f._2 << " )"; \
00151 } \
00152 struct __useless_ignoreme
00153 
00154 #define PARENTHESES_1(TMPL1, TMPL2, OP) \
00155 template<typename A, typename B> \
00156 std::ostream& operator<<(std::ostream& cout, \
00157                          const funct::TMPL1<funct::TMPL2<A, B> > & f) { \
00158   return cout << OP << "( " << f._ << " )"; \
00159 } \
00160 struct __useless_ignoreme
00161 
00162 PARENTHESES(ProductStruct, SumStruct, " ");
00163 PARENTHESES(ProductStruct, RatioStruct, " ");
00164 PARENTHESES(RatioStruct, SumStruct, "/");
00165 PARENTHESES(RatioStruct, ProductStruct, "/");
00166 PARENTHESES(RatioStruct, RatioStruct, "/");
00167 
00168 PARENTHESES(PowerStruct, SumStruct, "^");
00169 PARENTHESES(PowerStruct, ProductStruct, "^");
00170 PARENTHESES(PowerStruct, RatioStruct, "^");
00171 
00172 //PARENTHESES_FRACT(ProductStruct, " ");
00173 PARENTHESES_FRACT(RatioStruct, "/");
00174 PARENTHESES_FRACT(PowerStruct, "^");
00175 
00176 PARENTHESES_1(MinusStruct, SumStruct, "-");
00177 //PARENTHESES_1(MinusStruct, RatioStruct, "-");
00178 
00179 #undef PARENTHESES
00180 #undef PARENTHESES_FRACT
00181 #undef PARENTHESES_1
00182 
00183 }
00184 
00185 #endif