#ifndef __JRUNCONTROL_JEVENT_T__ #define __JRUNCONTROL_JEVENT_T__ #include #include #include #include #include #include "JLang/JLangToolkit.hh" #include "JRuncontrol/JRuncontrolToolkit.hh" /** * \author mdejong */ namespace KM3NETDAQ { /** * Auxiliary class for handling event name and optional static information. */ struct JEvent_t { /** * Default constructor. */ JEvent_t() : name("?"), info(), more(false) {} /** * Constructor. * * \param name event name */ JEvent_t(const std::string& name) : name(name), info(), more(false) {} /** * Constructor. * * \param name event name * \param info event information */ JEvent_t(const std::string& name, const std::string& info) : name(name), info(info), more(true) {} /** * Get event name. * * \return event name */ const std::string& getName() const { return name; } /** * Check if this event has information. * * \return true if information is available; else false */ bool hasInfo() const { return more; } /** * Get event information. * * \return event information. */ const std::string& getInfo() const { return info; } /** * Convert string to event. * * \param buffer buffer * \return event */ static JEvent_t toValue(const std::string& buffer) { using namespace std; using namespace JPP; JEvent_t object; const string::size_type sep = buffer.find(EVENTNAME_DELIMETER); if (sep != string::npos) { object.name = trim(buffer.substr(0, sep)); object.info = trim(buffer.substr(sep + 1)); object.more = true; } else { object.name = trim(buffer); object.info = ""; object.more = false; } return object; } /** * Read event name and optional number from input stream. * * \param in input stream * \param object event * \return input stream */ friend inline std::istream& operator>>(std::istream& in, JEvent_t& object) { std::string buffer; in >> buffer; object = JEvent_t::toValue(buffer); return in; } /** * Write event to output stream. * * \param out output stream * \param object event * \return output stream */ friend inline std::ostream& operator<<(std::ostream& out, const JEvent_t& object) { out << object.name; if (object.more) { out << getEventnameDelimeter() << object.info; } return out; } protected: std::string name; std::string info; bool more; }; } #endif