Jpp  15.0.5
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 }
Utility class to parse command line options.
Definition: JParser.hh:1500
int main(int argc, char *argv[])
Definition: Main.cc:15
then echo Enter input within $TIMEOUT_S seconds echo n User name
Definition: JCookie.sh:42
static const JZero zero
Function object to assign zero value.
Definition: JZero.hh:105
Definition of zero value for any class.
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
#define PRINT(OUT, CLASS)
Definition: JZero.cc:87
bool operator==(Packet const &p, ID const &id)
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
do set_variable OUTPUT_DIRECTORY $WORKDIR T
int debug
debug level
Definition: JSirene.cc:63
print
Definition: JConvertDusj.sh:44
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
then JCalibrateToT a
Definition: JTuneHV.sh:116
Utility class to parse command line options.
std::ostream & operator<<(std::ostream &stream, const CLBCommonHeader &header)