summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2013-12-07 13:12:25 -0800
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2013-12-07 13:12:25 -0800
commit80c8a16fb145f7ed4867d31fad3c22318a1ce708 (patch)
treef7605cdb86d653efaac761363ed596dd6b2e0459 /include
parent964d6274b0eba38df43d77b87c44bd728d2f0fb5 (diff)
replaces tabs in source code with regular spaces, added example for working with global variables
Diffstat (limited to 'include')
-rw-r--r--include/array.h83
-rw-r--r--include/exception.h78
-rw-r--r--include/extension.h2
-rw-r--r--include/globals.h18
-rw-r--r--include/value.h28
5 files changed, 150 insertions, 59 deletions
diff --git a/include/array.h b/include/array.h
new file mode 100644
index 0000000..6956fee
--- /dev/null
+++ b/include/array.h
@@ -0,0 +1,83 @@
+/**
+ * Array.h
+ *
+ * An array is an extension to the Value class. It extends the Value class
+ * to initialize the variable as an array, instead of a null pointer
+ *
+ * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
+ * @copyright 2013 Copernica BV
+ */
+
+/**
+ * Set up namespace
+ */
+namespace Php {
+
+/**
+ * Class definition
+ */
+class Array : public Value
+{
+public:
+ /**
+ * Constructor
+ */
+ Array() : Value() { setType(arrayType); }
+
+ /**
+ * Copy constructor
+ * @param array
+ */
+ Array(const Array &array) : Value(array) {}
+
+ /**
+ * Move constructor
+ * @param array
+ */
+ Array(Array &&that) : Value(std::move(that)) {}
+
+ /**
+ * Copy constructor from a value object
+ * @param value
+ */
+ Array(const Value &value) : Value(value) { setType(arrayType); }
+
+ /**
+ * Destructor
+ */
+ virtual ~Array() {}
+
+ /**
+ * Change the internal type of the variable
+ * @param Type
+ */
+ virtual Value &setType(Type type) override
+ {
+ // only possible for arrays
+ if (type != arrayType) return *this;
+
+ // call base
+ return Value::setType(type);
+ }
+
+protected:
+ /**
+ * Validate the object
+ * @return Value
+ */
+ virtual Value &validate() override
+ {
+ // make sure the value object is an array
+ setType(arrayType);
+
+ // call base
+ return Value::validate();
+ }
+
+};
+
+/**
+ * End of namespace
+ */
+}
+
diff --git a/include/exception.h b/include/exception.h
index ccb6b08..061c106 100644
--- a/include/exception.h
+++ b/include/exception.h
@@ -1,9 +1,9 @@
/**
- * Exception.h
- * Implementation of Php Exceptions.
+ * Exception.h
+ * Implementation of Php Exceptions.
*
- * @author Jasper van Eck <jasper.vaneck@copernica.com>
- * @copyright 2013 Copernica BV
+ * @author Jasper van Eck <jasper.vaneck@copernica.com>
+ * @copyright 2013 Copernica BV
*/
#include <exception>
@@ -18,42 +18,42 @@ namespace Php {
class Exception : public std::exception
{
private:
- /**
- * The exception message
- * @var char*
- */
- std::string _message;
-
- /**
- * The PHP exception code
- * @var int
- */
- int _code;
-
+ /**
+ * The exception message
+ * @var char*
+ */
+ std::string _message;
+
+ /**
+ * The PHP exception code
+ * @var int
+ */
+ int _code;
+
public:
- /**
- * Constructor
- * @param &string
- */
- Exception(const std::string &message, int code = 0) : std::exception(), _message(message), _code(code)
- {
- }
-
- /**
- * Destructor
- */
- virtual ~Exception()
- {
- }
-
- /**
- * Returns the message of the exception.
- * @return &string
- */
- std::string &message() throw()
- {
- return _message;
- }
+ /**
+ * Constructor
+ * @param &string
+ */
+ Exception(const std::string &message, int code = 0) : std::exception(), _message(message), _code(code)
+ {
+ }
+
+ /**
+ * Destructor
+ */
+ virtual ~Exception()
+ {
+ }
+
+ /**
+ * Returns the message of the exception.
+ * @return &string
+ */
+ std::string &message() throw()
+ {
+ return _message;
+ }
};
/**
diff --git a/include/extension.h b/include/extension.h
index 3555fb6..862549a 100644
--- a/include/extension.h
+++ b/include/extension.h
@@ -35,7 +35,7 @@ class Extension;
/**
* Optional callback types for starting and stopping the request
- * @param extension
+ * @param extension
*/
typedef bool (*request_callback)(Extension *extension);
diff --git a/include/globals.h b/include/globals.h
index b3ee6c3..6faeb8a 100644
--- a/include/globals.h
+++ b/include/globals.h
@@ -1,11 +1,11 @@
/**
* Globals.h
*
- * Wrapper object that gives access to all global variables. You
+ * Wrapper object that gives access to all global variables. You
* can use it more or less the same as the $_GLOBALS object in
- * PHP.
+ * PHP.
*
- * The global PHP variables are acessible via the Php::globals["varname"]
+ * The global PHP variables are acessible via the Php::globals["varname"]
* variables.
*
* @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
@@ -87,16 +87,16 @@ private:
Globals() {}
public:
- /**
- * Get the one and only instance
- * @return Globals
- */
- static Globals &instance();
+ /**
+ * Get the one and only instance
+ * @return Globals
+ */
+ static Globals &instance();
};
/**
* We always have one instance
- * @var Globals
+ * @var Globals
*/
extern Globals &globals;
diff --git a/include/value.h b/include/value.h
index b2ce89b..09392ad 100644
--- a/include/value.h
+++ b/include/value.h
@@ -264,7 +264,7 @@ public:
* Change the internal type of the variable
* @param Type
*/
- Value &setType(Type type);
+ virtual Value &setType(Type type);
/**
* Make a clone of the value with the same type
@@ -290,7 +290,7 @@ public:
bool isFloat() const { return type() == floatType; }
bool isObject() const { return type() == objectType; }
bool isArray() const { return type() == arrayType; }
- bool isCallable() const;
+ bool isCallable() const;
/**
* Retrieve the value as number
@@ -531,7 +531,7 @@ public:
/**
* Call the function in PHP
* We have ten variants of this function, depending on the number of parameters
- * This call operator is only useful when the variable represents a callable
+ * This call operator is only useful when the variable represents a callable
* @param name Name of the function
* @return Value
*/
@@ -548,13 +548,13 @@ public:
Value operator()(Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8, Value p9);
private:
- /**
- * Call function with a number of parameters
- * @param argc Number of parameters
- * @param argv The parameters
- * @return Value
- */
- Value exec(int argc, struct _zval_struct ***params);
+ /**
+ * Call function with a number of parameters
+ * @param argc Number of parameters
+ * @param argv The parameters
+ * @return Value
+ */
+ Value exec(int argc, struct _zval_struct ***params);
protected:
/**
@@ -564,6 +564,14 @@ protected:
struct _zval_struct *_val;
/**
+ * Validate the value
+ * This is a overridable function that is implemented in base classes to
+ * ensure that a value of certain type stays valid
+ * @return Value
+ */
+ virtual Value &validate() { return *this; }
+
+ /**
* The Globals and Member classes can access the zval directly
*/
friend class Globals;