map_value.h
changeset 3 2cc5ed6e6255
equal deleted inserted replaced
-1:000000000000 0:c767516c87e9
       
     1 #ifndef MAP_VALUE_H
       
     2 #define MAP_VALUE_H
       
     3 
       
     4 #include <exception>
       
     5 #include <functional>
       
     6 #include <iosfwd>
       
     7 
       
     8 class MapValue
       
     9 {
       
    10   public:
       
    11     friend std::ostream& operator<<(std::ostream &os, const MapValue& v);
       
    12     class IllegalOperation : public std::exception
       
    13     {
       
    14       virtual const char* what() const throw()
       
    15       {
       
    16         return "Illegal operation.";
       
    17       }
       
    18     };
       
    19     typedef enum
       
    20     {
       
    21       NUMERIC = 1 << 0,
       
    22       STRING  = 1 << 1
       
    23     } Type;
       
    24   private:
       
    25     bool has_value;
       
    26     void* p_value;
       
    27     MapValue::Type type;
       
    28     void clear();
       
    29   public:
       
    30     MapValue();
       
    31     MapValue(double);
       
    32     MapValue(std::string);
       
    33     MapValue(const char* str);
       
    34     MapValue(const MapValue& v);
       
    35     MapValue& operator=(const MapValue& v);
       
    36     ~MapValue();
       
    37     operator std::string() const;
       
    38     operator double() const;
       
    39     Type getType() const;
       
    40     bool hasValue() const;
       
    41 };
       
    42 
       
    43 #endif