Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields  

base.Variant.h

00001 /*----------------------------------------------------------------------------
00002   SWORD 2000 - Software With Objects for Rapid Development
00003   Copyright (C) 2003 Eric NICOLAS
00004   ----------------------------------------------------------------------------
00005   SWORD is free software; you can redistribute it and/or modify
00006   it under the terms of the GNU Lesser General Public License as published by
00007   the Free Software Foundation; either version 2 of the License, or
00008   (at your option) any later version.
00009 
00010   SWORD is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013   GNU Lesser General Public License for more details.
00014 
00015   You should have received a copy of the GNU Lesser General Public License
00016   along with SWORD; if not, write to the Free Software
00017   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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     // get + set as streams
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     // get + set as accessors
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     // checks
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     // display & streaming
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     // type inspection
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 } // namespace sword
00087 
00088 #include "sword.private/base.Variant.inl"
00089 
00090 #endif // _SWORD_BASE_VARIANT_

Generated on Tue Dec 23 20:08:56 2003 for SWORD by doxygen1.3-rc2