Jpp
JLimits.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 #include <limits>
4 
5 #include "JMath/JLimits.hh"
6 
7 #include "Jeep/JParser.hh"
8 #include "Jeep/JMessage.hh"
9 
10 
11 namespace {
12 
13  static const double A_MIN = -999.0;
14  static const double A_MAX = +999.0;
15 
16  struct __A__ {
17  /**
18  * Constructor.
19  *
20  * \param a value
21  */
22  __A__(double a)
23  {
24  this->a = a;
25  }
26 
27  /**
28  * Equals operator.
29  *
30  * \param first first value
31  * \param second second value
32  * \return true if first and second value are equal; else false
33  */
34  friend inline bool operator==(const __A__& first, const __A__& second)
35  {
36  return first.a == second.a;
37  }
38 
39  /**
40  * Write object to output.
41  *
42  * \param out output stream
43  * \param object object
44  * \return output stream
45  */
46  friend inline std::ostream& operator<<(std::ostream& out, const __A__& object)
47  {
48  return out << object.a;
49  }
50 
51  static __A__ min() { return __A__(A_MIN); }
52  static __A__ max() { return __A__(A_MAX); }
53 
54  protected:
55  double a;
56  };
57 
58 
59  /**
60  * Print class and zero value.
61  *
62  * \param out output stream
63  * \param name class name
64  */
65  template<class T>
66  inline void print(std::ostream& out, const char* name)
67  {
68  using namespace std;
69  using namespace JPP;
70 
71  out << setw(12) << left << name << ' ' << JLimits<T>::min() << ' ' << JLimits<T>::max() << endl;
72  }
73 
74 #define PRINT(OUT, CLASS) print<CLASS>(OUT, #CLASS)
75 }
76 
77 
78 /**
79  * \file
80  *
81  * Example program to test zero values (JMATH::zero).
82  * \author mdejong
83  */
84 int main(int argc, char**argv)
85 {
86  using namespace std;
87 
88  int debug;
89 
90  try {
91 
92  JParser<> zap("Example program to test zero values of non-primitive data types.");
93 
94  zap['d'] = make_field(debug) = 3;
95 
96  zap(argc, argv);
97  }
98  catch(const exception &error) {
99  FATAL(error.what() << endl);
100  }
101 
102  using namespace JPP;
103 
104  PRINT(cout, size_t);
105  PRINT(cout, int);
106  PRINT(cout, float);
107  PRINT(cout, double);
108  PRINT(cout, long double);
109  PRINT(cout, __A__);
110 
111  ASSERT(JLimits<size_t>::min() == numeric_limits<size_t>::min());
112  ASSERT(JLimits<size_t>::max() == numeric_limits<size_t>::max());
113  //ASSERT(JLimits<double>::min() == numeric_limits<double>::min());
114  ASSERT(JLimits<double>::max() == numeric_limits<double>::max());
115  ASSERT(JLimits<__A__> ::min() == A_MIN);
116  ASSERT(JLimits<__A__> ::max() == A_MAX);
117 
118  return 0;
119 }
JLimits.hh
JMessage.hh
ASSERT
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
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
main
int main(int argc, char **argv)
Definition: JLimits.cc:84
JParser.hh
PRINT
#define PRINT(OUT, CLASS)
Definition: JLimits.cc:74
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
std
Definition: jaanetDictionary.h:36
print
void print(const TH1 &h1, std::ostream &out)
Print histogram parameters.
Definition: JTriggerMonitor.cc:38
FATAL
#define FATAL(A)
Definition: JMessage.hh:67