map_value.h
changeset 1 67188bd752db
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/map_value.h	Mon Jul 07 08:10:39 2008 -0500
     1.3 @@ -0,0 +1,43 @@
     1.4 +#ifndef MAP_VALUE_H
     1.5 +#define MAP_VALUE_H
     1.6 +
     1.7 +#include <exception>
     1.8 +#include <functional>
     1.9 +#include <iosfwd>
    1.10 +
    1.11 +class MapValue
    1.12 +{
    1.13 +  public:
    1.14 +    friend std::ostream& operator<<(std::ostream &os, const MapValue& v);
    1.15 +    class IllegalOperation : public std::exception
    1.16 +    {
    1.17 +      virtual const char* what() const throw()
    1.18 +      {
    1.19 +        return "Illegal operation.";
    1.20 +      }
    1.21 +    };
    1.22 +    typedef enum
    1.23 +    {
    1.24 +      NUMERIC = 1 << 0,
    1.25 +      STRING  = 1 << 1
    1.26 +    } Type;
    1.27 +  private:
    1.28 +    bool has_value;
    1.29 +    void* p_value;
    1.30 +    MapValue::Type type;
    1.31 +    void clear();
    1.32 +  public:
    1.33 +    MapValue();
    1.34 +    MapValue(double);
    1.35 +    MapValue(std::string);
    1.36 +    MapValue(const char* str);
    1.37 +    MapValue(const MapValue& v);
    1.38 +    MapValue& operator=(const MapValue& v);
    1.39 +    ~MapValue();
    1.40 +    operator std::string() const;
    1.41 +    operator double() const;
    1.42 +    Type getType() const;
    1.43 +    bool hasValue() const;
    1.44 +};
    1.45 +
    1.46 +#endif