Jpp
JZero.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 
4 #include "JMath/JZero.hh"
5 
6 #include "Jeep/JParser.hh"
7 #include "Jeep/JMessage.hh"
8 
9 
10 namespace {
11 
12  struct __A__ {
13  /**
14  * Default constructor.
15  */
16  __A__() :
17  a(0)
18  {}
19 
20  /**
21  * Constructor.
22  *
23  * \param a value
24  */
25  __A__(double a)
26  {
27  this->a = a;
28  }
29 
30  /**
31  * Equals operator.
32  *
33  * \param first first value
34  * \param second second value
35  * \return true if first and second value are equal; else false
36  */
37  friend inline bool operator==(const __A__& first, const __A__& second)
38  {
39  return first.a == second.a;
40  }
41 
42  /**
43  * Write object to output.
44  *
45  * \param out output stream
46  * \param object object
47  * \return output stream
48  */
49  friend inline std::ostream& operator<<(std::ostream& out, const __A__& object)
50  {
51  return out << object.a;
52  }
53 
54  double a;
55  };
56 
57  /**
58  * Test equaliilty.
59  *
60  * \param zero zero value
61  * \return true if JMath::zero equals given zero value; else false
62  */
63  template<class T>
64  bool inline is_equal(const T& zero)
65  {
66  T value = JMATH::zero;
67 
68  return value == zero;
69  }
70 
71  /**
72  * Print class and zero value.
73  *
74  * \param out output stream
75  * \param name class name
76  */
77  template<class T>
78  inline void print(std::ostream& out, const char* name)
79  {
80  using namespace std;
81 
82  T value = JMATH::zero;
83 
84  out << setw(12) << left << name << ' ' << value << endl;
85  }
86 
87 #define PRINT(OUT, CLASS) print<CLASS>(OUT, #CLASS)
88 }
89 
90 
91 /**
92  * \file
93  *
94  * Example program to test zero values (JMATH::zero).
95  * \author mdejong
96  */
97 int main(int argc, char**argv)
98 {
99  using namespace std;
100 
101  int debug;
102 
103  try {
104 
105  JParser<> zap("Example program to test zero values of non-primitive data types.");
106 
107  zap['d'] = make_field(debug) = 3;
108 
109  zap(argc, argv);
110  }
111  catch(const exception &error) {
112  FATAL(error.what() << endl);
113  }
114 
115  using namespace JPP;
116 
117  PRINT(cout, int);
118  PRINT(cout, float);
119  PRINT(cout, double);
120  PRINT(cout, __A__);
121 
122  ASSERT(is_equal<int> (0));
123  ASSERT(is_equal<float> (0.0));
124  ASSERT(is_equal<double>(0.0));
125  ASSERT(is_equal<__A__> (__A__(0)));
126 
127  return 0;
128 }
JMessage.hh
ASSERT
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
JZero.hh
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
operator==
bool operator==(Packet const &p, ID const &id)
Definition: raw_data_converter.cpp:48
debug
int debug
debug level
Definition: JSirene.cc:59
operator<<
std::ostream & operator<<(std::ostream &stream, const CLBCommonHeader &header)
Definition: clb_common_header.hh:72
JParser.hh
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
main
int main(int argc, char **argv)
Definition: JZero.cc:97
std
Definition: jaanetDictionary.h:36
JMATH::zero
static const JZero zero
Function object to assign zero value.
Definition: JZero.hh:94
print
void print(const TH1 &h1, std::ostream &out)
Print histogram parameters.
Definition: JTriggerMonitor.cc:38
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
PRINT
#define PRINT(OUT, CLASS)
Definition: JZero.cc:87