00001 #ifndef __ENUM_H
00002 #define __ENUM_H
00003
00004 #include "Serializable.h"
00005 #include "Printable.h"
00006
00012
00013 namespace EnumNS {
00014
00015 inline void printRef(std::ostream& out, const int8_t& val) { out << val; }
00016 inline void printRef(std::ostream& out, const int16_t& val) { out << val; }
00017 inline void printRef(std::ostream& out, const int32_t& val) { out << val; }
00018 inline void printRef(std::ostream& out, const int64_t& val) { out << val; }
00019 inline void printRef(std::ostream& out, const uint8_t& val) { out << val; }
00020 inline void printRef(std::ostream& out, const uint16_t& val) { out << val; }
00021 inline void printRef(std::ostream& out, const uint32_t& val) { out << val; }
00022 inline void printRef(std::ostream& out, const uint64_t& val) { out << val; }
00023 inline void serializeRef(std::string& str, const int8_t& val) { mace::serialize(str, &val); }
00024 inline void serializeRef(std::string& str, const int16_t& val) { mace::serialize(str, &val); }
00025 inline void serializeRef(std::string& str, const int32_t& val) { mace::serialize(str, &val); }
00026 inline void serializeRef(std::string& str, const int64_t& val) { mace::serialize(str, &val); }
00027 inline void serializeRef(std::string& str, const uint8_t& val) { mace::serialize(str, &val); }
00028 inline void serializeRef(std::string& str, const uint16_t& val) { mace::serialize(str, &val); }
00029 inline void serializeRef(std::string& str, const uint32_t& val) { mace::serialize(str, &val); }
00030 inline void serializeRef(std::string& str, const uint64_t& val) { mace::serialize(str, &val); }
00031 inline int deserializeRef(std::istream& in, int8_t& val) { return mace::deserialize(in, &val); }
00032 inline int deserializeRef(std::istream& in, int16_t& val) { return mace::deserialize(in, &val); }
00033 inline int deserializeRef(std::istream& in, int32_t& val) { return mace::deserialize(in, &val); }
00034 inline int deserializeRef(std::istream& in, int64_t& val) { return mace::deserialize(in, &val); }
00035 inline int deserializeRef(std::istream& in, uint8_t& val) { return mace::deserialize(in, &val); }
00036 inline int deserializeRef(std::istream& in, uint16_t& val) { return mace::deserialize(in, &val); }
00037 inline int deserializeRef(std::istream& in, uint32_t& val) { return mace::deserialize(in, &val); }
00038 inline int deserializeRef(std::istream& in, uint64_t& val) { return mace::deserialize(in, &val); }
00039
00040 template<typename T> int deserializeRef(std::istream& in, const int8_t& val, T& tval) { int8_t v; int rv = mace::deserialize(in, &v); tval = (T)v; return rv;}
00041 template<typename T> int deserializeRef(std::istream& in, const int16_t& val, T& tval) { int16_t v; int rv = mace::deserialize(in, &v); tval = (T)v; return rv;}
00042 template<typename T> int deserializeRef(std::istream& in, const int32_t& val, T& tval) { int32_t v; int rv = mace::deserialize(in, &v); tval = (T)v; return rv;}
00043 template<typename T> int deserializeRef(std::istream& in, const int64_t& val, T& tval) { int64_t v; int rv = mace::deserialize(in, &v); tval = (T)v; return rv;}
00044 template<typename T> int deserializeRef(std::istream& in, const uint8_t& val, T& tval) { uint8_t v; int rv = mace::deserialize(in, &v); tval = (T)v; return rv;}
00045 template<typename T> int deserializeRef(std::istream& in, const uint16_t& val, T& tval) { uint16_t v; int rv = mace::deserialize(in, &v); tval = (T)v; return rv;}
00046 template<typename T> int deserializeRef(std::istream& in, const uint32_t& val, T& tval) { uint32_t v; int rv = mace::deserialize(in, &v); tval = (T)v; return rv;}
00047 template<typename T> int deserializeRef(std::istream& in, const uint64_t& val, T& tval) { uint64_t v; int rv = mace::deserialize(in, &v); tval = (T)v; return rv;}
00048
00049 #ifdef __CYGWIN32__
00050 inline void printRef(std::ostream& out, const int& val) { out << val; }
00051 inline void serializeRef(std::string& str, const int& val) { mace::serialize(str, &val); }
00052 inline int deserializeRef(std::istream& in, int& val) { return mace::deserialize(in, &val); }
00053 template<typename T> int deserializeRef(std::istream& in, const int& val, T& tval) { int v; int rv = mace::deserialize(in, &v); tval = (T)v; return rv;}
00054
00055 inline void printRef(std::ostream& out, const unsigned int& val) { out << val; }
00056 inline void serializeRef(std::string& str, const unsigned int& val) { mace::serialize(str, &val); }
00057 inline int deserializeRef(std::istream& in, unsigned int& val) { return mace::deserialize(in, &val); }
00058 template<typename T> int deserializeRef(std::istream& in, const unsigned int& val, T& tval) { unsigned int v; int rv = mace::deserialize(in, &v); tval = (T)v; return rv;}
00059 #else
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 #endif
00070
00071 }
00072
00088 template<class E> class Enum : public mace::PrintPrintable, public mace::Serializable {
00089 private:
00090 E e;
00091 public:
00092 operator E() { return e; }
00093 operator E() const { return e; }
00094 operator int64_t() const { return e; }
00095 Enum& operator=(const Enum& oe) { e = oe.e; return *this; }
00096 Enum& operator=(const E& oe) { e = oe; return *this; }
00097 bool operator==(const E& oe) const { return e == oe; }
00098 bool operator!=(const E& oe) const { return e != oe; }
00099 Enum() : e() {}
00100 Enum(const E& oe) : e(oe) {}
00101 Enum(const Enum& oe) : e(oe.e) {}
00102 void print(std::ostream& out) const {
00103 EnumNS::printRef(out, e);
00104 }
00105
00106 int deserialize(std::istream& in) throw(mace::SerializationException) {
00107 return EnumNS::deserializeRef(in, e, e);
00108 }
00109 void serialize(std::string& str) const {
00110 EnumNS::serializeRef(str, e);
00111 }
00112
00113 int deserializeXML_RPC(std::istream& in) throw(mace::SerializationException) {
00114 return EnumNS::deserializeRef(in, e, e);
00115 }
00116 void serializeXML_RPC(std::string& str) const throw(mace::SerializationException) {
00117 EnumNS::serializeRef(str, e);
00118 }
00119 };
00120
00121 #endif //__ENUM_H
00122