Jpp  15.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JProperties-setValue.cc
Go to the documentation of this file.
1 
2 #include <iostream>
3 #include <iomanip>
4 
5 #include "JLang/JCategory.hh"
6 #include "Jeep/JProperties.hh"
7 #include "Jeep/JParser.hh"
8 #include "Jeep/JMessage.hh"
9 
10 
11 namespace {
12 
13  using namespace JPP;
14 
15 
16  /**
17  * Test data structure.
18  */
19  struct JABC {
20  /**
21  * Constructor.
22  *
23  * \param a a
24  * \param b b
25  * \param c c
26  */
27  JABC(const double a,
28  const double b,
29  const double c)
30  {
31  this->a = a;
32  this->b = b;
33  this->c = c;
34  }
35 
36  double a;
37  double b;
38  double c;
39 
40  /**
41  * Get properties of this class.
42  *
43  * \param object test data
44  * \param equation equation parameters
45  */
46  template<bool is_const>
48  const JEquationParameters& equation = JEquationParameters("=", "\n;", "./", "#"),
49  const int debug = 0)
50  {
51  JProperties properties(equation, debug);
52 
53  properties.insert(gmake_property(object.a));
54  properties.insert(gmake_property(object.b));
55  properties.insert(gmake_property(object.c));
56 
57  return properties;
58  }
59  };
60 }
61 
62 /**
63  * \file
64  * Example program to test JPROPERTIES::JProperties class.
65  * \author mdejong
66  */
67 int main(int argc, char **argv)
68 {
69  using namespace std;
70 
71  int debug;
72 
73  try {
74 
75  JParser<> zap;
76 
77  zap['d'] = make_field(debug) = 3;
78 
79  zap(argc, argv);
80  }
81  catch(const exception &error) {
82  FATAL(error.what() << endl);
83  }
84 
85  double a = 1.0;
86  double b = 2.0;
87  double c = 3.0;
88 
89  JABC test(a, b, c);
90 
91  getProperties(test).getValue<double>("a") *= a;
92  getProperties(test).setValue<double>("b", 111.0);
93  getProperties(test).getValue<double>("c") += c;
94 
95  ASSERT(test.a == a*a);
96  ASSERT(test.b == 111.0);
97  ASSERT(test.c == 2*c);
98 
99  return 0;
100 }
Utility class to parse command line options.
Definition: JParser.hh:1500
int main(int argc, char *argv[])
Definition: Main.cc:15
JProperties & getProperties(T &object, const JEquationParameters &parameters=JEquationParameters(), const int debug=1)
Get properties of a given object.
#define gmake_property(A)
macro to convert (template) parameter to JPropertiesElement object
Utility class to parse parameter values.
Definition: JProperties.hh:496
Simple data structure to support I/O of equations (see class JLANG::JEquation).
Utility class to parse parameter values.
const T & getValue(const std::string &key) const
Get value.
Definition: JProperties.hh:974
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int debug
debug level
Definition: JSirene.cc:63
General purpose messaging.
void setValue(const std::string &key, const T &value)
Set value.
#define FATAL(A)
Definition: JMessage.hh:67
then JCalibrateToT a
Definition: JTuneHV.sh:116
Utility class to parse command line options.
Auxiliary class to define value, reference and pointer types for given data type and category...
Definition: JCategory.hh:18