Jpp  19.1.0
the software that should make you happy
JPrintProperties.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include <iomanip>
4 #include <string>
5 #include <vector>
6 #include <set>
7 #include <map>
8 
10 #include "JLang/JEquation.hh"
11 
12 #include "Jeep/JProperties.hh"
13 #include "Jeep/JComment.hh"
14 #include "Jeep/JParser.hh"
15 #include "Jeep/JMessage.hh"
16 
17 /**
18  * \file
19  *
20  * General purpose program to print properties file.
21  * \author mdejong
22  */
23 int main(int argc, char **argv)
24 {
25  using namespace std;
26  using namespace JPP;
27 
28  string inputFile;
29  JEquationParameters parameters("=", ";\n", "", "#");
30  set<string> key;
31  int debug;
32 
33  try {
34 
35  JProperties properties;
36 
37  properties["sep"] = parameters.getSeparator();
38  properties["eol"] = parameters.getEndOfLine();
39  properties["div"] = parameters.getDivision();
40  properties["skip"] = parameters.getSkipLine();
41  properties["left"] = parameters.getLeftBracket();
42  properties["right"] = parameters.getRightBracket();
43  properties["ws"] = parameters.getWhiteSpace();
44  properties["cc"] = parameters.getComment();
45 
46  JParser<> zap("General purpose program to print properties file.");
47 
48  zap['f'] = make_field(inputFile);
49  zap['@'] = make_field(properties) = JPARSER::initialised();
50  zap['k'] = make_field(key, "key");
51  zap['d'] = make_field(debug, "debug level") = 2;
52 
53  zap(argc, argv);
54  }
55  catch(const exception &error) {
56  FATAL(error.what() << endl);
57  }
58 
59 
60  JComment comment;
61 
62  const JEquationFacet facet(parameters);
63 
64  // input
65 
66  ifstream in(inputFile.c_str());
67 
68  in >> comment;
69 
70  in.imbue(locale(in.getloc(), facet.clone()));
71 
72  for (JEquation equation; in >> equation; ) {
73 
74  DEBUG(equation << endl);
75 
76  for (const auto& i : key) {
77 
78  if (equation.getKey().find(i) == 0) {
79  cout << ' ' << equation.getValue();
80  }
81  }
82  }
83 
84  in.close();
85 }
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
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.
Utility class to parse parameter values.
Definition: JProperties.hh:501
Facet class to specify parsing of equations in currect locale (see class JLANG::JEquation).
virtual JEquationFacet * clone() const override
Clone this facet.
Simple data structure to support I/O of equations (see class JLANG::JEquation).
const std::string & getEndOfLine() const
Get end of line characters.
const std::string & getWhiteSpace() const
Get white space characters.
const std::string & getComment() const
Get comment string.
const std::string & getSeparator() const
Get separator characters.
char getLeftBracket() const
Get left bracket.
const std::string & getSkipLine() const
Get skip line characters.
const std::string & getDivision() const
Get division characters.
char getRightBracket() const
Get right bracket.
General purpose equation class.
Definition: JEquation.hh:47
Utility class to parse command line options.
Definition: JParser.hh:1698
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JSTDTypes.hh:14
Auxiliary class for comment.
Definition: JComment.hh:43
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:68