Jpp
JHashCollection.cc
Go to the documentation of this file.
1 
2 #include <iostream>
3 #include <iomanip>
4 #include <cmath>
5 
7 
8 #include "Jeep/JParser.hh"
9 #include "Jeep/JMessage.hh"
10 
11 
12 namespace {
13 
14  /**
15  * Example class to get value for hash key.
16  */
17  struct get_value {
18  /**
19  * Constructor.
20  *
21  * \param precision precision
22  */
23  get_value(const double precision = 1.0)
24  {
25  this->precision = precision;
26  }
27 
28 
29  /*
30  * Function.
31  *
32  * \param key key
33  * \return hash value
34  */
35  inline int operator()(const double key) const
36  {
37  return (int) floor(key / precision);
38  }
39 
40 
41  double precision;
42  };
43 }
44 
45 
46 /**
47  * \file
48  *
49  * Example program to test JTOOLS::JHashCollection class.
50  * \author mdejong
51  */
52 int main(int argc, char **argv)
53 {
54  using namespace std;
55 
56  double precision;
57  int debug;
58 
59  try {
60 
61  JParser<> zap("Example program to test hash collection.");
62 
63  zap['e'] = make_field(precision) = 1.0e-3;
64  zap['d'] = make_field(debug) = 0;
65 
66  zap(argc, argv);
67  }
68  catch(const exception &error) {
69  FATAL(error.what() << endl);
70  }
71 
72 
73  using namespace JPP;
74 
75  typedef JHashCollection<double, get_value> hash_collection;
76 
77  hash_collection buffer(precision);
78 
79  for (double x = 2.0; x >= 1.0; x -= 0.1) {
80  buffer.insert(x);
81  }
82 
83  for (hash_collection::const_iterator i = buffer.begin(); i != buffer.end(); ++i) {
84  cout << *i << endl;
85  }
86 }
JMessage.hh
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JTOOLS::get_value
JResultEvaluator< JResult_t >::result_type get_value(const JResult_t &value)
Helper method to recursively evaluate a to function value.
Definition: JResult.hh:936
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
debug
int debug
debug level
Definition: JSirene.cc:59
JParser.hh
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
JHashCollection.hh
std
Definition: jaanetDictionary.h:36
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
main
int main(int argc, char **argv)
Definition: JHashCollection.cc:52