Changeset 600

Show
Ignore:
Timestamp:
07/22/08 05:33:58 (4 months ago)
Author:
weyrick
Message:

hash work

Files:

Legend:

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

    r599 r600  
    145145                    return (*k).pData; 
    146146            } 
     147            pVarP operator[] ( const pInt &key ) { 
     148                stableHash::iterator k = hashData.find(key); 
     149                if (k == hashData.end()) 
     150                    return pVarP(); 
     151                else 
     152                    return (*k).pData; 
     153            } 
    147154 
    148155 
  • trunk/rphp/runtime/include/pTypes.h

    r593 r600  
    136136    // get the boolean value of a pVar. does NOT convert so pVar 
    137137    // must already be a pTriState 
    138     inline pTriState pVar_getVal_bool(const pVar &p) { 
     138    inline pTriState pVar_getVal_pBool(const pVar &p) { 
    139139            return boost::get<rphp::pTriState>(p); 
    140140    } 
    141141 
    142     inline long pVar_getVal_int(const pVar &p) { 
     142    inline long pVar_getVal_pInt(const pVar &p) { 
    143143            return boost::get<pInt>(p); 
    144144    } 
     145     
     146    inline pBString pVar_getVal_pBString(const pVar &p) { 
     147            return boost::get<pBString>(p); 
     148    } 
     149     
     150    inline pUStringP pVar_getVal_pUString(const pVar &p) { 
     151            return boost::get<pUStringP>(p); 
     152    } 
    145153 
    146     inline pVarRef pVar_getVal_ref(const pVar &p) { 
     154    inline pVarRef pVar_getVal_pRef(const pVar &p) { 
    147155            return boost::get<pVarRef>(p); 
    148156    } 
  • trunk/rphp/runtime/pTypes.cpp

    r593 r600  
    4747            r = pVar_castToNumber(rhs); 
    4848            //std::cout << "pVar_add: r is " << r << std::endl; 
    49             result = pVar_getVal_int(l) + pVar_getVal_int(r); 
     49            result = pVar_getVal_pInt(l) + pVar_getVal_pInt(r); 
    5050            //std::cout << "pVar_add: result is " << result << std::endl; 
    5151        } 
  • trunk/rphp/runtime/test/phashTestCase.cpp

    r599 r600  
    1212{ 
    1313 
     14    rphp::pVarP lu; 
     15 
     16    // string key 
    1417    rphp::pVarP int1(new rphp::pVar(rphp::pInt(971))); 
    15  
    16     // php hash 
    17     rphp::pHash h; 
    18     h.insert("var-test", int1); 
    19  
    20     //std::cout << *(h["var-test"]) << std::endl; 
    21     rphp::pVarP int2 = h["var-test"]; 
    22  
    23     CPPUNIT_ASSERT( pVar_getVal_int(*int1) == pVar_getVal_int(*int2) ); 
    24  
    25     // not found 
    26     int2 = h["foo"]; 
    27     CPPUNIT_ASSERT( int2.get() == 0 ); 
     18    testHash.insert("var-test", int1); 
     19    CPPUNIT_ASSERT( testHash.getSize() == 1 ); 
    2820 
    2921    // int key 
    3022    rphp::pVarP str1(new rphp::pVar(rphp::pBString("int key 1"))); 
    31     h.insert(55, str1); 
    32      
     23    testHash.insert(55, str1); 
     24    CPPUNIT_ASSERT( testHash.getSize() == 2 ); 
     25 
    3326    // next key 
    3427    rphp::pVarP str2(new rphp::pVar(rphp::pBString("next key"))); 
    35     h.insertNext(str2); 
    36      
    37     h.varDump(); 
     28    testHash.insertNext(str2); 
     29    CPPUNIT_ASSERT( testHash.getSize() == 3 ); 
     30 
     31    //testHash.varDump(); 
     32 
     33    // string key 
     34    lu = testHash["var-test"]; 
     35    CPPUNIT_ASSERT( pVar_getVal_pInt(*int1) == pVar_getVal_pInt(*lu) ); 
     36 
     37    // int key 
     38    lu = testHash[55]; 
     39    CPPUNIT_ASSERT( pVar_getVal_pBString(*str1) == pVar_getVal_pBString(*lu) ); 
     40 
     41    // next key 
     42    lu = testHash[56]; 
     43    CPPUNIT_ASSERT( pVar_getVal_pBString(*str2) == pVar_getVal_pBString(*lu) ); 
     44 
     45    // not found 
     46    lu = testHash["foo"]; 
     47    CPPUNIT_ASSERT( lu.get() == 0 ); 
    3848 
    3949} 
     
    4353{ 
    4454 
    45   m_value1 = 2.0; 
    46   m_value2 = 3.0; 
    4755 
    4856} 
    4957*/ 
    5058 
     59 
  • trunk/rphp/runtime/test/phashTestCase.h

    r589 r600  
    1616  CPPUNIT_TEST_SUITE_END(); 
    1717 
    18 /* 
    1918protected: 
    20   double m_value1; 
    21   double m_value2; 
    22 */ 
     19  rphp::pHash testHash; 
    2320 
    24 /* 
    25 public: 
    26   void setUp(); 
    27 */ 
     21//public: 
     22//  void setUp(); 
    2823 
    2924protected: 
    3025  void basic(); 
     26 
    3127}; 
    3228 
  • trunk/rphp/runtime/test/pvarTestCase.cpp

    r593 r600  
    6969 
    7070        rphp::pVarRef rval; 
    71         if (rval = rphp::pVar_getVal_ref(r)) { 
     71        if (rval = rphp::pVar_getVal_pRef(r)) { 
    7272                *rval = rphp::pBString("changed the ref to a string!"); 
    7373        } 
     
    129129    result = boost::apply_visitor( my_visitor(), u ); 
    130130 
    131     if (rphp::pVar_getVal_bool(u)) { 
     131    if (rphp::pVar_getVal_pBool(u)) { 
    132132        std::cout << "the bool was true" << std::endl; 
    133133    } 
     
    141141    result = boost::apply_visitor( my_visitor(), u ); 
    142142 
    143     if (rphp::pVar_getVal_bool(u)) { 
     143    if (rphp::pVar_getVal_pBool(u)) { 
    144144        std::cout << "the bool was true" << std::endl; 
    145145    }