Changeset 569

Show
Ignore:
Timestamp:
06/25/08 03:03:46 (5 months ago)
Author:
moenicke
Message:

* made p3state being an enum type in a RPHP namespace

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/rphp/runtime/var-test.cpp

    r568 r569  
    3232 
    3333// using the c++ bool as a type seems to cause problems, so we implement php bool 
    34 // as an int. note that php integers are type long 
     34// as an enum. note that php integers are type long 
    3535// we also use in to decide if this value is NULL. unfortunately a null value would evaluate 
    3636// to true (in c++, since it's non 0). can we do this better? 
    37 typedef int p3state; 
    38 #define PFALSE 0 
    39 #define PTRUE  1 
    40 #define PNULL -1 
     37 
     38namespace RPHP { 
     39    enum p3state 
     40    { 
     41        False, 
     42        True, 
     43        Null 
     44    }; 
     45
     46 
    4147 
    4248// this would be the typedef for a generic php variable in our runtime 
    43 typedef boost::variant< p3state, long, double, std::string, php_hash> pvar; 
     49typedef boost::variant< RPHP::p3state, long, double, std::string, php_hash> pvar; 
    4450 
    4551// used for determining type at runtime 
     
    5157{ 
    5258public: 
    53     int operator()(const p3state &i) const 
     59    int operator()(const RPHP::p3state &i) const 
    5460    { 
    5561        if (i >= 0) { 
     
    112118    } 
    113119 
    114     pvartype operator()(const p3state &h) const 
     120    pvartype operator()(const RPHP::p3state &h) const 
    115121    { 
    116122        return (h >= 0) ? PVAR_BOOL : PVAR_NULL; 
     
    145151  } 
    146152 
    147   void operator()(const p3state &h) const 
     153    void operator()(const RPHP::p3state &h) const 
    148154  { 
    149155          (h <= 0) ? var = 0l : var = 1l; 
     
    180186 
    181187    // bool 
    182     u = PTRUE
    183  
    184     std::cout << u << std::endl; 
    185     result = boost::apply_visitor( my_visitor(), u ); 
    186  
    187     if (boost::get<p3state>(u) == PTRUE) { 
     188    u = RPHP::True
     189 
     190    std::cout << u << std::endl; 
     191    result = boost::apply_visitor( my_visitor(), u ); 
     192 
     193    if (boost::get<RPHP::p3state>(u) == RPHP::True) { 
    188194        std::cout << "the bool was true" << std::endl; 
    189195    } 
    190196 
    191197    // null 
    192     u = PNULL
     198    u = RPHP::Null
    193199 
    194200    std::cout << u << std::endl;