Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JProperties-sed.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
11namespace {
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 * \param d d
27 * \param e e
28 */
29 JABC(const int a,
30 const int b,
31 const int c,
32 const int d,
33 const int e)
34 {
35 this->a = a;
36 this->b = b;
37 this->c = c;
38 this->d = d;
39 this->e = e;
40 }
41
42 int a;
43 int b;
44 int c;
45 int d;
46 int e;
47
48 /**
49 * Get equation parameters.
50 *
51 * \return equation parameters
52 */
53 static inline JEquationParameters& getEquationParameters()
54 {
55 static JEquationParameters equation("=", "\n;", "./", "#");
56
57 return equation;
58 }
59
60 /**
61 * Get format.
62 *
63 * \return equation parameters
64 */
65 static inline std::string& getFormat()
66 {
67 static std::string format("a b c d e");
68
69 return format;
70 }
71
72 /**
73 * Get properties of this class.
74 *
75 * \param object test data
76 * \param equation equation parameters
77 */
78 template<bool is_const>
80 const JEquationParameters& equation = JABC::getEquationParameters(),
81 const int debug = 0)
82 {
83 JProperties properties(equation, debug);
84
85 properties.insert(gmake_property(object.a));
86 properties.insert(gmake_property(object.b));
87 properties.insert(gmake_property(object.c));
88 properties.insert(gmake_property(object.d));
89 properties.insert(gmake_property(object.e));
90
91 return properties;
92 }
93
94 /**
95 * Stream input of test data.
96 *
97 * \param in input stream
98 * \param object test data
99 * \return input stream
100 */
101 friend inline std::istream& operator>>(std::istream& in, JABC& object)
102 {
103 return JEEP::getProperties(object, getEquationParameters(), 1).read(in, getFormat());
104 }
105
106 /**
107 * Stream output of test data.
108 *
109 * \param out output stream
110 * \param object test data
111 * \return output stream
112 */
113 friend inline std::ostream& operator<<(std::ostream& out, const JABC& object)
114 {
115 return JEEP::getProperties(object, getEquationParameters(), 1).write(out, getFormat());
116 }
117 };
118}
119
120/**
121 * \file
122 * Example program to test JPROPERTIES::JProperties class.
123 * \author mdejong
124 */
125int main(int argc, char **argv)
126{
127 using namespace std;
128
129 string buffer;
130 string format;
131 int debug;
132
133 try {
134
135 JParser<> zap;
136
137 zap['f'] = make_field(buffer);
138 zap['F'] = make_field(format);
139 zap['d'] = make_field(debug) = 3;
140
141 zap(argc, argv);
142 }
143 catch(const exception &error) {
144 FATAL(error.what() << endl);
145 }
146
147
148 JABC test(10, 20, 30, 40, 50);
149
150 ASSERT(buffer != "");
151 ASSERT(format != "");
152
153 DEBUG("test: " << endl);
154 DEBUG(getProperties(test));
155
156 DEBUG("processing " << buffer << endl);
157
158 istringstream is(buffer);
159
160 is >> getProperties(test);
161
162 DEBUG("test: " << endl);
163 DEBUG(getProperties(test));
164
165 DEBUG("format " << format << endl);
166
167 JProperties properties = getProperties(test);
168
169 DEBUG("--> " << properties.sed(format, "%") << endl);
170
171 // output for test
172
173 cout << properties.sed(format, "%") << flush;
174
175 return 0;
176}
JFormat_t & getFormat()
Get format for given type.
Definition JManip.hh:682
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define ASSERT(A,...)
Assert macro.
Definition JMessage.hh:90
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
int main(int argc, char **argv)
Utility class to parse parameter values.
#define gmake_property(A)
macros to convert (template) parameter to JPropertiesElement object
Utility class to parse parameter values.
std::ostream & write(std::ostream &out) const
Write the current parameter values.
std::string sed(const std::string &format, const std::string &prefix="", const std::string &postfix="")
Stream editing of input format.
bool read(const JEquation &equation)
Read equation.
Simple data structure to support I/O of equations (see class JLANG::JEquation).
Utility class to parse command line options.
Definition JParser.hh:1698
const double a
std::istream & operator>>(std::istream &in, JAHRSCalibration &calibration)
Read AHRS calibration from input stream.
std::ostream & operator<<(std::ostream &out, const JAHRSCalibration &calibration)
Write AHRS calibration to output stream.
JProperties & getProperties(T &object, const JEquationParameters &parameters=JEquationParameters(), const int debug=1)
Get properties of a given object.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary class to define value, reference and pointer types for given data type and category.
Definition JCategory.hh:18