Changeset 583

Show
Ignore:
Timestamp:
07/08/08 06:29:51 (5 months ago)
Author:
weyrick
Message:

get phash holding pvar, fix some whitespace

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/rphp/runtime/rphp_hash.h

    r579 r583  
    2121 
    2222#include <boost/multi_index_container.hpp> 
    23 #include <boost/multi_index/identity.hpp> 
    2423#include <boost/multi_index/hashed_index.hpp> 
    2524#include <boost/multi_index/member.hpp> 
     
    2827#include <iostream> 
    2928 
     29#include "rphp_pvar.h" 
     30 
    3031using boost::multi_index_container; 
    3132using namespace boost::multi_index; 
    3233 
     34namespace rphp { 
     35 
     36struct _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 
    3346typedef multi_index_container< 
    34   std::string
     47  _dataContainer
    3548  indexed_by< 
    36     hashed_unique<identity<std::string> >, 
     49    hashed_unique< member<_dataContainer, bstring, &_dataContainer::str_key> >, 
    3750    sequenced<> 
    3851  > 
    3952> stableHash; 
    4053 
    41 typedef nth_index<stableHash,1>::type seq_hash; 
     54// sequenced index accessor 
     55typedef nth_index<stableHash,1>::type seq_index; 
    4256 
    43 namespace rphp { 
    44  
    45 // XXX placeholder 
    4657class phash { 
    4758    private: 
     
    5061    public: 
    5162        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)))); 
    5566        } 
    5667 
     
    6071        void dump() { 
    6172            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; 
    6576            } 
    6677        } 
  • trunk/rphp/runtime/rphp_pvar.h

    r579 r583  
    2626#include "unicode/unistr.h" 
    2727 
    28 #include "rphp_hash.h" 
    29 #include "rphp_object.h" 
    30  
    3128#include <iostream> 
    3229 
     
    3734enum p3state 
    3835{ 
    39        Null, 
    40        False, 
    41        True 
     36    Null, 
     37    False, 
     38    True 
    4239}; 
    4340 
     
    5653typedef UnicodeString ustring; 
    5754 
     55// forward declarations for phash and pobject 
     56class phash; 
     57//class pobject; 
     58 
    5859// base variant that represents a php variable 
    59 typedef boost::variant< p3state/*int*/, pint/*long*/, pfloat/*double*/, bstring, ustring, phash, pobject> pvarBase; 
     60typedef boost::variant< p3state/*int*/, pint/*long*/, pfloat/*double*/, bstring, ustring, boost::recursive_wrapper< phash >/*, pobject*/> pvarBase; 
    6061 
    6162// reference to a pvarBase, i.e. a container for pvar variables 
     
    6465 
    6566// 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; 
     67typedef boost::variant< p3state/*int*/, pint/*long*/, pfloat/*double*/, bstring, ustring, boost::recursive_wrapper< phash >, /*pobject,*/ pvarRef> pvar; 
    6768 
    6869// associated enum for checking type 
    6970typedef enum { 
    70        PVAR_NULL,     // rphp::p3state 
    71        PVAR_BOOL,     // rphp::p3state 
    72        PVAR_INT,      // rphp::pint 
    73        PVAR_FLOAT,    // rphp::pfloat 
    74        PVAR_BSTRING,  // rphp::bstring 
    75        PVAR_USTRING,  // rphp::ustring 
    76        PVAR_HASH,     // rphp::phash 
    77        PVAR_OBJ,      // rphp::pobject 
    78        PVAR_REF          // rphp::pvarRef 
     71    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 
    7980} pvarType; 
    8081 
    8182} /* namespace rphp */ 
    8283 
    83  
    8484#endif /* RPHP_PVAR_H_ */ 
  • trunk/rphp/runtime/rphp_types.h

    r579 r583  
    2323 
    2424#include "rphp_pvar.h" 
     25#include "rphp_hash.h" 
    2526 
    2627namespace rphp { 
     
    3536    } 
    3637 
    37        pvarType operator()(const pint &i) const { 
     38    pvarType operator()(const pint &i) const { 
    3839        return PVAR_INT; 
    3940    } 
     
    5455        return PVAR_HASH; 
    5556    } 
    56  
     57/* 
    5758    pvarType operator()(const pobject &h) const { 
    5859        return PVAR_OBJ; 
    5960    } 
    60  
     61*/ 
    6162    pvarType operator()(const pvarRef &p) const { 
    6263        return PVAR_REF; 
     
    7172{ 
    7273protected: 
    73        pvar &var; 
     74    pvar &var; 
    7475public: 
    75        convertToNumber(pvar &v) : var(v) {} 
     76    convertToNumber(pvar &v) : var(v) {} 
    7677 
    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   
    8081 
    8182    void operator()(const pint &a) const { 
    82                // nothing, already numeric 
     83        // nothing, already numeric 
    8384    } 
    8485 
    8586    void operator()(const pfloat &i) const { 
    86                // nothing, already numeric 
     87        // nothing, already numeric 
    8788    } 
    8889 
    8990    void operator()(const bstring &a) const { 
    90        // TODO: handle floats 
    91                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       
    9697    } 
    9798 
    9899    void operator()(const ustring &a) const { 
    99        // TODO: do a real conversion here 
    100        // should handle both integers and floats 
    101        var = 0l; 
     100        // TODO: do a real conversion here 
     101        // should handle both integers and floats 
     102        var = 0l; 
    102103    } 
    103104 
    104105    void operator()(const phash &h) const { 
    105                var = (long)h.getSize(); 
     106        var = (long)h.getSize(); 
    106107    } 
    107  
     108/* 
    108109    void operator()(const pobject &h) const { 
    109        var = 0l; 
     110        var = 0l; 
    110111    } 
    111  
     112*/ 
    112113    void operator()(const pvarRef &r) const { 
    113        // unbox 
    114        //boost::apply_visitor(convertToNumber(*r), *r); 
     114        // unbox 
     115        //boost::apply_visitor(convertToNumber(*r), *r); 
    115116    } 
    116117 
  • trunk/rphp/runtime/var-test.cpp

    r579 r583  
    5252    } 
    5353 
     54    /* 
    5455    int operator()(const rphp::pobject &h) const { 
    5556        std::cout << "i see a pobject" << std::endl; 
    5657        return 0; 
    5758    } 
     59    */ 
    5860 
    5961    int operator()(const rphp::pvarRef &h) const { 
     
    8789    std::cout << "ustring: " << sizeof(rphp::ustring) << std::endl; 
    8890    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; 
    9092    std::cout << "pvarBase: " << sizeof(rphp::pvarBase) << std::endl; 
    9193    std::cout << "pvarRef: " << sizeof(rphp::pvarRef) << std::endl;