Jpp  19.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JObject.cc
Go to the documentation of this file.
1 
2 #include <iostream>
3 #include <iomanip>
4 #include <vector>
5 #include <iterator>
6 
7 #include "JLang/JObject.hh"
8 
9 #include "Jeep/JParser.hh"
10 #include "Jeep/JMessage.hh"
11 
12 
13 namespace {
14 
15  using namespace JPP;
16 
18 
19 
20  /**
21  * Example worker class which requires static instance to be processed.
22  */
23  struct __A__ :
24  public JObject<__A__>
25  {
26  __A__(const int N, buffer_type& buffer) :
27  N(N),
28  buffer(buffer)
29  {}
30 
31  void operator()()
32  {
33  for (int i = 0; i != N; ++i) {
34  buffer.push_back(buffer.size());
35  }
36  }
37 
38  int N;
39  buffer_type& buffer;
40  };
41 
42 
43  /**
44  * Process object.
45  */
46  inline void process(__A__& object)
47  {
48  object();
49  }
50 }
51 
52 
53 /**
54  * \file
55  *
56  * Example program to test JLANG::JObject class.
57  * \author mdejong
58  */
59 int main(int argc, char **argv)
60 {
61  using namespace std;
62 
63  int debug;
64 
65  try {
66 
67  JParser<> zap("Example program to test object.");
68 
69  zap['d'] = make_field(debug) = 3;
70 
71  zap(argc, argv);
72  }
73  catch(const exception &error) {
74  FATAL(error.what() << endl);
75  }
76 
77 
78  using namespace JPP;
79 
80  buffer_type buffer;
81 
82  process(__A__(3, buffer).getInstance());
83  process(getInstance(__A__(2, buffer)));
84  //process(__A__(5, buffer)); // compiler error: invalid initialization of non-const reference (as should be)
85 
86  for (buffer_type::const_iterator i = buffer.begin(); i != buffer.end(); ++i) {
87  cout << *i << endl;
88  }
89 }
Utility class to parse command line options.
Definition: JParser.hh:1711
int main(int argc, char *argv[])
Definition: Main.cc:15
std::vector< JHitW0 > buffer_type
hits
Definition: JPerth.cc:70
T & getInstance(const T &object)
Get static instance from temporary object.
Definition: JObject.hh:75
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
Auxiliary base class for inline creation of a static value or clone from a temporary object...
Definition: JObject.hh:18
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
Definition: JMuonPostfit.sh:40
Utility class to parse command line options.
int debug
debug level