Changeset 569
- Timestamp:
- 06/25/08 03:03:46 (5 months ago)
- Files:
-
- trunk/rphp/runtime/var-test.cpp (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/rphp/runtime/var-test.cpp
r568 r569 32 32 33 33 // 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 long34 // as an enum. note that php integers are type long 35 35 // we also use in to decide if this value is NULL. unfortunately a null value would evaluate 36 36 // 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 38 namespace RPHP { 39 enum p3state 40 { 41 False, 42 True, 43 Null 44 }; 45 } 46 41 47 42 48 // 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;49 typedef boost::variant< RPHP::p3state, long, double, std::string, php_hash> pvar; 44 50 45 51 // used for determining type at runtime … … 51 57 { 52 58 public: 53 int operator()(const p3state &i) const59 int operator()(const RPHP::p3state &i) const 54 60 { 55 61 if (i >= 0) { … … 112 118 } 113 119 114 pvartype operator()(const p3state &h) const120 pvartype operator()(const RPHP::p3state &h) const 115 121 { 116 122 return (h >= 0) ? PVAR_BOOL : PVAR_NULL; … … 145 151 } 146 152 147 void operator()(constp3state &h) const153 void operator()(const RPHP::p3state &h) const 148 154 { 149 155 (h <= 0) ? var = 0l : var = 1l; … … 180 186 181 187 // 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) { 188 194 std::cout << "the bool was true" << std::endl; 189 195 } 190 196 191 197 // null 192 u = PNULL;198 u = RPHP::Null; 193 199 194 200 std::cout << u << std::endl;
