#ifndef __JPAIR__ #define __JPAIR__ #include #include #include "JLang/JClass.hh" #include "JIO/JSerialisable.hh" namespace JTOOLS { namespace { using JIO::JReader; using JIO::JWriter; using JLANG::JClass; } /** * Template definition of a pair of objects. */ template class JPair; /** * Template specialisation for a pair of values. */ template class JPair { public: typedef JKey_t key_type; typedef JValue_t mapped_type; typedef JPair value_type; /** * Constructor. * * \param key JKey_t * \param value JValue_t */ JPair(typename JClass ::argument_type key, typename JClass::argument_type value) : first (key), second(value) {} /** * Read JPair from input. * * \param in istream * \param pair JPair * \return istream */ friend inline std::istream& operator>>(std::istream& in, JPair& pair) { in >> pair.first; in >> pair.second; return in; } /** * Write JPair to output. * * \param out ostream * \param pair JPair * \return ostream */ friend inline std::ostream& operator<<(std::ostream& out, const JPair& pair) { out << pair.first; out << ' '; out << pair.second; return out; } /** * Read JPair from input. * * \param in JReader * \param pair JPair * \return JReader */ friend inline JReader& operator>>(JReader& in, JPair& pair) { in >> pair.first; in >> pair.second; return in; } /** * Write JPair to output. * * \param out JWriter * \param pair JPair * \return JWriter */ friend inline JWriter& operator<<(JWriter& out, const JPair& pair) { out << pair.first; out << pair.second; return out; } const key_type& getKey() const { return this->first; } const mapped_type& getValue() const { return this->second; } mapped_type& getValue() { return this->second; } JKey_t first; JValue_t second; }; /** * Template specialisation for a pair of references. */ template class JPair { public: typedef JKey_t key_type; typedef JValue_t mapped_type; typedef JPair value_type; /** * Constructor. * * \param key JKey_t * \param value JValue_t */ JPair(const key_type& key, mapped_type& value) : first (key), second(value) {} const key_type& getKey() const { return this->first; } const mapped_type& getValue() const { return this->second; } mapped_type& getValue() { return this->second; } const JKey_t& first; JValue_t& second; }; /** * Template specialisation for a pair of const references. */ template class JPair { public: typedef JKey_t key_type; typedef JValue_t mapped_type; typedef JPair value_type; /** * Constructor. * * \param key JKey_t * \param value JValue_t */ JPair(const key_type& key, const mapped_type& value) : first (key), second(value) {} const key_type& getKey() const { return this->first; } const mapped_type& getValue() const { return this->second; } const JKey_t& first; const JValue_t& second; }; } #endif