Changeset 592
- Timestamp:
- 07/15/08 07:08:32 (4 months ago)
- Files:
-
- trunk/rphp/runtime/rphp_hash.cpp (modified) (1 diff)
- trunk/rphp/runtime/rphp_hash.h (modified) (1 diff)
- trunk/rphp/runtime/rphp_object.cpp (modified) (1 diff)
- trunk/rphp/runtime/rphp_object.h (modified) (1 diff)
- trunk/rphp/runtime/rphp_pvar.h (modified) (1 diff)
- trunk/rphp/runtime/rphp_types.cpp (modified) (1 diff)
- trunk/rphp/runtime/rphp_types.h (modified) (1 diff)
- trunk/rphp/runtime/test/phashTestCase.cpp (modified) (1 diff)
- trunk/rphp/runtime/test/pvarTestCase.cpp (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/rphp/runtime/rphp_hash.cpp
r591 r592 18 18 19 19 #include "rphp_hash.h" 20 #include <iostream> 20 21 21 // hash function for rphp::ustring 22 namespace icu_3_8 { 23 std::size_t hash_value(rphp:: ustring const& s) {22 U_NAMESPACE_BEGIN 23 // this is used by the multi_index for hashing unicode strings 24 std::size_t hash_value(rphp::pUString const& s) { 24 25 return static_cast<std::size_t>(s.hashCode()); 25 26 } 26 } 27 U_NAMESPACE_END 27 28 28 29 namespace rphp { 29 30 30 void phash::insert(const ustring &key, pvarP data) {31 void pHash::insert(const pUString &key, pVarP data) { 31 32 32 hashData.insert(h_container(key, data));33 hashData.insert(h_container(key, data)); 33 34 34 }35 36 void phash::varDump() {37 38 39 std::cout << "array(" << hashData.size() << ") {" << std::endl;40 41 seq_index& ot = get<1>(hashData);42 43 for (seq_index::iterator it = ot.begin(); it!=ot.end(); it++) {44 std::cout << " ['" << (*it).key << "'] => " << *(*it).data << std::endl;45 35 } 46 36 47 std::cout << "}" << std::endl; 48 49 } 37 void pHash::varDump() { 50 38 51 39 52 std::ostream& operator << (std::ostream& os, const rphp::phash& h) 53 { 54 return os << "php_hash:" << std::endl; 55 } 40 std::cout << "array(" << hashData.size() << ") {" << std::endl; 41 42 seq_index& ot = get<1>(hashData); 43 44 for (seq_index::iterator it = ot.begin(); it!=ot.end(); it++) { 45 std::cout << " ['" << (*it).key << "'] => " << *(*it).data << std::endl; 46 } 47 48 std::cout << "}" << std::endl; 49 50 } 51 52 std::ostream& operator << (std::ostream& os, const rphp::pHash& h) 53 { 54 return os << "php_hash:" << std::endl; 55 } 56 56 57 57 } /* namespace rphp */ trunk/rphp/runtime/rphp_hash.h
r591 r592 28 28 #include "rphp_pvar.h" 29 29 30 // hash function for use with rphp::pUString 31 U_NAMESPACE_BEGIN 32 std::size_t hash_value(rphp::pUString const& s); 33 U_NAMESPACE_END 34 30 35 using boost::multi_index_container; 31 36 using namespace boost::multi_index; 32 37 33 // hash function for rphp::ustring34 namespace icu_3_8 {35 std::size_t hash_value(rphp::ustring const& s);36 }37 38 38 namespace rphp { 39 39 40 // container we store in our stable hash 41 struct h_container { 40 /* 41 * defines an interface to a hash table class which implements php style 42 * hash table/array semantics 43 * 44 */ 42 45 43 pvarP data; 44 const ustring key; 45 bool isNumKey; 46 // container stored in stableHash 47 struct h_container { 46 48 47 h_container(const ustring k, pvarP d) : data(d), key(k), isNumKey(false) { 48 // TODO: set isNumKey based on isNumeric check on key 49 // we will need this to emulate their numeric keys 50 } 49 pVarP data; 50 const pUString key; 51 // TODO: php has support for numeric keys 51 52 52 }; 53 h_container(const pUString k, pVarP d) : data(d), key(k) { } 53 54 54 // a boost.multiindex that stores data with two indexes: hashed and sequenced 55 typedef multi_index_container< 56 // the container structure we store for each item in the hash 57 h_container, 58 // index definitions: hash and sequence 59 indexed_by< 60 hashed_unique< member<h_container, const ustring, &h_container::key> >, 61 sequenced<> 62 > 63 > stableHash; 55 }; 64 56 65 // sequenced index accessor 66 typedef nth_index<stableHash,1>::type seq_index; 57 // the stableHash container 58 // a boost.multiindex that stores data with two indexes: hashed and sequenced 59 typedef multi_index_container< 60 // the container structure we store for each item in the hash 61 h_container, 62 // index definitions: hash and sequence 63 indexed_by< 64 hashed_unique< member<h_container, const pUString, &h_container::key> >, 65 sequenced<> 66 > 67 > stableHash; 67 68 68 class phash { 69 private: 70 stableHash hashData; 71 public: 69 // sequenced index accessor 70 typedef nth_index<stableHash,1>::type seq_index; 72 71 73 typedef stableHash::size_type size_type; 74 75 phash() { std::cout << "creating fresh phash" << std::endl; } 72 /** 73 * pHash definition 74 * 75 */ 76 class pHash { 76 77 77 phash(phash const& p) { 78 std::cout << "phash copy construct" << std::endl; 79 hashData = p.hashData; 80 } 78 private: 79 stableHash hashData; 81 80 82 void insert(const ustring &key, pvarP data);81 public: 83 82 84 void varDump(); 85 86 const size_type getSize() { return hashData.size(); } 87 88 pvarP operator[] ( const ustring &key ) { 89 stableHash::iterator k = hashData.find(key); 90 if (k == hashData.end()) 91 return pvarP(); 92 else 93 return (*k).data; 94 } 83 // types 84 typedef stableHash::size_type size_type; 95 85 96 97 ~phash() { std::cout << "destroying phash" << std::endl; }86 // construct/destroy/copy 87 pHash() { std::cout << "creating fresh pHash" << std::endl; } 98 88 99 }; 89 pHash(pHash const& p) { 90 std::cout << "pHash copy construct" << std::endl; 91 hashData = p.hashData; 92 } 100 93 101 std::ostream& operator << (std::ostream& os, const rphp::phash& h); 94 ~pHash() { std::cout << "destroying pHash" << std::endl; } 95 96 // modifiers 97 void insert(const pUString &key, pVarP data); 98 99 // size 100 const size_type getSize() { return hashData.size(); } 101 102 // dump of contents 103 void varDump(); 104 105 // lookup 106 pVarP operator[] ( const pUString &key ) { 107 stableHash::iterator k = hashData.find(key); 108 if (k == hashData.end()) 109 return pVarP(); 110 else 111 return (*k).data; 112 } 113 114 115 }; 116 117 // stream interface 118 std::ostream& operator << (std::ostream& os, const rphp::pHash& h); 102 119 103 120 } /* namespace rphp */ trunk/rphp/runtime/rphp_object.cpp
r591 r592 22 22 namespace rphp { 23 23 24 std::ostream& operator << (std::ostream& os, const rphp::pobject& h) {25 return os << "pobject" << std::endl;26 }24 std::ostream& operator << (std::ostream& os, const rphp::pObject& h) { 25 return os << "pobject" << std::endl; 26 } 27 27 28 28 } trunk/rphp/runtime/rphp_object.h
r591 r592 25 25 namespace rphp { 26 26 27 // XXX placeholder28 class pobject {29 private:30 phash properties;31 public:32 pobject() : properties() { }27 // XXX placeholder 28 class pObject { 29 private: 30 pHash properties; 31 public: 32 pObject() : properties() { } 33 33 34 const phash::size_type getNumProperties() {35 return properties.getSize();36 }34 const pHash::size_type getNumProperties() { 35 return properties.getSize(); 36 } 37 37 38 };38 }; 39 39 40 40 41 std::ostream& operator << (std::ostream& os, const rphp::pobject& h);41 std::ostream& operator << (std::ostream& os, const rphp::pObject& h); 42 42 43 43 } trunk/rphp/runtime/rphp_pvar.h
r591 r592 24 24 #include <boost/variant.hpp> 25 25 #include <boost/shared_ptr.hpp> 26 27 26 #include <unicode/unistr.h> 28 #include <unicode/ustream.h> // ostream API for UnicodeString 29 27 #include <unicode/ustream.h> 30 28 #include <iostream> 31 32 BOOST_TRIBOOL_THIRD_STATE(pNull)33 29 34 30 namespace rphp { 35 31 36 // a boost::tribool represents php true, false and null values 37 typedef boost::logic::tribool p3state; 32 /* 33 * Definition of the various types used in the rphp runtime, including the 34 * main pVar variant 35 */ 38 36 39 // pNull is defined above 40 #define pTrue rphp::p3state(true) 41 #define pFalse rphp::p3state(false) 37 // a boost::tribool represents php true, false and null values 38 // pTrue, pFalse and pNull are defined 39 typedef boost::logic::tribool pTriState; 40 // convenience accesors 41 BOOST_TRIBOOL_THIRD_STATE(pNull) 42 #define pTrue pTriState(true) 43 #define pFalse pTriState(false) 42 44 43 // pvar numbers44 typedef long pint;45 typedef double pfloat;45 // numeric types 46 typedef long pInt; 47 typedef double pFloat; 46 48 47 // string types: binary and unicode flavor 49 // string types: binary and unicode flavor 50 // "binary" strings 51 typedef std::string pBString; 48 52 49 // STL basic string. 50 // GNU stdc++ provides implicit sharing but this isn't part of the standard 51 typedef std::string bstring;53 // unicode strings, using the ICU library 54 typedef UnicodeString pUString; 55 typedef boost::shared_ptr<pUString> pUStringP; 52 56 53 // UnicodeString uses 2 byte characters. Storage of base class is 32 bytes on 32bit, 40 on 64bit 54 // implicitly shared 55 typedef UnicodeString ustring; 56 typedef boost::shared_ptr<ustring> ustringP; 57 // php hash tables 58 class pHash; 59 typedef boost::shared_ptr<pHash> pHashP; 57 60 58 // php hash tables59 class phash;60 typedef boost::shared_ptr<phash> phashP;61 // php objects 62 class pObject; 63 typedef boost::shared_ptr<pObject> pObjectP; 61 64 62 // php objects 63 class pobject; 64 typedef boost::shared_ptr<pobject> pobjectP; 65 // base variant that represents a php variable 66 typedef boost::variant< pTriState, pInt, pFloat, pBString, pUStringP, pHashP, pObjectP > pVarBase; 65 67 66 // base variant that represents a php variable 67 typedef boost::variant< p3state, pint, pfloat, bstring, ustringP, phashP, pobjectP> pvarBase; 68 // reference to a pvarBase, i.e. a container for pvar variables 69 // shared_ptr maintains a reference count and guarantees proper destruction 70 typedef boost::shared_ptr<pVarBase> pVarRef; 68 71 69 // reference to a pvarBase, i.e. a container for pvar variables 70 // shared_ptr maintains a reference count and guarantees proper destruction 71 typedef boost::shared_ptr<pvarBase> pvarRef;72 // full pvar definition: a variant that can hold a base type or a reference 73 typedef boost::variant< pTriState, pInt, pFloat, pBString, pUStringP, pHashP, pObjectP, pVarRef > pVar; 74 typedef boost::shared_ptr<pVar> pVarP; 72 75 73 // full pvar definition: a variant that can hold a base type or a reference 74 typedef boost::variant< p3state, pint, pfloat, bstring, ustringP, phashP, pobjectP, pvarRef> pvar; 75 typedef boost::shared_ptr<pvar> pvarP; 76 77 // associated enum for checking type 78 typedef enum { 79 PVAR_NULL, // rphp::p3state 80 PVAR_BOOL, // rphp::p3state 81 PVAR_INT, // rphp::pint 82 PVAR_FLOAT, // rphp::pfloat 83 PVAR_BSTRING, // rphp::bstring 84 PVAR_USTRING, // rphp::ustring 85 PVAR_HASH, // rphp::phash 86 PVAR_OBJ, // rphp::pobject 87 PVAR_REF // rphp::pvarRef 88 } pvarType; 76 // associated enum for checking type 77 typedef enum { 78 pVarNullType, 79 pVarBoolType, 80 pVarIntType, 81 pVarFloatType, 82 pVarBStringType, 83 pVarUStringType, 84 pVarHashType, 85 pVarObjectType, 86 pVarRefType 87 } pVarType; 89 88 90 89 } /* namespace rphp */ trunk/rphp/runtime/rphp_types.cpp
r588 r592 21 21 namespace rphp { 22 22 23 // non destructive cast (explicit copy)24 pvar pvar_castToNumber(const pvar p) {23 // non destructive cast (explicit copy) 24 pVar pVar_castToNumber(const pVar p) { 25 25 26 pvar r = p;27 boost::apply_visitor(convertToNumber(r), r);28 return r;26 pVar r = p; 27 boost::apply_visitor(convertToNumber(r), r); 28 return r; 29 29 30 }31 32 // TODO: belongs in rphp_operators.cpp33 pvar pvar_add(const pvar lhs, const pvar rhs)34 {35 pvar l,r,result;36 37 pvarType lhs_type = pvar_getType(lhs);38 pvarType rhs_type = pvar_getType(rhs);39 if ( (lhs_type == PVAR_HASH) && (rhs_type == PVAR_HASH) ) {40 //std::cout << "fixme: concat hashes" << std::endl;41 result = 0l;42 }43 else {44 // convert to number, then add45 l = pvar_castToNumber(lhs);46 //std::cout << "pvar_add: l is " << l << std::endl;47 r = pvar_castToNumber(rhs);48 //std::cout << "pvar_add: r is " << r << std::endl;49 result = pvar_getVal_int(l) + pvar_getVal_int(r);50 //std::cout << "pvar_add: result is " << result << std::endl;51 30 } 52 31 53 return result; 54 } 32 // TODO: belongs in rphp_operators.cpp 33 pVar pVar_add(const pVar lhs, const pVar rhs) 34 { 35 pVar l,r,result; 36 37 pVarType lhs_type = pVar_getType(lhs); 38 pVarType rhs_type = pVar_getType(rhs); 39 if ( (lhs_type == pVarHashType) && (rhs_type == pVarHashType) ) { 40 //std::cout << "fixme: concat hashes" << std::endl; 41 result = 0l; 42 } 43 else { 44 // convert to number, then add 45 l = pVar_castToNumber(lhs); 46 //std::cout << "pVar_add: l is " << l << std::endl; 47 r = pVar_castToNumber(rhs); 48 //std::cout << "pVar_add: r is " << r << std::endl; 49 result = pVar_getVal_int(l) + pVar_getVal_int(r); 50 //std::cout << "pVar_add: result is " << result << std::endl; 51 } 52 53 return result; 54 } 55 55 56 56 trunk/rphp/runtime/rphp_types.h
r591 r592 28 28 namespace rphp { 29 29 30 // a visitor for determining type of pvar 31 class pvarTypeChecker : public boost::static_visitor<pvarType> 32 { 33 public: 30 // a visitor for determining type of pVar 31 class pVarTypeChecker : public boost::static_visitor<pVarType> { 34 32 35 pvarType operator()(const p3state &h) const { 36 return (pNull(h)) ? PVAR_NULL : PVAR_BOOL; 33 public: 34 35 pVarType operator()(const pTriState &h) const { 36 return (pNull(h)) ? pVarNullType : pVarBoolType; 37 } 38 39 pVarType operator()(const pInt &i) const { 40 return pVarIntType; 41 } 42 43 pVarType operator()(const pFloat &i) const { 44 return pVarFloatType; 45 } 46 47 pVarType operator()(const pBString &str) const { 48 return pVarBStringType; 49 } 50 51 pVarType operator()(const pUStringP &str) const { 52 return pVarUStringType; 53 } 54 55 pVarType operator()(const pHashP &h) const { 56 return pVarHashType; 57 } 58 59 pVarType operator()(const pObjectP &h) const { 60 return pVarObjectType; 61 } 62 63 pVarType operator()(const pVarRef &p) const { 64 return pVarRefType; 65 } 66 67 }; 68 69 70 // a visitor for converting to a number (long or float) 71 class convertToNumber : public boost::static_visitor<void> { 72 protected: 73 pVar &var; 74 75 public: 76 convertToNumber(pVar &v) : var(v) { } 77 78 void operator()(pTriState &h) const { 79 (h) ? var = 1l : var = 0l; 80 } 81 82 void operator()(pInt &a) const { 83 // nothing, already numeric 84 } 85 86 void operator()(pFloat &i) const { 87 // nothing, already numeric 88 } 89 90 void operator()(pBString &a) const { 91 // TODO: handle floats 92 try { 93 var = boost::lexical_cast<long>(a); 94 } catch(boost::bad_lexical_cast &) { 95 var = 0l; 96 } 97 } 98 99 void operator()(pUStringP &a) const { 100 // TODO: do a real conversion here 101 // should handle both integers and floats 102 var = 0l; 103 } 104 105 void operator()(pHashP &h) const { 106 var = (pInt)h->getSize(); 107 } 108 109 void operator()(pObjectP &h) const { 110 var = (pInt)h->getNumProperties(); 111 } 112 113 void operator()(pVarRef &r) const { 114 // unbox 115 //boost::apply_visitor(convertToNumber(*r), *r); 116 } 117 118 }; 119 120 121 /* 122 * convenience accessors 123 * 124 */ 125 126 // convert to number (in place) 127 inline pVarType pVar_getType(const pVar &p) { 128 return boost::apply_visitor(pVarTypeChecker(), p); 37 129 } 38 130 39 pvarType operator()(const pint &i) const { 40 return PVAR_INT; 131 // convert to number (in place) 132 inline void pVar_convertToNumber(pVar &p) { 133 boost::apply_visitor(convertToNumber(p), p); 41 134 } 42 135 43 pvarType operator()(const pfloat &i) const { 44 return PVAR_FLOAT; 136 // get the boolean value of a pVar. does NOT convert so pVar 137 // must already be a pTriState 138 inline pTriState pVar_getVal_bool(const pVar &p) { 139 return boost::get<rphp::pTriState>(p); 45 140 } 46 141 47 pvarType operator()(const bstring &str) const{48 return PVAR_BSTRING;142 inline long pVar_getVal_int(const pVar &p) { 143 return boost::get<pInt>(p); 49 144 } 50 145 51 pvarType operator()(const ustringP &str) const{52 return PVAR_USTRING;146 inline pVarRef pVar_getVal_ref(const pVar &p) { 147 return boost::get<pVarRef>(p); 53 148 } 54 149 55 pvarType operator()(const phashP &h) const { 56 return PVAR_HASH; 57 } 58 59 pvarType operator()(const pobjectP &h) const { 60 return PVAR_OBJ; 61 } 62 63 pvarType operator()(const pvarRef &p) const { 64 return PVAR_REF; 65 } 66 67 }; 68 69 70 71 // a visitor for converting to a number (long or float) 72 class convertToNumber : public boost::static_visitor<void> 73 { 74 protected: 75 pvar &var; 76 public: 77 convertToNumber(pvar &v) : var(v) {} 78 79 void operator()(const p3state &h) const { 80 (h) ? var = 1l : var = 0l; 81 } 82 83 void operator()(const pint &a) const { 84 // nothing, already numeric 85 } 86 87 void operator()(const pfloat &i) const { 88 // nothing, already numeric 89 } 90 91 void operator()(const bstring &a) const { 92 // TODO: handle floats 93 try { 94 var = boost::lexical_cast<long>(a); 95 } catch(boost::bad_lexical_cast &) { 96 var = 0l; 97 } 98 } 99 100 void operator()(const ustringP &a) const { 101 // TODO: do a real conversion here 102 // should handle both integers and floats 103 var = 0l; 104 } 105 106 void operator()(const phashP &h) const { 107 var = (pint)h->getSize(); 108 } 109 110 void operator()(const pobjectP &h) const { 111 var = (pint)h->getNumProperties(); 112 } 113 114 void operator()(const pvarRef &r) const { 115 // unbox 116 //boost::apply_visitor(convertToNumber(*r), *r); 117 } 118 119 }; 120 121 // convert to number (in place) 122 inline pvarType pvar_getType(const pvar &p) { 123 return boost::apply_visitor(pvarTypeChecker(), p); 124 } 125 126 // convert to number (in place) 127 inline void pvar_convertToNumber(pvar &p) { 128 boost::apply_visitor(convertToNumber(p), p); 129 } 130 131 // get the boolean value of a pvar. does NOT convert so pvar 132 // must already be a p3state 133 inline p3state pvar_getVal_bool(const pvar &p) { 134 return boost::get<rphp::p3state>(p); 135 } 136 137 inline long pvar_getVal_int(const pvar &p) { 138 return boost::get<pint>(p); 139 } 140 141 inline pvarRef pvar_getVal_ref(const pvar &p) { 142 return boost::get<pvarRef>(p); 143 } 144 145 146 pvar pvar_castToNumber(const pvar p); 147 pvar pvar_add(const pvar lhs, const pvar rhs); 148 150 /* 151 * type conversions 152 * 153 */ 154 pVar pVar_castToNumber(const pVar p); 155 pVar pVar_add(const pVar lhs, const pVar rhs); 149 156 150 157 } /* namespace rphp */ trunk/rphp/runtime/test/phashTestCase.cpp
r591 r592 12 12 { 13 13 14 rphp::p varP int1(new rphp::pvar(rphp::pint(971)));14 rphp::pVarP int1(new rphp::pVar(rphp::pInt(971))); 15 15 16 16 // php hash 17 rphp::p hash h;17 rphp::pHash h; 18 18 h.insert("var-test", int1); 19 19 20 20 //std::cout << *(h["var-test"]) << std::endl; 21 rphp::p varP int2 = h["var-test"];21 rphp::pVarP int2 = h["var-test"]; 22 22 23 CPPUNIT_ASSERT( p var_getVal_int(*int1) == pvar_getVal_int(*int2) );23 CPPUNIT_ASSERT( pVar_getVal_int(*int1) == pVar_getVal_int(*int2) ); 24 24 25 25 // not found trunk/rphp/runtime/test/pvarTestCase.cpp
r591 r592 2 2 /* 3 3 4 driver for testing p vars4 driver for testing pVars 5 5 6 6 */ … … 20 20 public: 21 21 22 int operator()(const rphp::p 3state &i) const {23 if ( pNull(i)) {22 int operator()(const rphp::pTriState &i) const { 23 if (rphp::pNull(i)) { 24 24 std::cout << "i see a null" << std::endl; 25 25 } … … 30 30 } 31 31 32 int operator()(const rphp::p int &i) const {33 std::cout << "i see a p int" << std::endl;32 int operator()(const rphp::pInt &i) const { 33 std::cout << "i see a pInt" << std::endl; 34 34 return i; 35 35 } 36 36 37 int operator()(const rphp::p float &i) const {37 int operator()(const rphp::pFloat &i) const { 38 38 std::cout << "i see a float" << std::endl; 39 39 return 0; 40 40 } 41 41 42 int operator()(const rphp:: bstring &str) const {42 int operator()(const rphp::pBString &str) const { 43 43 std::cout << "i see a binary string" << std::endl; 44 44 return str.length(); 45 45 } 46 46 47 int operator()(const rphp:: ustringP &str) const {47 int operator()(const rphp::pUStringP &str) const { 48 48 std::cout << "i see a unicode string" << std::endl; 49 49 return str->length(); 50 50 } 51 51 52 int operator()(const rphp::p hashP &h) const {53 std::cout << "i see a p hash" << std::endl;54 return 0; 55 } 56 57 int operator()(const rphp::p objectP &h) const {58 std::cout << "i see a p object" << std::endl;59 return 0; 60 } 61 62 int operator()(const rphp::p varRef &h) const {52 int operator()(const rphp::pHashP &h) const { 53 std::cout << "i see a pHash" << std::endl; 54 return 0; 55 } 56 57 int operator()(const rphp::pObjectP &h) const { 58 std::cout << "i see a pObject" << std::endl; 59 return 0; 60 } 61 62 int operator()(const rphp::pVarRef &h) const { 63 63 std::cout << "i see a php reference" << std::endl; 64 64 return 0; … … 66 66 }; 67 67 68 void changeRef(rphp::p var r) {69 70 rphp::p varRef rval;71 if (rval = rphp::p var_getVal_ref(r)) {72 *rval = rphp:: bstring("changed the ref to a string!");68 void changeRef(rphp::pVar r) { 69 70 rphp::pVarRef rval; 71 if (rval = rphp::pVar_getVal_ref(r)) { 72 *rval = rphp::pBString("changed the ref to a string!"); 73 73 } 74 74 else { … … 81 81 void pvarTestCase::basic() 82 82 { 83 rphp::p var u,t,r;83 rphp::pVar u,t,r; 84 84 85 85 // sizes 86 86 std::cout << std::endl; 87 std::cout << "p 3state: " << sizeof(rphp::p3state) << std::endl;88 std::cout << "p int: " << sizeof(rphp::pint) << std::endl;89 std::cout << "p float: " << sizeof(rphp::pfloat) << std::endl;90 std::cout << " bstring: " << sizeof(rphp::bstring) << std::endl;91 std::cout << " ustring: " << sizeof(rphp::ustring) << std::endl;92 std::cout << " ustringP: " << sizeof(rphp::ustringP) << std::endl;93 std::cout << "p hash: " << sizeof(rphp::phash) << std::endl;94 std::cout << "p hashP: " << sizeof(rphp::phashP) << std::endl;95 std::cout << "p object: " << sizeof(rphp::pobject) << std::endl;96 std::cout << "p objectP: " << sizeof(rphp::pobjectP) << std::endl;97 std::cout << "p varBase: " << sizeof(rphp::pvarBase) << std::endl;98 std::cout << "p varRef: " << sizeof(rphp::pvarRef) << std::endl;99 std::cout << "p var: " << sizeof(rphp::pvar) << std::endl;87 std::cout << "pTriState: " << sizeof(rphp::pTriState) << std::endl; 88 std::cout << "pInt: " << sizeof(rphp::pInt) << std::endl; 89 std::cout << "pFloat: " << sizeof(rphp::pFloat) << std::endl; 90 std::cout << "pBString: " << sizeof(rphp::pBString) << std::endl; 91 std::cout << "pUString: " << sizeof(rphp::pUString) << std::endl; 92 std::cout << "pUStringP: " << sizeof(rphp::pUStringP) << std::endl; 93 std::cout << "pHash: " << sizeof(rphp::pHash) << std::endl; 94 std::cout << "pHashP: " << sizeof(rphp::pHashP) << std::endl; 95 std::cout << "pObject: " << sizeof(rphp::pObject) << std::endl; 96 std::cout << "pObjectP: " << sizeof(rphp::pObjectP) << std::endl; 97 std::cout << "pVarBase: " << sizeof(rphp::pVarBase) << std::endl; 98 std::cout << "pVarRef: " << sizeof(rphp::pVarRef) << std::endl; 99 std::cout << "pVar: " << sizeof(rphp::pVar) << std::endl; 100 100 101 101 // binary string 102 u = rphp:: bstring("hello world there");102 u = rphp::pBString("hello world there"); 103 103 104 104 std::cout << u << std::endl; … … 106 106 107 107 // unicode string 108 u = new rphp:: ustring("hello world there -- unicode style");108 u = new rphp::pUString("hello world there -- unicode style"); 109 109 110 110 std::cout << u << std::endl; … … 112 112 113 113 // long 114 u = rphp::p int(15);114 u = rphp::pInt(15); 115 115 116 116 std::cout << u << std::endl; … … 118 118 119 119 // float 120 u = rphp::p float(2.3123);120 u = rphp::pFloat(2.3123); 121 121 122 122 std::cout << u << std::endl; … … 124 124 125 125 // bool 126 u = pTrue;127 128 std::cout << u << std::endl; 129 result = boost::apply_visitor( my_visitor(), u ); 130 131 if (rphp::p var_getVal_bool(u)) {126 u = rphp::pTrue; 127 128 std::cout << u << std::endl; 129 result = boost::apply_visitor( my_visitor(), u ); 130 131 if (rphp::pVar_getVal_bool(u)) { 132 132 std::cout << "the bool was true" << std::endl; 133 133 } … … 136 136 } 137 137 138 u = pFalse;139 140 std::cout << u << std::endl; 141 result = boost::apply_visitor( my_visitor(), u ); 142 143 if (rphp::p var_getVal_bool(u)) {138 u = rphp::pFalse; 139 140 std::cout << u << std::endl; 141 result = boost::apply_visitor( my_visitor(), u ); 142 143 if (rphp::pVar_getVal_bool(u)) { 144 144 std::cout << "the bool was true" << std::endl; 145 145 } … … 149 149 150 150 // null 151 u = pNull;151 u = rphp::pNull; 152 152 153 153 std::cout << u << std::endl; … … 156 156 // php hash 157 157 /* 158 rphp::p hash h;159 h.insert("var-test", rphp::p int(971));160 rphp::p var hole = rphp::pfloat(1.234);158 rphp::pHash h; 159 h.insert("var-test", rphp::pInt(971)); 160 rphp::pVar hole = rphp::pFloat(1.234); 161 161 h.insert("var-test2", hole); 162 162 std::cout << h; … … 170 170 171 171 // type checking? 172 int pt = rphp::p var_getType(u);172 int pt = rphp::pVar_getType(u); 173 173 switch (pt) { 174 case rphp:: PVAR_HASH:174 case rphp::pVarHashType: 175 175 std::cout << "found a hash" << std::endl; 176 176 break; 177 case rphp:: PVAR_FLOAT:177 case rphp::pVarFloatType: 178 178 std::cout << "found a float" << std::endl; 179 179 break; 180 case rphp:: PVAR_NULL:180 case rphp::pVarNullType: 181 181 std::cout << "found a null" << std::endl; 182 182 break; … … 191 191 u = std::string("55"); 192 192 boost::apply_visitor( my_visitor(), u ); 193 rphp::p var_convertToNumber(u);193 rphp::pVar_convertToNumber(u); 194 194 boost::apply_visitor( my_visitor(), u ); 195 195 std::cout << "final: " << u << std::endl; … … 198 198 199 199 // try adding a long and a numeric string 200 u = rphp::p int(10); // NOTE: this is a long. int's turn into p3state (bool/null)200 u = rphp::pInt(10); // NOTE: this is a long. int's turn into p3state (bool/null) 201 201 t = std::string("20"); 202 r = p var_add(u, t);202 r = pVar_add(u, t); 203 203 std::cout << "number add: " << r << std::endl; 204 204 std::cout << "u is: " << u << std::endl; … … 207 207 // references 208 208 209 // create a new reference. can only be comprised of p varBase items (i.e., can't be a ref to a ref)209 // create a new reference. can only be comprised of pVarBase items (i.e., can't be a ref to a ref) 210 210 std::cout << "references----" << std::endl; 211 rphp::p varRef r1(new rphp::pvarBase);212 213 // assign a value to the p var214 *r1 = rphp::p int(5);215 boost::apply_visitor( my_visitor(), *r1 ); 216 217 // call a function which takes a p var (not strictly a pvarRef)211 rphp::pVarRef r1(new rphp::pVarBase); 212 213 // assign a value to the pVar 214 *r1 = rphp::pInt(5); 215 boost::apply_visitor( my_visitor(), *r1 ); 216 217 // call a function which takes a pVar (not strictly a pVarRef) 218 218 changeRef(r1); 219 219 boost::apply_visitor( my_visitor(), *r1 ); 220 220 221 221 // assign two variables to the same reference 222 rphp::p varRef r2 = r1;222 rphp::pVarRef r2 = r1; 223 223 boost::apply_visitor( my_visitor(), *r1 ); 224 224 boost::apply_visitor( my_visitor(), *r2 ); 225 225 226 226 // change one 227 *r2 = rphp::p int(20);227 *r2 = rphp::pInt(20); 228 228 boost::apply_visitor( my_visitor(), *r1 ); 229 229 boost::apply_visitor( my_visitor(), *r2 );
