Changeset 583
- Timestamp:
- 07/08/08 06:29:51 (5 months ago)
- Files:
-
- trunk/rphp/runtime/rphp_hash.h (modified) (4 diffs)
- trunk/rphp/runtime/rphp_pvar.h (modified) (4 diffs)
- trunk/rphp/runtime/rphp_types.h (modified) (4 diffs)
- trunk/rphp/runtime/var-test.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/rphp/runtime/rphp_hash.h
r579 r583 21 21 22 22 #include <boost/multi_index_container.hpp> 23 #include <boost/multi_index/identity.hpp>24 23 #include <boost/multi_index/hashed_index.hpp> 25 24 #include <boost/multi_index/member.hpp> … … 28 27 #include <iostream> 29 28 29 #include "rphp_pvar.h" 30 30 31 using boost::multi_index_container; 31 32 using namespace boost::multi_index; 32 33 34 namespace rphp { 35 36 struct _dataContainer { 37 38 pvar data; 39 bstring str_key; 40 41 _dataContainer(bstring key, pvar d) : data(d), str_key(key) { } 42 43 }; 44 45 // a boost.multiindex that stores data with two indexes: hashed and sequenced 33 46 typedef multi_index_container< 34 std::string,47 _dataContainer, 35 48 indexed_by< 36 hashed_unique< identity<std::string> >,49 hashed_unique< member<_dataContainer, bstring, &_dataContainer::str_key> >, 37 50 sequenced<> 38 51 > 39 52 > stableHash; 40 53 41 typedef nth_index<stableHash,1>::type seq_hash; 54 // sequenced index accessor 55 typedef nth_index<stableHash,1>::type seq_index; 42 56 43 namespace rphp {44 45 // XXX placeholder46 57 class phash { 47 58 private: … … 50 61 public: 51 62 phash(int sizevar) : size(sizevar) { 52 hashData.insert( "foo");53 hashData.insert( "bar");54 hashData.insert( "baz");63 hashData.insert(_dataContainer("foo", pvar(pint(5)))); 64 hashData.insert(_dataContainer("bar", pvar(bstring("some string val")))); 65 hashData.insert(_dataContainer("baz", pvar(pfloat(5.3212)))); 55 66 } 56 67 … … 60 71 void dump() { 61 72 std::cout << "hash has " << hashData.size() << " elements" << std::endl; 62 seq_ hash& ot = get<1>(hashData);63 for (seq_ hash::iterator it = ot.begin(); it!=ot.end(); it++) {64 std::cout << *it<< std::endl;73 seq_index& ot = get<1>(hashData); 74 for (seq_index::iterator it = ot.begin(); it!=ot.end(); it++) { 75 std::cout << "key: " << (*it).str_key << " | data: " << (*it).data << std::endl; 65 76 } 66 77 } trunk/rphp/runtime/rphp_pvar.h
r579 r583 26 26 #include "unicode/unistr.h" 27 27 28 #include "rphp_hash.h"29 #include "rphp_object.h"30 31 28 #include <iostream> 32 29 … … 37 34 enum p3state 38 35 { 39 Null,40 False,41 True36 Null, 37 False, 38 True 42 39 }; 43 40 … … 56 53 typedef UnicodeString ustring; 57 54 55 // forward declarations for phash and pobject 56 class phash; 57 //class pobject; 58 58 59 // base variant that represents a php variable 59 typedef boost::variant< p3state/*int*/, pint/*long*/, pfloat/*double*/, bstring, ustring, phash, pobject> pvarBase;60 typedef boost::variant< p3state/*int*/, pint/*long*/, pfloat/*double*/, bstring, ustring, boost::recursive_wrapper< phash >/*, pobject*/> pvarBase; 60 61 61 62 // reference to a pvarBase, i.e. a container for pvar variables … … 64 65 65 66 // full pvar definition: a variant that can hold a base type or a reference 66 typedef boost::variant< p3state/*int*/, pint/*long*/, pfloat/*double*/, bstring, ustring, phash, pobject,pvarRef> pvar;67 typedef boost::variant< p3state/*int*/, pint/*long*/, pfloat/*double*/, bstring, ustring, boost::recursive_wrapper< phash >, /*pobject,*/ pvarRef> pvar; 67 68 68 69 // associated enum for checking type 69 70 typedef enum { 70 PVAR_NULL, // rphp::p3state71 PVAR_BOOL, // rphp::p3state72 PVAR_INT, // rphp::pint73 PVAR_FLOAT, // rphp::pfloat74 PVAR_BSTRING, // rphp::bstring75 PVAR_USTRING, // rphp::ustring76 PVAR_HASH, // rphp::phash77 PVAR_OBJ, // rphp::pobject78 PVAR_REF // rphp::pvarRef71 PVAR_NULL, // rphp::p3state 72 PVAR_BOOL, // rphp::p3state 73 PVAR_INT, // rphp::pint 74 PVAR_FLOAT, // rphp::pfloat 75 PVAR_BSTRING, // rphp::bstring 76 PVAR_USTRING, // rphp::ustring 77 PVAR_HASH, // rphp::phash 78 PVAR_OBJ, // rphp::pobject 79 PVAR_REF // rphp::pvarRef 79 80 } pvarType; 80 81 81 82 } /* namespace rphp */ 82 83 83 84 84 #endif /* RPHP_PVAR_H_ */ trunk/rphp/runtime/rphp_types.h
r579 r583 23 23 24 24 #include "rphp_pvar.h" 25 #include "rphp_hash.h" 25 26 26 27 namespace rphp { … … 35 36 } 36 37 37 pvarType operator()(const pint &i) const {38 pvarType operator()(const pint &i) const { 38 39 return PVAR_INT; 39 40 } … … 54 55 return PVAR_HASH; 55 56 } 56 57 /* 57 58 pvarType operator()(const pobject &h) const { 58 59 return PVAR_OBJ; 59 60 } 60 61 */ 61 62 pvarType operator()(const pvarRef &p) const { 62 63 return PVAR_REF; … … 71 72 { 72 73 protected: 73 pvar &var;74 pvar &var; 74 75 public: 75 convertToNumber(pvar &v) : var(v) {}76 convertToNumber(pvar &v) : var(v) {} 76 77 77 void operator()(const p3state &h) const {78 (h == rphp::True) ? var = 1l : var = 0l;79 }78 void operator()(const p3state &h) const { 79 (h == rphp::True) ? var = 1l : var = 0l; 80 } 80 81 81 82 void operator()(const pint &a) const { 82 // nothing, already numeric83 // nothing, already numeric 83 84 } 84 85 85 86 void operator()(const pfloat &i) const { 86 // nothing, already numeric87 // nothing, already numeric 87 88 } 88 89 89 90 void operator()(const bstring &a) const { 90 // TODO: handle floats91 try {92 var = boost::lexical_cast<long>(a);93 } catch(boost::bad_lexical_cast &) {94 var = 0l;95 }91 // TODO: handle floats 92 try { 93 var = boost::lexical_cast<long>(a); 94 } catch(boost::bad_lexical_cast &) { 95 var = 0l; 96 } 96 97 } 97 98 98 99 void operator()(const ustring &a) const { 99 // TODO: do a real conversion here100 // should handle both integers and floats101 var = 0l;100 // TODO: do a real conversion here 101 // should handle both integers and floats 102 var = 0l; 102 103 } 103 104 104 105 void operator()(const phash &h) const { 105 var = (long)h.getSize();106 var = (long)h.getSize(); 106 107 } 107 108 /* 108 109 void operator()(const pobject &h) const { 109 var = 0l;110 var = 0l; 110 111 } 111 112 */ 112 113 void operator()(const pvarRef &r) const { 113 // unbox114 //boost::apply_visitor(convertToNumber(*r), *r);114 // unbox 115 //boost::apply_visitor(convertToNumber(*r), *r); 115 116 } 116 117 trunk/rphp/runtime/var-test.cpp
r579 r583 52 52 } 53 53 54 /* 54 55 int operator()(const rphp::pobject &h) const { 55 56 std::cout << "i see a pobject" << std::endl; 56 57 return 0; 57 58 } 59 */ 58 60 59 61 int operator()(const rphp::pvarRef &h) const { … … 87 89 std::cout << "ustring: " << sizeof(rphp::ustring) << std::endl; 88 90 std::cout << "phash: " << sizeof(rphp::phash) << std::endl; 89 std::cout << "pobj: " << sizeof(rphp::pobject) << std::endl;91 //std::cout << "pobj: " << sizeof(rphp::pobject) << std::endl; 90 92 std::cout << "pvarBase: " << sizeof(rphp::pvarBase) << std::endl; 91 93 std::cout << "pvarRef: " << sizeof(rphp::pvarRef) << std::endl;
