From: <sja...@us...> - 2003-09-02 02:04:05
|
Update of /cvsroot/binaryphp/binaryphp In directory sc8-pr-cvs1:/tmp/cvs-serv17440 Modified Files: php_var.cpp php_var.hpp Log Message: - Added operator= overloading. - Added missing declarations in php_var.hpp for operator overloaded at the - bottom of php_var.cpp. - Changed to_array() so that if there was a value, it gets put into element 0. - Fixed a segfault (when I added operator=). Index: php_var.cpp =================================================================== RCS file: /cvsroot/binaryphp/binaryphp/php_var.cpp,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** php_var.cpp 17 Aug 2003 20:43:13 -0000 1.31 --- php_var.cpp 2 Sep 2003 02:04:02 -0000 1.32 *************** *** 27,31 **** { container = doublestring(i); ! type.is_int = true; } php_var::php_var(int i) --- 27,31 ---- { container = doublestring(i); ! type.is_float = true; } php_var::php_var(int i) *************** *** 72,86 **** php_var::operator const char*() { ! if(type.is_string || type.is_int) ! return container.c_str(); else ! return "Array"; } php_var::operator string() { ! if(type.is_string || type.is_int) ! return container; else ! return string("Array"); } php_var::operator bool() --- 72,86 ---- php_var::operator const char*() { ! if(type.is_array || type.is_object || type.is_resource ) ! return (char *)type; else ! return container.c_str(); } php_var::operator string() { ! if(type.is_array || type.is_object || type.is_resource ) ! return string((char *)type); else ! return container; } php_var::operator bool() *************** *** 134,138 **** if(type.is_string) { ! // return &container[subscript]; } else if(type.is_array) --- 134,138 ---- if(type.is_string) { ! throw php_var("can't handle array access to strings"); } else if(type.is_array) *************** *** 235,238 **** --- 235,286 ---- return ret; } + php_var &php_var::operator=(const php_var &temp) + { + type = temp.type; + container = temp.container; + keys = temp.keys; + data = temp.data; + res = temp.res; + return *this; + } + php_var &php_var::operator=(int i) + { + container = intstring(i); + type = PHP_INT; + return *this; + } + php_var &php_var::operator=(unsigned int i) + { + container = intstring(i); + type = PHP_INT; + return *this; + } + php_var &php_var::operator=(double d) + { + container = doublestring(d); + type = PHP_FLOAT; + return *this; + } + php_var &php_var::operator=(char *str) + { + container = str; + type = PHP_STRING; + return *this; + } + php_var &php_var::operator=(string str) + { + container = str; + type = PHP_STRING; + return *this; + } + php_var &php_var::operator=(bool b) + { + if(b) + container = "1"; + else + container = "0"; + type = PHP_BOOL; + return *this; + } void php_var::operator+=(int inc) { *************** *** 283,287 **** void php_var::to_array() { ! type.is_array = true; } template<typename T> inline T * OBJ(php_var obj) { return (reinterpret_cast<T *>(obj.res)); } --- 331,339 ---- void php_var::to_array() { ! type = PHP_ARRAY; ! if(container.length() > 0) { ! (*this)[0] = container; ! container = ""; ! } } template<typename T> inline T * OBJ(php_var obj) { return (reinterpret_cast<T *>(obj.res)); } *************** *** 294,298 **** return out; } ! bool operator<(int i,php_var v) { return(v > i); --- 346,350 ---- return out; } ! bool operator<(int i, php_var v) { return(v > i); Index: php_var.hpp =================================================================== RCS file: /cvsroot/binaryphp/binaryphp/php_var.hpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** php_var.hpp 17 Aug 2003 20:11:47 -0000 1.4 --- php_var.hpp 2 Sep 2003 02:04:02 -0000 1.5 *************** *** 61,64 **** --- 61,72 ---- int operator--(); + php_var &operator=(const php_var &temp); + php_var &operator=(int i); + php_var &operator=(unsigned int i); + php_var &operator=(double d); + php_var &operator=(char *str); + php_var &operator=(string str); + php_var &operator=(bool b); + void operator+=(int inc); void operator+=(php_var str); *************** *** 80,83 **** --- 88,96 ---- php_var_type type; // Contains current type. }; + + bool operator<(int i, php_var v); + bool operator>(int i, php_var v); + php_var operator-(php_var l, php_var r); + float operator/(php_var &l, php_var &r); php_var operator*(php_var l, php_var r); |