diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-03-04 09:27:01 +0100 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-03-04 09:27:01 +0100 |
commit | 59cfe935248918c1151b300eb19496b76ed579a9 (patch) | |
tree | e4f00380d599fe3f7cc9399edead14ca1b74a6f9 /include/array.h | |
parent | ecc297108d2851af885c1fb28434769f9478649d (diff) |
removed forcedvalue and implemented array and object directly because now it is easier to finetune these classes, removed the Value::validate() method because it does not seem to be necessary, Object constructor now also accepts Php::Value objects that hold a string, to instantiate the described class
Diffstat (limited to 'include/array.h')
-rw-r--r-- | include/array.h | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/include/array.h b/include/array.h new file mode 100644 index 0000000..94d2824 --- /dev/null +++ b/include/array.h @@ -0,0 +1,115 @@ +/** + * Array.h + * + * The Array is a wrapper around the value class that ensures that a + * certain property always is an array + * + * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> + * @copyright 2013, 2014 Copernica BV + */ + +/** + * Set up namespace + */ +namespace Php { + +/** + * Class definition + */ +class Array : public Value +{ +public: + /** + * Constructor + */ + Array() : Value() { setType(Type::Array); } + + /** + * Copy constructor from a value object + * @param value + */ + Array(const Value &value) : Value(value) + { + // type must be valid + if (value.type() != Type::Array) throw Php::Exception("Assiging a non-array to an array variable"); + } + + /** + * Move constructor from a value object + * @param value + */ + Array(Value &&value) : Value(std::move(value)) + { + // type must be valid + if (value.type() != Type::Array) throw Php::Exception("Moving a non-array to an array variable"); + } + + /** + * Destructor + */ + virtual ~Array() {} + + /** + * Change the internal type of the variable + * @param Type + */ + virtual Value &setType(Type type) override + { + // throw exception if things are going wrong + if (type != Type::Array) throw Php::Exception("Changing type of a fixed array variable"); + + // call base + return Value::setType(Type::Array); + } + + /** + * Assignment operator + * @param value + * @return Array + */ + Array &operator=(const Value &value) + { + // skip self assignment + if (this == &value) return *this; + + // type must be valid + if (value.type() != Type::Array) throw Php::Exception("Assiging a non-array to a fixed array variable"); + + // call base + Value::operator=(value); + + // done + return *this; + } + + /** + * Move assignment operator + * @param value + * @return Array + */ + Array &operator=(Value &&value) + { + // skip self assignment + if (this == &value) return *this; + + // type must be valid + if (value.type() != Type::Array) throw Php::Exception("Moving a non-array to a fixed array variable"); + + // call base + Value::operator=(std::move(value)); + + // done + return *this; + } +}; + +/** + * Define for arrays and objects + */ +using Array = Array; + +/** + * End of namespace + */ +} + |