Show
Ignore:
Timestamp:
04/12/08 11:22:27 (7 months ago)
Author:
tom
Message:

Revert previous fix for #89 and add a new improved fix that enhances the
value class to have a proper null type and do comparisions SQL style so
that null is neither equal nor not equal to other things.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/include/mapnik/value.hpp

    r660 r693  
    4040namespace mapnik  { 
    4141    
    42    typedef boost::variant<bool,int,double,UnicodeString> value_base; 
     42   struct value_null 
     43   { 
     44   }; 
     45    
     46   typedef boost::variant<value_null,bool,int,double,UnicodeString> value_base; 
    4347    
    4448   namespace impl { 
     
    4751      { 
    4852            template <typename T, typename U> 
    49             bool operator() (const T &, const U & ) const 
     53            bool operator() (const T &, const U &) const 
    5054            { 
    5155               return false; 
     
    7377               return  lhs == rhs; 
    7478            } 
     79 
     80            bool operator() (value_null, value_null) const 
     81            { 
     82               return false; 
     83            } 
    7584      }; 
    7685       
     86      struct not_equals 
     87         : public boost::static_visitor<bool> 
     88      { 
     89            template <typename T, typename U> 
     90            bool operator() (const T &, const U &) const 
     91            { 
     92               return true; 
     93            } 
     94         
     95            template <typename T> 
     96            bool operator() (T lhs, T rhs) const 
     97            { 
     98               return lhs != rhs; 
     99            } 
     100             
     101            bool operator() (int lhs, double rhs) const 
     102            { 
     103               return  lhs != rhs; 
     104            } 
     105         
     106            bool operator() (double lhs, int rhs) const 
     107            { 
     108               return  lhs != rhs; 
     109            } 
     110         
     111            bool operator() (UnicodeString const& lhs,  
     112                             UnicodeString const& rhs) const 
     113            { 
     114               return  lhs != rhs; 
     115            } 
     116 
     117            bool operator() (value_null, value_null) const 
     118            { 
     119               return false; 
     120            } 
     121 
     122            template <typename T> 
     123            bool operator() (value_null, const T &) const 
     124            { 
     125               return false; 
     126            } 
     127 
     128            template <typename T> 
     129            bool operator() (const T &, value_null) const 
     130            { 
     131               return false; 
     132            } 
     133      }; 
     134 
    77135      struct greater_than 
    78136         : public boost::static_visitor<bool> 
    79137      { 
    80138            template <typename T, typename U> 
    81             bool operator()( const T &, const U & ) const 
    82             { 
    83                return false; 
    84             } 
    85          
    86             template <typename T> 
    87             bool operator()( T lhs, T rhs ) const 
     139            bool operator()(const T &, const U &) const 
     140            { 
     141               return false; 
     142            } 
     143         
     144            template <typename T> 
     145            bool operator()(T lhs, T rhs) const 
    88146            { 
    89147               return lhs > rhs; 
     
    103161            { 
    104162               return  lhs > rhs; 
     163            } 
     164 
     165            bool operator() (value_null, value_null) const 
     166            { 
     167               return false; 
    105168            } 
    106169      }; 
     
    110173      {  
    111174            template <typename T, typename U> 
    112             bool operator()( const T &, const U & ) const 
     175            bool operator()(const T &, const U &) const 
    113176            { 
    114177               return false; 
     
    131194            } 
    132195         
    133             bool operator() (UnicodeString const& lhs, UnicodeString const& rhs ) const 
     196            bool operator() (UnicodeString const& lhs, UnicodeString const& rhs) const 
    134197            { 
    135198               return lhs >= rhs; 
     199            } 
     200 
     201            bool operator() (value_null, value_null) const 
     202            { 
     203               return false; 
    136204            } 
    137205      }; 
     
    141209      {  
    142210            template <typename T, typename U> 
    143             bool operator()( const T &, const U & ) const 
    144             { 
    145                return false; 
    146             } 
    147          
    148             template <typename T> 
    149             bool operator()( T  lhs,T rhs) const 
     211            bool operator()(const T &, const U &) const 
     212            { 
     213               return false; 
     214            } 
     215         
     216            template <typename T> 
     217            bool operator()(T lhs, T rhs) const 
    150218            { 
    151219               return lhs < rhs; 
     
    162230            } 
    163231         
    164             bool operator()( UnicodeString const& lhs,  
    165                              UnicodeString const& rhs ) const 
     232            bool operator()(UnicodeString const& lhs,  
     233                            UnicodeString const& rhs ) const 
    166234            { 
    167235               return lhs < rhs; 
     236            } 
     237 
     238            bool operator() (value_null, value_null) const 
     239            { 
     240               return false; 
    168241            } 
    169242      }; 
     
    173246      {  
    174247            template <typename T, typename U> 
    175             bool operator()( const T &, const U & ) const 
    176             { 
    177                return false; 
    178             } 
    179          
    180             template <typename T> 
    181             bool operator()(T lhs, T rhs ) const 
     248            bool operator()(const T &, const U &) const 
     249            { 
     250               return false; 
     251            } 
     252         
     253            template <typename T> 
     254            bool operator()(T lhs, T rhs) const 
    182255            { 
    183256               return lhs <= rhs; 
     
    195268         
    196269            template <typename T> 
    197             bool operator()( UnicodeString const& lhs,  
    198                              UnicodeString const& rhs ) const 
     270            bool operator()(UnicodeString const& lhs,  
     271                            UnicodeString const& rhs ) const 
    199272            { 
    200273               return lhs <= rhs; 
     274            } 
     275 
     276            bool operator() (value_null, value_null) const 
     277            { 
     278               return false; 
    201279            } 
    202280      }; 
     
    387465               return ss.str(); 
    388466            } 
    389       }; 
     467             
     468            std::string operator() (value_null const& val) const 
     469            { 
     470               return ""; 
     471            } 
     472       }; 
    390473 
    391474      struct to_unicode : public boost::static_visitor<UnicodeString> 
     
    411494               out << std::setprecision(16) << val; 
    412495               return UnicodeString(out.str().c_str()); 
     496            } 
     497             
     498            UnicodeString operator() (value_null const& val) const 
     499            { 
     500               return UnicodeString(""); 
    413501            } 
    414502      }; 
     
    456544               return ss.str(); 
    457545            } 
     546 
     547            std::string operator() (value_null const& val) const 
     548            { 
     549               return "null"; 
     550            } 
    458551      }; 
    459552   } 
    460      
     553 
    461554   class value 
    462555   { 
     
    469562      public: 
    470563         value () 
    471             : base_(0) {} 
     564            : base_(value_null()) {} 
    472565         
    473566         template <typename T> value(T _val_) 
     
    481574         bool operator!=(value const& other) const 
    482575         { 
    483             return !(boost::apply_visitor(impl::equals(),base_,other.base_)); 
     576            return boost::apply_visitor(impl::not_equals(),base_,other.base_); 
    484577         } 
    485578