summaryrefslogtreecommitdiff
path: root/include/value.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/value.h')
-rw-r--r--include/value.h267
1 files changed, 139 insertions, 128 deletions
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