#ifndef __JDETECTOR__JLOCATION__ #define __JDETECTOR__JLOCATION__ #include #include #include #include #include "JLang/JComparable.hh" #include "JLang/JString.hh" #include "JIO/JSerialisable.hh" #include "Jeep/JPrint.hh" /** * \file * * Logical location of module. * \author mdejong */ namespace JDETECTOR {} namespace JPP { using namespace JDETECTOR; } namespace JDETECTOR { using JLANG::JComparable; using JIO::JReader; using JIO::JWriter; /** * Logical location of module. * * The logical location of a module consists of a string and floor number.\n * This class implements the JLANG::JComparable interface. */ class JLocation : public JComparable { public: /** * Default constructor. */ JLocation() : string(-1), floor (-1) {} /** * Constructor. * * \param string string * \param floor floor */ JLocation(const int string, const int floor) { this->string = string; this->floor = floor; } /** * Get location. * * \return location */ const JLocation& getLocation() const { return static_cast(*this); } /** * Get location. * * \return location */ JLocation& getLocation() { return static_cast(*this); } /** * Set location. * * \param location location */ void setLocation(const JLocation& location) { static_cast(*this) = location; } /** * Convert module location to string. * * \return string */ std::string toString() const { return toString("% %"); } /** * Convert module loation to string. * * The targets target in the format string fmt are * consecutively replaced by floor and string. * * \param fmt format * \param target target * \return string */ std::string toString(const std::string& fmt, const std::string target = "%") const { JLANG::JString buffer(fmt); buffer.replace(target, string, 1); buffer.replace(target, floor, 1); return buffer; } /** * Get string number. * * \return string number */ int getString() const { return string; } /** * Get floor number. * * \return floor number */ int getFloor() const { return floor; } /** * Less than method. * * \param location module location * \result true if first location before second location; else false */ bool less(const JLocation& location) const { if (this->getString() == location.getString()) return this->getFloor() < location.getFloor(); else return this->getString() < location.getString(); } /** * Read module location from input. * * \param in input stream * \param location module location * \return input stream */ friend inline std::istream& operator>>(std::istream& in, JLocation& location) { in >> location.string; in >> location.floor; return in; } /** * Write module location to output. * * \param out output stream * \param location module location * \return output stream */ friend inline std::ostream& operator<<(std::ostream& out, const JLocation& location) { using namespace std; out << setw(4) << location.string; out << ' '; out << setw(2) << location.floor; return out; } /** * Read module location from input. * * \param in reader * \param location module location * \return reader */ friend inline JReader& operator>>(JReader& in, JLocation& location) { in >> location.string; in >> location.floor; return in; } /** * Write module location to output. * * \param out writer * \param location module location * \return writer */ friend inline JWriter& operator<<(JWriter& out, const JLocation& location) { out << location.string; out << location.floor; return out; } protected: int string; int floor; }; /** * Get module label for monitoring and other applications.\n * The format is "(XXXX,YY)", where XXXX is the string number and YY the floor. * * \param location module location * \return label */ inline std::string getLabel(const JLocation& location) { using namespace std; using namespace JPP; return MAKE_STRING("(" << FILL(4,'0') << location.getString() << "." << FILL(2,'0') << location.getFloor() << ")"); } } #endif