Changeset 590

Show
Ignore:
Timestamp:
07/14/08 09:27:02 (6 months ago)
Author:
weyrick
Message:

switch p3state to a boost::tribool. we now have pTrue, pFalse, and pNull
values, which evaluate properly in conditionals (i.e. only pTrue is true)

Location:
trunk/rphp/runtime
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/rphp/runtime/rphp_pvar.h

    r589 r590  
    2121#define RPHP_PVAR_H_ 
    2222 
    23 #include "boost/variant.hpp" 
    24 #include "boost/shared_ptr.hpp" 
     23#include <boost/logic/tribool.hpp> 
     24#include <boost/variant.hpp> 
     25#include <boost/shared_ptr.hpp> 
    2526 
    26 #include "unicode/unistr.h" 
    27 #include "unicode/ustream.h" // ostream API for UnicodeString 
     27#include <unicode/unistr.h> 
     28#include <unicode/ustream.h> // ostream API for UnicodeString 
    2829 
    2930#include <iostream> 
    3031 
     32BOOST_TRIBOOL_THIRD_STATE(pNull) 
     33 
    3134namespace rphp { 
    3235 
    33 // this represents a php bool and null value 
    34 // it is stored in the variant as an int type 
    35 enum p3state 
    36 { 
    37     Null, 
    38     False, 
    39     True 
    40 }; 
     36// a boost::tribool represents php true, false and null values 
     37typedef boost::logic::tribool p3state; 
     38 
     39// pNull is defined above 
     40#define pTrue rphp::p3state(true) 
     41#define pFalse rphp::p3state(false) 
    4142 
    4243// pvar numbers 
  • trunk/rphp/runtime/rphp_types.h

    r588 r590  
    3333 
    3434    pvarType operator()(const p3state &h) const { 
    35         return (h == rphp::Null) ? PVAR_NULL : PVAR_BOOL; 
     35        return (pNull(h)) ? PVAR_NULL : PVAR_BOOL; 
    3636    } 
    3737 
     
    7777 
    7878    void operator()(const p3state &h) const { 
    79             (h == rphp::True) ? var = 1l : var = 0l; 
     79            (h) ? var = 1l : var = 0l; 
    8080    } 
    8181 
  • trunk/rphp/runtime/test/pvarTestCase.cpp

    r589 r590  
    2121 
    2222    int operator()(const rphp::p3state &i) const { 
    23         if (i == rphp::Null) { 
     23        if (pNull(i)) { 
    2424            std::cout << "i see a null" << std::endl; 
    2525        } 
     
    2727            std::cout << "i see a bool" << std::endl; 
    2828        } 
    29         return i; 
     29        return (i) ? 1 : 0; 
    3030    } 
    3131 
     
    122122 
    123123    // bool 
    124     u = rphp::True; 
    125  
    126     std::cout << u << std::endl; 
    127     result = boost::apply_visitor( my_visitor(), u ); 
    128  
    129     if (rphp::pvar_getVal_bool(u) == rphp::True) { 
     124    u = pTrue; 
     125 
     126    std::cout << u << std::endl; 
     127    result = boost::apply_visitor( my_visitor(), u ); 
     128 
     129    if (rphp::pvar_getVal_bool(u)) { 
    130130        std::cout << "the bool was true" << std::endl; 
    131131    } 
     132    else { 
     133        std::cout << "the bool was false" << std::endl; 
     134    } 
     135     
     136    u = pFalse; 
     137 
     138    std::cout << u << std::endl; 
     139    result = boost::apply_visitor( my_visitor(), u ); 
     140 
     141    if (rphp::pvar_getVal_bool(u)) { 
     142        std::cout << "the bool was true" << std::endl; 
     143    } 
     144    else { 
     145        std::cout << "the bool was false" << std::endl; 
     146    } 
    132147 
    133148    // null 
    134     u = rphp::Null; 
     149    u = pNull; 
    135150 
    136151    std::cout << u << std::endl; 
     
    161176        std::cout << "found a float" << std::endl; 
    162177        break; 
     178    case rphp::PVAR_NULL: 
     179        std::cout << "found a null" << std::endl; 
     180        break; 
    163181    default: 
    164182        std::cout << "woops, what type was it?" << std::endl;