summaryrefslogtreecommitdiff
path: root/include/value.h
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2013-08-28 16:09:22 +0200
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2013-08-28 16:09:22 +0200
commit06f99dc74625d1ce338abda0ab6e0b0194bf48b8 (patch)
treeaae309028b9cf1222557d7158fb1e65e74582ba9 /include/value.h
parente72cd10803a020d762db6a7073420294241f690e (diff)
renamed variable class to value class, and implemented most of the methods in it
Diffstat (limited to 'include/value.h')
-rw-r--r--include/value.h245
1 files changed, 245 insertions, 0 deletions
diff --git a/include/value.h b/include/value.h
new file mode 100644
index 0000000..fe370dc
--- /dev/null
+++ b/include/value.h
@@ -0,0 +1,245 @@
+/**
+ * Value.h
+ *
+ * Base class for values that are stored in the Zend engine. One instance
+ * of the value class represents a variable that exists in user space in
+ * the PHP environment, for example as global variable, local variable
+ * inside a function or as a member of an object or an array.
+ *
+ * A value can be a scalar or a more complicated structure like an object
+ * or an array.
+ *
+ * Internally, the Zend engine works with "zval" objects for this. These "zval"
+ * object hold a reference counter and a reference setting. The PHP-CPP Value
+ * class takes care of doing this, so all you need to do is use objects of
+ * this class.
+ *
+ * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
+ * @copyright 2013 Copernica BV
+ */
+
+/**
+ * Forward definitions
+ */
+struct _zval_struct;
+
+/**
+ * Set up namespace
+ */
+namespace PhpCpp {
+
+/**
+ * Class definition
+ */
+class Value
+{
+public:
+ /**
+ * Empty constructor (value = NULL)
+ */
+ Value();
+
+ /**
+ * Constructor based on integer value
+ * @param value
+ */
+ Value(int value);
+
+ /**
+ * Constructor based on boolean value
+ * @param value
+ */
+ Value(bool value);
+
+ /**
+ * Constructor based on string value
+ * @param value
+ */
+ Value(const std::string &value);
+
+ /**
+ * Constructor based on decimal value
+ * @param value
+ */
+ Value(double value);
+
+ /**
+ * Wrap object around zval
+ * @param zval
+ */
+ Value(struct _zval_struct *zval);
+
+ /**
+ * Copy constructor
+ * @param value
+ */
+ Value(const Value &that);
+
+ /**
+ * Destructor
+ */
+ virtual ~Value();
+
+ /**
+ * Assignment operator
+ * @param value
+ * @return Value
+ */
+ virtual Value &operator=(const Value &value);
+
+ /**
+ * Assignment operator
+ * @param value
+ * @return Value
+ */
+ Value &operator=(int value);
+
+ /**
+ * Assignment operator
+ * @param value
+ * @return Value
+ */
+ Value &operator=(bool value);
+
+ /**
+ * Assignment operator
+ * @param value
+ * @return Value
+ */
+ Value &operator=(const std::string &value);
+
+ /**
+ * Assignment operator
+ * @param value
+ * @return Value
+ */
+ Value &operator=(double value);
+
+ /**
+ * The type of object
+ * @return Type
+ */
+ Type type();
+
+ /**
+ * Change the internal type of the variable
+ * @param Type
+ */
+ void setType(Type type);
+
+ /**
+ * Is this a NULL value?
+ * @return bool
+ */
+ bool isNull();
+
+ /**
+ * Is this an integer value?
+ * @return bool
+ */
+ bool isInt();
+
+ /**
+ * Is this a boolean value?
+ * @return bool
+ */
+ bool isBool();
+
+ /**
+ * Is this a string value?
+ * @return bool
+ */
+ bool isString();
+
+ /**
+ * Is this a decimal value?
+ * @return bool
+ */
+ bool isDecimal();
+
+ /**
+ * Is this an object value?
+ * @return bool
+ */
+ bool isObject();
+
+ /**
+ * Is this an array value?
+ * @return bool
+ */
+ bool isArray();
+
+ /**
+ * Retrieve the value as integer
+ * @return int
+ */
+ int intValue();
+
+ /**
+ * Retrieve the value as boolean
+ * @return bool
+ */
+ bool boolValue();
+
+ /**
+ * Retrieve the value as string
+ * @return string
+ */
+ std::string stringValue();
+
+ /**
+ * Retrieve the value as decimal
+ * @return double
+ */
+ double decimalValue();
+
+ /**
+ * Cast to an int
+ * @return int
+ */
+ operator int ()
+ {
+ return intValue();
+ }
+
+ /**
+ * Cast to a boolean
+ * @return boolean
+ */
+ operator bool ()
+ {
+ return boolValue();
+ }
+
+ /**
+ * Cast to a string
+ * @return string
+ */
+ operator std::string ()
+ {
+ return stringValue();
+ }
+
+ /**
+ * Cast to a floating point
+ * @return double
+ */
+ operator double ()
+ {
+ return decimalValue();
+ }
+
+protected:
+ /**
+ * The wrapped zval
+ * @var struct zval
+ */
+ struct _zval_struct *_val;
+};
+
+/**
+ * End of namespace
+ */
+}
+
+