Changeset 592

Show
Ignore:
Timestamp:
07/15/08 07:08:32 (4 months ago)
Author:
weyrick
Message:

bunch of clean up

Files:

Legend:

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

    r591 r592  
    1818 
    1919#include "rphp_hash.h" 
     20#include <iostream> 
    2021 
    21 // hash function for rphp::ustring 
    22 namespace icu_3_8 { 
    23     std::size_t hash_value(rphp::ustring const& s) { 
     22U_NAMESPACE_BEGIN 
     23    // this is used by the multi_index for hashing unicode strings 
     24    std::size_t hash_value(rphp::pUString const& s) { 
    2425        return static_cast<std::size_t>(s.hashCode()); 
    2526    } 
    26 
     27U_NAMESPACE_END 
    2728 
    2829namespace rphp { 
    2930 
    30 void phash::insert(const ustring &key, pvarP data) { 
     31    void pHash::insert(const pUString &key, pVarP data) { 
    3132 
    32     hashData.insert(h_container(key, data)); 
     33        hashData.insert(h_container(key, data)); 
    3334 
    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; 
    4535    } 
    4636 
    47     std::cout << "}" << std::endl; 
    48      
    49 
     37    void pHash::varDump() { 
    5038 
    5139 
    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    } 
    5656 
    5757} /* namespace rphp */ 
  • trunk/rphp/runtime/rphp_hash.h

    r591 r592  
    2828#include "rphp_pvar.h" 
    2929 
     30// hash function for use with rphp::pUString 
     31U_NAMESPACE_BEGIN 
     32    std::size_t hash_value(rphp::pUString const& s); 
     33U_NAMESPACE_END 
     34 
    3035using boost::multi_index_container; 
    3136using namespace boost::multi_index; 
    3237 
    33 // hash function for rphp::ustring 
    34 namespace icu_3_8 { 
    35     std::size_t hash_value(rphp::ustring const& s); 
    36 } 
    37  
    3838namespace rphp { 
    3939 
    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     */ 
    4245 
    43     pvarP data; 
    44     const ustring key; 
    45     bool isNumKey; 
     46    // container stored in stableHash 
     47    struct h_container { 
    4648 
    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 
    5152 
    52 }; 
     53        h_container(const pUString k, pVarP d) : data(d), key(k) { } 
    5354 
    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    }; 
    6456 
    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; 
    6768 
    68 class phash { 
    69     private: 
    70         stableHash hashData; 
    71     public: 
     69    // sequenced index accessor 
     70    typedef nth_index<stableHash,1>::type seq_index; 
    7271 
    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 { 
    7677 
    77         phash(phash const& p) { 
    78             std::cout << "phash copy construct" << std::endl; 
    79             hashData = p.hashData; 
    80         } 
     78        private: 
     79            stableHash hashData; 
    8180 
    82         void insert(const ustring &key, pvarP data); 
     81        public: 
    8382 
    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; 
    9585 
    96          
    97         ~phash() { std::cout << "destroying phash" << std::endl; } 
     86            // construct/destroy/copy 
     87            pHash() { std::cout << "creating fresh pHash" << std::endl; } 
    9888 
    99 }; 
     89            pHash(pHash const& p) { 
     90                std::cout << "pHash copy construct" << std::endl; 
     91                hashData = p.hashData; 
     92            } 
    10093 
    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); 
    102119 
    103120} /* namespace rphp */ 
  • trunk/rphp/runtime/rphp_object.cpp

    r591 r592  
    2222namespace rphp { 
    2323 
    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   
    2727 
    2828} 
  • trunk/rphp/runtime/rphp_object.h

    r591 r592  
    2525namespace rphp { 
    2626 
    27 // XXX placeholder 
    28 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() { } 
    3333 
    34         const phash::size_type getNumProperties() { 
    35             return properties.getSize(); 
    36        
     34            const pHash::size_type getNumProperties() { 
     35                return properties.getSize(); 
     36           
    3737 
    38 }; 
     38    }; 
    3939 
    4040 
    41 std::ostream& operator << (std::ostream& os, const rphp::pobject& h); 
     41    std::ostream& operator << (std::ostream& os, const rphp::pObject& h); 
    4242 
    4343} 
  • trunk/rphp/runtime/rphp_pvar.h

    r591 r592  
    2424#include <boost/variant.hpp> 
    2525#include <boost/shared_ptr.hpp> 
    26  
    2726#include <unicode/unistr.h> 
    28 #include <unicode/ustream.h> // ostream API for UnicodeString 
    29  
     27#include <unicode/ustream.h> 
    3028#include <iostream> 
    31  
    32 BOOST_TRIBOOL_THIRD_STATE(pNull) 
    3329 
    3430namespace rphp { 
    3531 
    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     */ 
    3836 
    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) 
    4244 
    43 // pvar number
    44 typedef long pint; 
    45 typedef double pfloat; 
     45    // numeric type
     46    typedef long   pInt; 
     47    typedef double pFloat; 
    4648 
    47 // string types: binary and unicode flavor 
     49    // string types: binary and unicode flavor 
     50    // "binary" strings 
     51    typedef std::string pBString; 
    4852 
    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
    5256 
    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; 
    5760 
    58 // php hash table
    59 class phash
    60 typedef boost::shared_ptr<phash> phashP; 
     61    // php object
     62    class pObject
     63    typedef boost::shared_ptr<pObject> pObjectP; 
    6164 
    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; 
    6567 
    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; 
    6871 
    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
    7275 
    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; 
    8988 
    9089} /* namespace rphp */ 
  • trunk/rphp/runtime/rphp_types.cpp

    r588 r592  
    2121namespace rphp { 
    2222 
    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) { 
    2525 
    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; 
    2929 
    30 } 
    31  
    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 == 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 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; 
    5130    } 
    5231 
    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    } 
    5555 
    5656 
  • trunk/rphp/runtime/rphp_types.h

    r591 r592  
    2828namespace rphp { 
    2929 
    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> { 
    3432 
    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); 
    37129    } 
    38130 
    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); 
    41134    } 
    42135 
    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); 
    45140    } 
    46141 
    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)
    49144    } 
    50145 
    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)
    53148    } 
    54149 
    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); 
    149156 
    150157} /* namespace rphp */ 
  • trunk/rphp/runtime/test/phashTestCase.cpp

    r591 r592  
    1212{ 
    1313 
    14     rphp::pvarP int1(new rphp::pvar(rphp::pint(971))); 
     14    rphp::pVarP int1(new rphp::pVar(rphp::pInt(971))); 
    1515 
    1616    // php hash 
    17     rphp::phash h; 
     17    rphp::pHash h; 
    1818    h.insert("var-test", int1); 
    1919 
    2020    //std::cout << *(h["var-test"]) << std::endl; 
    21     rphp::pvarP int2 = h["var-test"]; 
     21    rphp::pVarP int2 = h["var-test"]; 
    2222 
    23     CPPUNIT_ASSERT( pvar_getVal_int(*int1) == pvar_getVal_int(*int2) ); 
     23    CPPUNIT_ASSERT( pVar_getVal_int(*int1) == pVar_getVal_int(*int2) ); 
    2424 
    2525    // not found 
  • trunk/rphp/runtime/test/pvarTestCase.cpp

    r591 r592  
    22/* 
    33 
    4 driver for testing pvars 
     4driver for testing pVars 
    55 
    66*/ 
     
    2020public: 
    2121 
    22     int operator()(const rphp::p3state &i) const { 
    23         if (pNull(i)) { 
     22    int operator()(const rphp::pTriState &i) const { 
     23        if (rphp::pNull(i)) { 
    2424            std::cout << "i see a null" << std::endl; 
    2525        } 
     
    3030    } 
    3131 
    32     int operator()(const rphp::pint &i) const { 
    33         std::cout << "i see a pint" << std::endl; 
     32    int operator()(const rphp::pInt &i) const { 
     33        std::cout << "i see a pInt" << std::endl; 
    3434        return i; 
    3535    } 
    3636 
    37     int operator()(const rphp::pfloat &i) const { 
     37    int operator()(const rphp::pFloat &i) const { 
    3838        std::cout << "i see a float" << std::endl; 
    3939        return 0; 
    4040    } 
    4141 
    42     int operator()(const rphp::bstring &str) const { 
     42    int operator()(const rphp::pBString &str) const { 
    4343        std::cout << "i see a binary string" << std::endl; 
    4444        return str.length(); 
    4545    } 
    4646 
    47     int operator()(const rphp::ustringP &str) const { 
     47    int operator()(const rphp::pUStringP &str) const { 
    4848        std::cout << "i see a unicode string" << std::endl; 
    4949        return str->length(); 
    5050    } 
    5151 
    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 { 
     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 { 
    6363        std::cout << "i see a php reference" << std::endl; 
    6464        return 0; 
     
    6666}; 
    6767 
    68 void changeRef(rphp::pvar r) { 
    69  
    70         rphp::pvarRef rval; 
    71         if (rval = rphp::pvar_getVal_ref(r)) { 
    72                 *rval = rphp::bstring("changed the ref to a string!"); 
     68void 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!"); 
    7373        } 
    7474        else { 
     
    8181void pvarTestCase::basic() 
    8282{ 
    83     rphp::pvar u,t,r; 
     83    rphp::pVar u,t,r; 
    8484 
    8585    // sizes 
    8686    std::cout << std::endl; 
    87     std::cout << "p3state: " << sizeof(rphp::p3state) << std::endl; 
    88     std::cout << "pint: " << sizeof(rphp::pint) << std::endl; 
    89     std::cout << "pfloat: " << 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 << "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; 
     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; 
    100100 
    101101    // binary string 
    102     u = rphp::bstring("hello world there"); 
     102    u = rphp::pBString("hello world there"); 
    103103 
    104104    std::cout << u << std::endl; 
     
    106106 
    107107    // unicode string 
    108     u = new rphp::ustring("hello world there -- unicode style"); 
     108    u = new rphp::pUString("hello world there -- unicode style"); 
    109109 
    110110    std::cout << u << std::endl; 
     
    112112 
    113113    // long 
    114     u = rphp::pint(15); 
     114    u = rphp::pInt(15); 
    115115 
    116116    std::cout << u << std::endl; 
     
    118118 
    119119    // float 
    120     u = rphp::pfloat(2.3123); 
     120    u = rphp::pFloat(2.3123); 
    121121 
    122122    std::cout << u << std::endl; 
     
    124124 
    125125    // bool 
    126     u = pTrue; 
    127  
    128     std::cout << u << std::endl; 
    129     result = boost::apply_visitor( my_visitor(), u ); 
    130  
    131     if (rphp::pvar_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)) { 
    132132        std::cout << "the bool was true" << std::endl; 
    133133    } 
     
    136136    } 
    137137     
    138     u = pFalse; 
    139  
    140     std::cout << u << std::endl; 
    141     result = boost::apply_visitor( my_visitor(), u ); 
    142  
    143     if (rphp::pvar_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)) { 
    144144        std::cout << "the bool was true" << std::endl; 
    145145    } 
     
    149149 
    150150    // null 
    151     u = pNull; 
     151    u = rphp::pNull; 
    152152 
    153153    std::cout << u << std::endl; 
     
    156156    // php hash 
    157157    /* 
    158     rphp::phash h; 
    159     h.insert("var-test", rphp::pint(971)); 
    160     rphp::pvar 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); 
    161161    h.insert("var-test2", hole); 
    162162    std::cout << h; 
     
    170170 
    171171    // type checking? 
    172     int pt = rphp::pvar_getType(u); 
     172    int pt = rphp::pVar_getType(u); 
    173173    switch (pt) { 
    174     case rphp::PVAR_HASH
     174    case rphp::pVarHashType
    175175        std::cout << "found a hash" << std::endl; 
    176176        break; 
    177     case rphp::PVAR_FLOAT
     177    case rphp::pVarFloatType
    178178        std::cout << "found a float" << std::endl; 
    179179        break; 
    180     case rphp::PVAR_NULL
     180    case rphp::pVarNullType
    181181        std::cout << "found a null" << std::endl; 
    182182        break; 
     
    191191    u = std::string("55"); 
    192192    boost::apply_visitor( my_visitor(), u ); 
    193     rphp::pvar_convertToNumber(u); 
     193    rphp::pVar_convertToNumber(u); 
    194194    boost::apply_visitor( my_visitor(), u ); 
    195195    std::cout << "final: " << u << std::endl; 
     
    198198 
    199199    // try adding a long and a numeric string 
    200     u = rphp::pint(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) 
    201201    t = std::string("20"); 
    202     r = pvar_add(u, t); 
     202    r = pVar_add(u, t); 
    203203    std::cout << "number add: " << r << std::endl; 
    204204    std::cout << "u is: " << u << std::endl; 
     
    207207    // references 
    208208 
    209     // create a new reference. can only be comprised of pvarBase 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) 
    210210    std::cout << "references----" << std::endl; 
    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) 
     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) 
    218218    changeRef(r1); 
    219219    boost::apply_visitor( my_visitor(), *r1 ); 
    220220 
    221221    // assign two variables to the same reference 
    222     rphp::pvarRef r2 = r1; 
     222    rphp::pVarRef r2 = r1; 
    223223    boost::apply_visitor( my_visitor(), *r1 ); 
    224224    boost::apply_visitor( my_visitor(), *r2 ); 
    225225 
    226226        // change one 
    227     *r2 = rphp::pint(20); 
     227    *r2 = rphp::pInt(20); 
    228228    boost::apply_visitor( my_visitor(), *r1 ); 
    229229    boost::apply_visitor( my_visitor(), *r2 );