Jpp  master_rocky-43-ge265d140c
the software that should make you happy
JText.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 
4 #include "TROOT.h"
5 #include "TFile.h"
6 #include "TText.h"
7 
8 #include "Jeep/JContainer.hh"
9 #include "Jeep/JProperties.hh"
10 #include "Jeep/JParser.hh"
11 #include "Jeep/JMessage.hh"
12 
13 
14 /**
15  * Auxiliary data structure for line.
16  */
17 struct JText {
18 
19  /**
20  * Read text from input stream.
21  *
22  * \param in input stream
23  * \param text text
24  * \return input stream
25  */
26  friend inline std::istream& operator>>(std::istream& in, JText& text)
27  {
28  in >> text.x1 >> text.y1;
29 
30  return getline(in, text.text);
31  }
32 
33  /**
34  * Write text to output stream.
35  *
36  * \param out output stream
37  * \param text text
38  * \return output stream
39  */
40  friend inline std::ostream& operator<<(std::ostream& out, const JText& text)
41  {
42  return out << text.x1 << ' ' << text.y1 << ' ' << text.text;
43  }
44 
45  double x1;
46  double y1;
47  std::string text;
48 };
49 
50 
51 /**
52  * \file
53  * Auxiliary program to create TText.
54  * \author mdejong
55  */
56 int main(int argc, char **argv)
57 {
58  using namespace std;
59  using namespace JPP;
60 
61  typedef JContainer< vector<JText> > JParameters_t;
62 
63  string outputFile;
64  JParameters_t parameters;
65  Short_t align = 22;
66  Float_t angle = 0.0;
67  Color_t color = kBlack;
68  Font_t font = 43;
69  Float_t size = 40;
70  int debug;
71 
72  try {
73 
74  JProperties properties;
75 
76  properties.insert(gmake_property(align));
77  properties.insert(gmake_property(angle));
78  properties.insert(gmake_property(color));
79  properties.insert(gmake_property(font));
80  properties.insert(gmake_property(size));
81 
82  JParser<> zap("Auxiliary program to create TText.");
83 
84  zap['o'] = make_field(outputFile);
85  zap['p'] = make_field(parameters, "x1 y1 text");
86  zap['@'] = make_field(properties, "text attributes") = JPARSER::initialised();
87  zap['d'] = make_field(debug) = 1;
88 
89  zap(argc, argv);
90  }
91  catch(const exception &error) {
92  FATAL(error.what() << endl);
93  }
94 
95 
96  TFile out(outputFile.c_str(), "recreate");
97 
98  for (size_t i = 0; i != parameters.size(); ++i) {
99 
100  TText* p = new TText(parameters[i].x1, parameters[i].y1, parameters[i].text.c_str());
101 
102  p->SetTextAlign(align);
103  p->SetTextAngle(angle);
104  p->SetTextColor(color);
105  p->SetTextFont (font);
106  p->SetTextSize (size);
107 
108  out.WriteTObject(p);
109  }
110 
111  out.Write();
112  out.Close();
113 }
Container I/O.
string outputFile
General purpose messaging.
#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
Utility class to parse parameter values.
#define gmake_property(A)
macros to convert (template) parameter to JPropertiesElement object
int main(int argc, char **argv)
Definition: JText.cc:56
Utility class to parse parameter values.
Definition: JProperties.hh:501
Utility class to parse command line options.
Definition: JParser.hh:1698
char text[TEXT_SIZE]
Definition: elog.cc:72
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:478
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JSTDTypes.hh:14
Auxiliary wrapper for I/O of container with optional comment (see JComment).
Definition: JContainer.hh:42
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:68
Auxiliary data structure for line.
Definition: JText.cc:17
friend std::istream & operator>>(std::istream &in, JText &text)
Read text from input stream.
Definition: JText.cc:26
std::string text
Definition: JText.cc:47
friend std::ostream & operator<<(std::ostream &out, const JText &text)
Write text to output stream.
Definition: JText.cc:40
double y1
Definition: JText.cc:46
double x1
Definition: JText.cc:45