Jpp  18.0.1-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JEvent_t.hh
Go to the documentation of this file.
1 #ifndef __JRUNCONTROL_JEVENT_T__
2 #define __JRUNCONTROL_JEVENT_T__
3 
4 #include <string>
5 #include <istream>
6 #include <ostream>
7 #include <sstream>
8 #include <iomanip>
9 
10 #include "JLang/JLangToolkit.hh"
12 
13 
14 /**
15  * \author mdejong
16  */
17 
18 namespace KM3NETDAQ {
19 
20  /**
21  * Auxiliary class for handling event name and optional static information.
22  */
23  struct JEvent_t {
24  /**
25  * Default constructor.
26  */
28  name("?"),
29  info(),
30  more(false)
31  {}
32 
33 
34  /**
35  * Constructor.
36  *
37  * \param name event name
38  */
40  name(name),
41  info(),
42  more(false)
43  {}
44 
45 
46  /**
47  * Constructor.
48  *
49  * \param name event name
50  * \param info event information
51  */
53  const std::string& info) :
54  name(name),
55  info(info),
56  more(true)
57  {}
58 
59 
60  /**
61  * Get event name.
62  *
63  * \return event name
64  */
65  const std::string& getName() const
66  {
67  return name;
68  }
69 
70 
71  /**
72  * Check if this event has information.
73  *
74  * \return true if information is available; else false
75  */
76  bool hasInfo() const
77  {
78  return more;
79  }
80 
81 
82  /**
83  * Get event information.
84  *
85  * \return event information.
86  */
87  const std::string& getInfo() const
88  {
89  return info;
90  }
91 
92 
93  /**
94  * Convert string to event.
95  *
96  * \param buffer buffer
97  * \return event
98  */
99  static JEvent_t toValue(const std::string& buffer)
100  {
101  using namespace std;
102  using namespace JPP;
103 
104  JEvent_t object;
105 
106  const string::size_type sep = buffer.find(EVENTNAME_DELIMETER);
107 
108  if (sep != string::npos) {
109 
110  object.name = trim(buffer.substr(0, sep));
111  object.info = trim(buffer.substr(sep + 1));
112  object.more = true;
113 
114  } else {
115 
116  object.name = trim(buffer);
117  object.info = "";
118  object.more = false;
119  }
120 
121  return object;
122  }
123 
124 
125  /**
126  * Read event name and optional number from input stream.
127  *
128  * \param in input stream
129  * \param object event
130  * \return input stream
131  */
132  friend inline std::istream& operator>>(std::istream& in, JEvent_t& object)
133  {
134  std::string buffer;
135 
136  in >> buffer;
137 
138  object = JEvent_t::toValue(buffer);
139 
140  return in;
141  }
142 
143 
144  /**
145  * Write event to output stream.
146  *
147  * \param out output stream
148  * \param object event
149  * \return output stream
150  */
151  friend inline std::ostream& operator<<(std::ostream& out, const JEvent_t& object)
152  {
153  out << object.name;
154 
155  if (object.more) {
156  out << getEventnameDelimeter() << object.info;
157  }
158 
159  return out;
160  }
161 
162 
163  protected:
166  bool more;
167  };
168 }
169 
170 #endif
const std::string & getName() const
Get event name.
Definition: JEvent_t.hh:65
const std::string & getInfo() const
Get event information.
Definition: JEvent_t.hh:87
JEvent_t(const std::string &name)
Constructor.
Definition: JEvent_t.hh:39
static const char EVENTNAME_DELIMETER
Definition: JDAQTags.hh:49
bool hasInfo() const
Check if this event has information.
Definition: JEvent_t.hh:76
static JEvent_t toValue(const std::string &buffer)
Convert string to event.
Definition: JEvent_t.hh:99
std::string trim(const std::string &buffer)
Trim string.
Definition: JLangToolkit.hh:79
then awk string
Auxiliary class for handling event name and optional static information.
Definition: JEvent_t.hh:23
friend std::istream & operator>>(std::istream &in, JEvent_t &object)
Read event name and optional number from input stream.
Definition: JEvent_t.hh:132
char getEventnameDelimeter()
Get the event name delimeter.
JEvent_t()
Default constructor.
Definition: JEvent_t.hh:27
friend std::ostream & operator<<(std::ostream &out, const JEvent_t &object)
Write event to output stream.
Definition: JEvent_t.hh:151
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
JEvent_t(const std::string &name, const std::string &info)
Constructor.
Definition: JEvent_t.hh:52
std::string info
Definition: JEvent_t.hh:165
std::string name
Definition: JEvent_t.hh:164