00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef _SWORD_BASE_VARIANT_
00020 #define _SWORD_BASE_VARIANT_
00021
00022 #include "sword/streams.IStream.h"
00023 #include "sword/streams.OStream.h"
00024 #include "sword/time.Time.h"
00025
00026 namespace sword {
00027
00028 class SWORDDECL Variant {
00029 public:
00030 enum Type { NONE=0, INTEGER, DOUBLE, STRING, TIME };
00031
00032 Variant();
00033 Variant(int value);
00034 Variant(double value);
00035 Variant(const std::string& value);
00036 Variant(const Time& value);
00037
00038
00039 void operator>>(int& value) const;
00040 void operator>>(double& value) const;
00041 void operator>>(std::string& value) const;
00042 void operator>>(Time& value) const;
00043
00044 void operator<<(int value);
00045 void operator<<(double value);
00046 void operator<<(const std::string& value);
00047 void operator<<(const Time& value);
00048
00049
00050 int asInteger() const;
00051 double asDouble() const;
00052 std::string asString() const;
00053 Time asTime() const;
00054
00055 void setInteger(int value);
00056 void setDouble(double value);
00057 void setString(const std::string& value);
00058 void setTime(const Time& value);
00059
00060
00061 bool empty() const;
00062 bool isInt() const;
00063 bool isDouble() const;
00064 bool isString() const;
00065 bool isChar() const;
00066 bool isNumeric() const;
00067 bool isTime() const;
00068
00069
00070 friend std::ostream& operator<<(std::ostream& lhs, const Variant& rhs);
00071 friend std::istream& operator>>(std::istream& lhs, Variant& rhs);
00072 friend OStream& operator<<(OStream& lhs, const Variant& rhs);
00073 friend IStream& operator>>(IStream& lhs, Variant& rhs);
00074
00075
00076 Type type() const;
00077
00078 private:
00079 Type type_;
00080 int int_;
00081 double double_;
00082 std::string string_;
00083 Time time_;
00084 };
00085
00086 }
00087
00088 #include "sword.private/base.Variant.inl"
00089
00090 #endif // _SWORD_BASE_VARIANT_