summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2013-10-20 14:25:24 -0700
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2013-10-20 14:25:24 -0700
commit87462517ca9ae8ece9ef3f97d3f105c72e74a4d7 (patch)
treeb1f53acdcb1e33a774cfea6e17b950c6db54f8a9 /include
parent61ba30d716dab670a5f2ed0ee2f6650375b2058d (diff)
long types have been replaced with int16, int32 and int64 types to make code more readable and easier portable between architectures
longType and decimalType have been replace by numericType and floatType Many arithmetic operators have been added to the value class Solved various issues with copying and moving value objects
Diffstat (limited to 'include')
-rw-r--r--include/hashmember.h26
-rw-r--r--include/type.h4
-rw-r--r--include/value.h267
3 files changed, 163 insertions, 134 deletions
diff --git a/include/hashmember.h b/include/hashmember.h
index 2724836..d476b55 100644
--- a/include/hashmember.h
+++ b/include/hashmember.h
@@ -71,12 +71,30 @@ public:
}
/**
- * Cast to a long
- * @return long
+ * Cast to a integer
+ * @return int16_t
*/
- operator long () const
+ operator int16_t () const
{
- return _base.get(_index).longValue();
+ return _base.get(_index).numericValue();
+ }
+
+ /**
+ * Cast to a integer
+ * @return int32_t
+ */
+ operator int32_t () const
+ {
+ return _base.get(_index).numericValue();
+ }
+
+ /**
+ * Cast to a integer
+ * @return int64_t
+ */
+ operator int64_t () const
+ {
+ return _base.get(_index).numericValue();
}
/**
diff --git a/include/type.h b/include/type.h
index 04e488b..25b26da 100644
--- a/include/type.h
+++ b/include/type.h
@@ -19,8 +19,8 @@ namespace Php {
*/
typedef enum _Type {
nullType = 0,
- longType = 1,
- decimalType = 2,
+ numericType = 1,
+ floatType = 2,
boolType = 3,
arrayType = 4,
objectType = 5,
diff --git a/include/value.h b/include/value.h
index 6c879e6..ed6cec4 100644
--- a/include/value.h
+++ b/include/value.h
@@ -45,51 +45,17 @@ public:
Value();
/**
- * Constructor for null ptr
- */
- Value(std::nullptr_t value);
-
- /**
- * Constructor based on integer value
- * @param value
- */
- Value(int value);
-
- /**
- * Constructor based on integer value
- * @param value
- */
- Value(long value);
-
- /**
- * Constructor based on boolean value
+ * Constructor for various types
* @param value
*/
+ Value(std::nullptr_t value);
+ Value(int16_t value);
+ Value(int32_t value);
+ Value(int64_t value);
Value(bool value);
-
- /**
- * Constructor based on single character
- * @param value
- */
Value(char value);
-
- /**
- * Constructor based on string value
- * @param value
- */
Value(const std::string &value);
-
- /**
- * Constructor based on byte buffer
- * @param value
- * @param size
- */
Value(const char *value, int size = -1);
-
- /**
- * Constructor based on decimal value
- * @param value
- */
Value(double value);
/**
@@ -117,67 +83,146 @@ public:
virtual ~Value();
/**
- * Assignment operator
+ * Move assignment
* @param value
* @return Value
*/
- Value &operator=(const Value &value);
+ Value &operator=(Value &&value);
/**
- * Move assignment
+ * Assignment operator for various types
* @param value
* @return Value
*/
- Value &operator=(Value &&value);
+ Value &operator=(const Value &value);
+ Value &operator=(int16_t value);
+ Value &operator=(int32_t value);
+ Value &operator=(int64_t value);
+ Value &operator=(bool value);
+ Value &operator=(char value);
+ Value &operator=(const std::string &value);
+ Value &operator=(const char *value);
+ Value &operator=(double value);
/**
- * Assignment operator
+ * Add a value to the object
* @param value
* @return Value
*/
- Value &operator=(long value);
+ Value &operator+=(const Value &value);
+ Value &operator+=(int16_t value);
+ Value &operator+=(int32_t value);
+ Value &operator+=(int64_t value);
+ Value &operator+=(bool value);
+ Value &operator+=(char value);
+ Value &operator+=(const std::string &value);
+ Value &operator+=(const char *value);
+ Value &operator+=(double value);
/**
- * Assignment operator
+ * Subtract a value from the object
* @param value
* @return Value
*/
- Value &operator=(int value);
-
+ Value &operator-=(const Value &value);
+ Value &operator-=(int16_t value);
+ Value &operator-=(int32_t value);
+ Value &operator-=(int64_t value);
+ Value &operator-=(bool value);
+ Value &operator-=(char value);
+ Value &operator-=(const std::string &value);
+ Value &operator-=(const char *value);
+ Value &operator-=(double value);
+
/**
- * Assignment operator
+ * Multiply the object with a certain value
* @param value
* @return Value
*/
- Value &operator=(bool value);
+ Value &operator*=(const Value &value);
+ Value &operator*=(int16_t value);
+ Value &operator*=(int32_t value);
+ Value &operator*=(int64_t value);
+ Value &operator*=(bool value);
+ Value &operator*=(char value);
+ Value &operator*=(const std::string &value);
+ Value &operator*=(const char *value);
+ Value &operator*=(double value);
/**
+ * Divide the object with a certain value
+ * @param value
+ * @return Value
+ */
+ Value &operator/=(const Value &value);
+ Value &operator/=(int16_t value);
+ Value &operator/=(int32_t value);
+ Value &operator/=(int64_t value);
+ Value &operator/=(bool value);
+ Value &operator/=(char value);
+ Value &operator/=(const std::string &value);
+ Value &operator/=(const char *value);
+ Value &operator/=(double value);
+
+ /**
* Assignment operator
* @param value
* @return Value
*/
- Value &operator=(char value);
+ Value operator+(const Value &value);
+ Value operator+(int16_t value);
+ Value operator+(int32_t value);
+ Value operator+(int64_t value);
+ Value operator+(bool value);
+ Value operator+(char value);
+ Value operator+(const std::string &value);
+ Value operator+(const char *value);
+ Value operator+(double value);
/**
- * Assignment operator
+ * Subtraction operator
* @param value
* @return Value
*/
- Value &operator=(const std::string &value);
-
+ Value operator-(const Value &value);
+ Value operator-(int16_t value);
+ Value operator-(int32_t value);
+ Value operator-(int64_t value);
+ Value operator-(bool value);
+ Value operator-(char value);
+ Value operator-(const std::string &value);
+ Value operator-(const char *value);
+ Value operator-(double value);
+
/**
- * Assignment operator
+ * Multiplication operator
* @param value
* @return Value
*/
- Value &operator=(const char *value);
-
+ Value operator*(const Value &value);
+ Value operator*(int16_t value);
+ Value operator*(int32_t value);
+ Value operator*(int64_t value);
+ Value operator*(bool value);
+ Value operator*(char value);
+ Value operator*(const std::string &value);
+ Value operator*(const char *value);
+ Value operator*(double value);
+
/**
- * Assignment operator
+ * Division operator
* @param value
* @return Value
*/
- Value &operator=(double value);
+ Value operator/(const Value &value);
+ Value operator/(int16_t value);
+ Value operator/(int32_t value);
+ Value operator/(int64_t value);
+ Value operator/(bool value);
+ Value operator/(char value);
+ Value operator/(const std::string &value);
+ Value operator/(const char *value);
+ Value operator/(double value);
/**
* The type of object
@@ -205,73 +250,22 @@ public:
Value clone(Type type) const;
/**
- * Is this a NULL value?
- * @return bool
- */
- bool isNull() const
- {
- return type() == nullType;
- }
-
- /**
- * Is this an integer value?
- * @return bool
- */
- bool isLong() const
- {
- return type() == longType;
- }
-
- /**
- * Is this a boolean value?
- * @return bool
- */
- bool isBool() const
- {
- return type() == boolType;
- }
-
- /**
- * Is this a string value?
- * @return bool
- */
- bool isString() const
- {
- return type() == stringType;
- }
-
- /**
- * Is this a decimal value?
- * @return bool
- */
- bool isDecimal() const
- {
- return type() == decimalType;
- }
-
- /**
- * Is this an object value?
+ * Check if the value is of a certain type
* @return bool
*/
- bool isObject() const
- {
- return type() == objectType;
- }
-
- /**
- * Is this an array value?
- * @return bool
- */
- bool isArray() const
- {
- return type() == arrayType;
- }
+ bool isNull() const { return type() == nullType; }
+ bool isNumeric() const { return type() == numericType; }
+ bool isBool() const { return type() == boolType; }
+ bool isString() const { return type() == stringType; }
+ bool isFloat() const { return type() == floatType; }
+ bool isObject() const { return type() == objectType; }
+ bool isArray() const { return type() == arrayType; }
/**
- * Retrieve the value as integer
- * @return int
+ * Retrieve the value as number
+ * @return long
*/
- long longValue() const;
+ long numericValue() const;
/**
* Retrieve the value as boolean
@@ -297,7 +291,7 @@ public:
* Retrieve the value as decimal
* @return double
*/
- double decimalValue() const;
+ double floatValue() const;
/**
* The number of members in case of an array or object
@@ -349,12 +343,30 @@ public:
bool contains(const char *key, int size) const;
/**
- * Cast to a long
- * @return long
+ * Cast to a number
+ * @return int32_t
+ */
+ operator int16_t () const
+ {
+ return numericValue();
+ }
+
+ /**
+ * Cast to a number
+ * @return int32_t
*/
- operator long () const
+ operator int32_t () const
{
- return longValue();
+ return numericValue();
+ }
+
+ /**
+ * Cast to a number
+ * @return uint64_t
+ */
+ operator int64_t () const
+ {
+ return numericValue();
}
/**
@@ -390,7 +402,7 @@ public:
*/
operator double () const
{
- return decimalValue();
+ return floatValue();
}
/**
@@ -485,7 +497,6 @@ public:
*/
HashMember<std::string> operator[](const char *key);
-
protected:
/**
* The wrapped zval