Changeset 590
- Timestamp:
- 07/14/08 09:27:02 (6 months ago)
- Location:
- trunk/rphp/runtime
- Files:
-
- 3 modified
-
rphp_pvar.h (modified) (1 diff)
-
rphp_types.h (modified) (2 diffs)
-
test/pvarTestCase.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/rphp/runtime/rphp_pvar.h
r589 r590 21 21 #define RPHP_PVAR_H_ 22 22 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> 25 26 26 #include "unicode/unistr.h"27 #include "unicode/ustream.h"// ostream API for UnicodeString27 #include <unicode/unistr.h> 28 #include <unicode/ustream.h> // ostream API for UnicodeString 28 29 29 30 #include <iostream> 30 31 32 BOOST_TRIBOOL_THIRD_STATE(pNull) 33 31 34 namespace rphp { 32 35 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 37 typedef boost::logic::tribool p3state; 38 39 // pNull is defined above 40 #define pTrue rphp::p3state(true) 41 #define pFalse rphp::p3state(false) 41 42 42 43 // pvar numbers -
trunk/rphp/runtime/rphp_types.h
r588 r590 33 33 34 34 pvarType operator()(const p3state &h) const { 35 return ( h == rphp::Null) ? PVAR_NULL : PVAR_BOOL;35 return (pNull(h)) ? PVAR_NULL : PVAR_BOOL; 36 36 } 37 37 … … 77 77 78 78 void operator()(const p3state &h) const { 79 (h == rphp::True) ? var = 1l : var = 0l;79 (h) ? var = 1l : var = 0l; 80 80 } 81 81 -
trunk/rphp/runtime/test/pvarTestCase.cpp
r589 r590 21 21 22 22 int operator()(const rphp::p3state &i) const { 23 if ( i == rphp::Null) {23 if (pNull(i)) { 24 24 std::cout << "i see a null" << std::endl; 25 25 } … … 27 27 std::cout << "i see a bool" << std::endl; 28 28 } 29 return i;29 return (i) ? 1 : 0; 30 30 } 31 31 … … 122 122 123 123 // 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)) { 130 130 std::cout << "the bool was true" << std::endl; 131 131 } 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 } 132 147 133 148 // null 134 u = rphp::Null;149 u = pNull; 135 150 136 151 std::cout << u << std::endl; … … 161 176 std::cout << "found a float" << std::endl; 162 177 break; 178 case rphp::PVAR_NULL: 179 std::cout << "found a null" << std::endl; 180 break; 163 181 default: 164 182 std::cout << "woops, what type was it?" << std::endl;
