Jpp  17.3.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
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  * \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  */
125 int 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 }
Utility class to parse command line options.
Definition: JParser.hh:1517
bool read(const JEquation &equation)
Read equation.
Definition: JProperties.hh:677
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
JFormat_t & getFormat()
Get format for given type.
Definition: JManip.hh:680
Utility class to parse parameter values.
Definition: JProperties.hh:496
Simple data structure to support I/O of equations (see class JLANG::JEquation).
is
Definition: JDAQCHSM.chsm:167
Utility class to parse parameter values.
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
std::ostream & write(std::ostream &out) const
Write the current parameter values.
Definition: JProperties.hh:845
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
then JCalibrateToT a
Definition: JTuneHV.sh:116
then awk string
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
$WORKDIR ev_configure_dqsimulator txt echo process $DQ_SIMULATOR $i $SOURCE_HOST[$index] csh c(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&($DQ_SIMULATOR\-u\$NAME\$\-H\$SERVER\$\-M\$LOGGER\$\-d $DEBUG</dev/null > &/dev/null &))'
std::istream & operator>>(std::istream &in, JAANET::JHead &header)
Read header from input.
Definition: JHead.hh:1756
then JMuonMCEvt f $INPUT_FILE o $INTERMEDIATE_FILE d
Definition: JMuonPath.sh:47
Utility class to parse command line options.
std::ostream & operator<<(std::ostream &stream, const CLBCommonHeader &header)
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
Auxiliary class to define value, reference and pointer types for given data type and category...
Definition: JCategory.hh:18
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62