From e14055694478d70e58b5fc653b08a9a514bbc455 Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Sun, 25 Aug 2013 17:40:03 +0200 Subject: {more work in progress: the function that was defined with c++ now gets calls, but it does not yet call the actual implementation --- include/argument.h | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 include/argument.h (limited to 'include/argument.h') diff --git a/include/argument.h b/include/argument.h new file mode 100644 index 0000000..862b677 --- /dev/null +++ b/include/argument.h @@ -0,0 +1,125 @@ +/** + * Argument.h + * + * Class holds information about an argument that is passed to a function. + * You'll need this class when you're defining your own functions. + * + * @author Emiel Bruijntjes + * @copyright 2013 Copernica BV + */ + +/** + * Set up namespace + */ +namespace PhpCpp { + +/** + * Forward definitions + */ +class ArgInfo; + +/** + * Class definition + */ +class Argument +{ +public: + /** + * Constructor if this argument should be an instance of a certain class + * @param name Name of the argument + * @param classname If a specific class is required, the class type + * @param null Are NULL values allowed in stead of an instance? + * @param ref Is this a pass-by-reference argument? + */ + Argument(const std::string &name, const std::string &classname, bool null = true, bool ref = false); + + /** + * Constructor if the argument can be anything + * @param name Name of the argument + * @param type Type hint + * @param ref Is this a pass-by-reference argument? + */ + Argument(const std::string &name, Type type = nullType, bool ref = false); + + /** + * Copy constructor + * @param argument The argument to copy + */ + Argument(const Argument &argument) + { + // copy members + _refcount = argument._refcount; + _info = argument._info; + + // increase references + (*_refcount)++; + } + + /** + * Destructor + */ + virtual ~Argument() + { + // cleanup current object + cleanup(); + } + + /** + * Copy operator + * @param argument The argument to copy + * @return Argument + */ + Argument &operator=(const Argument &argument) + { + // skip self assignment + if (this == &argument) return *this; + + // clean up current object + cleanup(); + + // copy members + _refcount = argument._refcount; + _info = argument._info; + + // increase references + (*_refcount)++; + + // done + return *this; + } + + /** + * Retrieve argument info + * @return ArgInfo + * @internal + */ + ArgInfo *internal() const + { + return _info; + } + +private: + /** + * Number of references + * @var int + */ + int *_refcount; + + /** + * Pointer to the implementation + * @var ArgInfo + */ + ArgInfo *_info; + + /** + * Remove one reference from the object + */ + void cleanup(); + +}; + +/** + * End of namespace + */ +} + -- cgit v1.2.3