Jpp  17.3.0-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPrintTestResults.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 #include <string>
4 
5 #include "Jeep/JPrint.hh"
6 #include "Jeep/JParser.hh"
7 #include "Jeep/JMessage.hh"
8 
9 #include "JLang/JPredicate.hh"
10 #include "JLang/JVectorize.hh"
11 
12 #include "JGizmo/JRootObjectID.hh"
13 
15 
16 #include "TString.h"
17 #include "TRegexp.h"
18 
19 
20 namespace {
21 
22  using namespace JPP;
23 
24  static const std::string& WILDCARD = ".*";
25  static const char COMMENT = '#';
26 
27  /**
28  * Compare a property list with a map of selection criteria.
29  *
30  * \param properties property list
31  * \param selections selection criteria
32  * \return true if properties match all selection criteria; else false
33  */
34  inline bool compare(const JProperties& properties,
35  const std::map<std::string, std::string>& selections)
36  {
37  using namespace std;
38 
39  for (map<string, string>::const_iterator i = selections.begin(); i != selections.end(); ++i) {
40 
41  const TString value(properties.getString(i->first));
42  const TRegexp regexp(i->second);
43 
44  if (!value.Contains(regexp)) {
45  return false;
46  }
47  }
48 
49  return true;
50  }
51 
52 
53  /**
54  * Remove color ASCII code from input stream.
55  *
56  * \param in input stream
57  * \return number of stripped characters
58  */
59  inline size_t stripColor(std::istream& in)
60  {
61  static const char colorStart = '\033';
62  static const char colorEnd = 'm';
63 
64  size_t n = 0;
65 
66  while (in.peek() == (int) colorStart) {
67 
68  while (in.peek() != (int) colorEnd) {
69 
70  in.ignore();
71  ++n;
72  }
73 
74  in.ignore();
75  ++n;
76  }
77 
78  return n;
79  }
80 }
81 
82 
83 /**
84  * \file
85  *
86  * Auxiliary program to print histogram comparison results.
87  * \author bjung
88  */
89 int main(int argc, char **argv)
90 {
91  using namespace std;
92  using namespace JPP;
93 
94  string inputFile;
95 
96  vector<string> keys;
97  map<string, string> selections;
98 
99  int debug;
100 
101  try {
102 
103  JProperties properties;
104 
105  const array_type<string>& listOfKeys = get_keys(JTestSummary().getProperties());
106  const string& keyExplainer = MAKE_STRING("Summary information:" << endl << listOfKeys);
107 
108  for (array_type<string>::const_iterator i = listOfKeys.cbegin(); i != listOfKeys.cend(); ++i) {
109  selections[*i] = WILDCARD;
110  properties[*i] = selections[*i];
111  }
112 
113  JParser<> zap("Auxiliary program to print histogram comparison results.");
114 
115  zap['f'] = make_field(inputFile, "Histogram comparison ASCII output file");
116  zap['k'] = make_field(keys, keyExplainer) = JPARSER::initialised();
117  zap['@'] = make_field(properties, "Selection criteria") = JPARSER::initialised();
118  zap['d'] = make_field(debug) = 3;
119 
120  zap(argc, argv);
121  }
122  catch (const exception &error) {
123  FATAL(error.what() << endl);
124  }
125 
126  ifstream in(inputFile);
127 
128  for (string buffer; getline(in, buffer); ) {
129 
130  istringstream iss(buffer);
131  stripColor(iss);
132 
133  if (iss.peek() == (int) COMMENT) {
134  continue;
135  }
136 
137  JTestSummary summary;
138  read(iss, summary);
139 
140  if (compare(summary.getProperties(), selections)) {
141  print(cout, summary, keys.cbegin(), keys.cend(), ' ', false);
142  }
143  }
144 
145  return 0;
146 }
Utility class to parse command line options.
Definition: JParser.hh:1517
int main(int argc, char *argv[])
Definition: Main.cc:15
std::istream & read(std::istream &in, JTestSummary &summary, const char delimiter= ' ')
Read test summary.
JProperties & getProperties(T &object, const JEquationParameters &parameters=JEquationParameters(), const int debug=1)
Get properties of a given object.
Utility class to parse parameter values.
Definition: JProperties.hh:496
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:83
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:127
JProperties getProperties(const JEquationParameters &equation=JTestSummary::getEquationParameters())
Get properties of this class.
const int n
Definition: JPolint.hh:697
I/O formatting auxiliaries.
std::string getString(const std::string &key) const
Get string value.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
then awk string
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:478
static struct JACOUSTICS::@4 compare
Auxiliary data structure to sort transmissions.
Auxiliary methods to convert data members or return values of member methods of a set of objects to a...
print
Definition: JConvertDusj.sh:44
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.
Class dedicated to standardize the title of the graphical objects produced by the JTest_t() derived c...
Definition: JTestSummary.hh:33
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 data structure for return type of make methods.
Definition: JVectorize.hh:26
const array_type< JKey_t > & get_keys(const std::map< JKey_t, JValue_t, JComparator_t, JAllocator_t > &data)
Method to create array of keys of map.
Definition: JVectorize.hh:139
int debug
debug level