00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "Serializable.h"
00034 #include "XML_RPCSerialization.h"
00035
00041 #ifndef _MACE_PAIR_H
00042 #define _MACE_PAIR_H
00043
00044 namespace mace {
00045
00051
00052 template<class F, class S>
00053 class printpair : public std::pair<F, S>, public PrintPrintable {
00054 public:
00055 printpair() : std::pair<F, S>() {
00056 }
00057
00058 printpair(const F& f, const S& s) : std::pair<F, S>(f, s) {
00059 }
00060
00061 virtual ~printpair() { }
00062
00063 void print(std::ostream& out) const {
00064 out << "(" << this->first << ", " << this->second << ")";
00065 }
00066
00067 void printState(std::ostream& out) const {
00068 out << "(";
00069 mace::printState(out, &this->first, this->first);
00070 out << ", ";
00071 mace::printState(out, &this->second, this->second);
00072 out << ")";
00073 }
00074
00075 };
00076
00078 template<class F, class S>
00079 class pair : public mace::printpair<F, S>, public Serializable {
00080 public:
00081 pair() : mace::printpair<F, S>() {
00082 }
00083
00084 pair(const F& f, const S& s) : mace::printpair<F, S>(f, s) {
00085 }
00086
00087 virtual ~pair() { }
00088
00089 int deserialize(std::istream& in) throw(SerializationException) {
00090 int bytes = 0;
00091
00092 bytes += mace::deserialize(in, &this->first);
00093 bytes += mace::deserialize(in, &this->second);
00094
00095 return bytes;
00096 }
00097
00098 int deserializeXML_RPC(std::istream& in) throw(SerializationException) {
00099 long offset = in.tellg();
00100 SerializationUtil::expectTag(in, "<array>");
00101 SerializationUtil::expectTag(in, "<data>");
00102 SerializationUtil::expectTag(in, "<value>");
00103 mace::deserializeXML_RPC(in, &this->first, this->first);
00104 SerializationUtil::expectTag(in, "</value>");
00105 SerializationUtil::expectTag(in, "<value>");
00106 mace::deserializeXML_RPC(in, &this->second, this->second);
00107 SerializationUtil::expectTag(in, "</value>");
00108 SerializationUtil::expectTag(in, "</data>");
00109 SerializationUtil::expectTag(in, "</array>");
00110 return (long)in.tellg() - offset;
00111 }
00112
00113 void serialize(std::string &str) const {
00114 mace::serialize(str, &this->first);
00115 mace::serialize(str, &this->second);
00116 }
00117
00118 void serializeXML_RPC(std::string& str) const throw(SerializationException) {
00119 str.append("<array><data><value>");
00120 mace::serializeXML_RPC(str, &this->first, this->first);
00121 str.append("</value><value>");
00122 mace::serializeXML_RPC(str, &this->second, this->second);
00123 str.append("</value></data></array>");
00124 }
00125 };
00126
00129 }
00130 #endif // _MACE_PAIR_H