#ifndef __JDB__JPBS_T__ #define __JDB__JPBS_T__ #include #include #include #include #include #include /** * \author mdejong */ namespace JDATABASE {} namespace JPP { using namespace JDATABASE; } namespace JDATABASE { /** * Product breakdown structure (%PBS). * * The %PBS consists of one (or more) integer value(s), separated by JPBS_t::DOT.\n * The corresponding ASCII format reads \"\[.\]*\". */ struct JPBS_t : public std::vector { /** * Separator between %PBS values. */ static const char DOT = '.'; /** * Default constructor. */ JPBS_t() {} /** * Constructor. * * Note that the parsing of arguments terminates at the first occurrence of a negative value. * * \param i0 %PBS number * \param i1 %PBS number * \param i2 %PBS number * \param i3 %PBS number * \param i4 %PBS number * \param i5 %PBS number * \param i6 %PBS number * \param i7 %PBS number * \param i8 %PBS number * \param i9 %PBS number */ JPBS_t(const int i0, const int i1 = -1, const int i2 = -1, const int i3 = -1, const int i4 = -1, const int i5 = -1, const int i6 = -1, const int i7 = -1, const int i8 = -1, const int i9 = -1) { if (i0 >= 0) { push_back(i0); } else { return; } if (i1 >= 0) { push_back(i1); } else { return; } if (i2 >= 0) { push_back(i2); } else { return; } if (i3 >= 0) { push_back(i3); } else { return; } if (i4 >= 0) { push_back(i4); } else { return; } if (i5 >= 0) { push_back(i5); } else { return; } if (i6 >= 0) { push_back(i6); } else { return; } if (i7 >= 0) { push_back(i7); } else { return; } if (i8 >= 0) { push_back(i8); } else { return; } if (i9 >= 0) { push_back(i9); } else { return; } } /** * Constructor. * * \param input input text */ JPBS_t(const std::string& input) { std::istringstream is(input); is >> *this; } /** * Get %PBS. * * \return %PBS */ const JPBS_t& getPBS() const { return static_cast(*this); } /** * Check validity. * * \return true if valid; else false */ bool is_valid() const { return !this->empty(); } /** * Equality operator. * * \param first first %PBS * \param second second %PBS * \return true if %PBS is equal; else false */ friend inline bool operator==(const JPBS_t& first, const JPBS_t& second) { if (first.size() == second.size()) { for (const_iterator p = first.begin(), q = second.begin(); p != first.end(); ++p, ++q) { if (*p != *q) { return false; } } return true; } return false; } /** * Less-than operator. * * \param first first %PBS * \param second second %PBS * \return true if first %PBS higher in hierarchy; else false */ friend inline bool operator<(const JPBS_t& first, const JPBS_t& second) { for (const_iterator p = first.begin(), q = second.begin(); p != first.end() && q != second.end(); ++p, ++q) { if (*p != *q) { return *p < *q; } } return first.size() < second.size(); } /** * Read %PBS from input stream. * * \param in input stream * \param object %PBS * \return input stream */ friend inline std::istream& operator>>(std::istream& in, JPBS_t& object) { using namespace std; object.clear(); int pbs; if (in >> pbs) { object.push_back(pbs); while (in.peek() == (int) JPBS_t::DOT) { if (in.ignore() && in >> pbs) object.push_back(pbs); else in.setstate(ios::failbit); } } else { in.setstate(ios::failbit); } return in; } /** * Write %PBS to output stream. * * \param out output stream * \param object %PBS * \return output stream */ friend inline std::ostream& operator<<(std::ostream& out, const JPBS_t& object) { using namespace std; using namespace JPP; ostringstream os; if (!object.empty()) { const_iterator i = object.begin(); os << *i; while (++i != object.end()) { os << JPBS_t::DOT << *i; } } return out << os.str(); } ClassDefNV(JPBS_t, 1); }; /** * Namespace for predefined %PBS values. */ namespace PBS { static const JPBS_t DETECTOR (0); //!< %PBS of detector static const JPBS_t DETECTION_UNIT (3); //!< %PBS of detection unit static const JPBS_t BASE (3, 2); //!< %PBS of detection unit base static const JPBS_t BASE_CONTAINER (3, 2, 2); //!< %PBS of detection unit base container static const JPBS_t DOM (3, 4); //!< %PBS of optical module static const JPBS_t PMT (3, 4, 2, 3); //!< %PBS of photo-multiplier tube (PMT) static const JPBS_t CLB (3, 4, 3, 2); //!< %PBS of central-logic board static const JPBS_t T_SENSOR (3, 4, 3, 2, 1, 1); //!< %PBS of temperature sensor static const JPBS_t H_SENSOR (3, 4, 3, 2, 1, 2); //!< %PBS of magnetic field sensor static const JPBS_t FPGA (3, 4, 3, 2, 2); //!< %PBS of FPGA static const JPBS_t POWER_BOARD (3, 4, 3, 5); //!< %PBS of power board static const JPBS_t NANO_BEACON (3, 4, 3, 7); //!< %PBS of nano-beacon static const JPBS_t AHRS (3, 4, 3, 4); //!< %PBS of compass static const JPBS_t ACOUSTIC_SENSOR(3, 4, 3, 6, 2); //!< %PBS of piezo sensor static const JPBS_t HYDROPHONE (4, 5); //!< %PBS of hydrophone } /** * Test if given %PBS corresponds to a detector. * * \param pbs %PBS * \return true if detector; else false */ inline bool is_detector(const JPBS_t& pbs) { return (pbs == PBS::DETECTOR); } /** * Test if given %PBS corresponds to a string. * * \param pbs %PBS * \return true if string; else false */ inline bool is_string(const JPBS_t& pbs) { return (pbs == PBS::DETECTION_UNIT); } /** * Test if given %PBS corresponds to a optical module. * * \param pbs %PBS * \return true if optical module; else false */ inline bool is_optical_module(const JPBS_t& pbs) { return (pbs == PBS::DOM); } /** * Test if given %PBS corresponds to a base module. * * \param pbs %PBS * \return true if base module; else false */ inline bool is_base_module(const JPBS_t& pbs) { return (pbs == PBS::BASE || pbs == PBS::BASE_CONTAINER); } } #endif