diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/class.h | 48 | ||||
-rw-r--r-- | include/classbase.h | 35 | ||||
-rw-r--r-- | include/interface.h | 46 | ||||
-rw-r--r-- | include/namespace.h | 28 |
4 files changed, 121 insertions, 36 deletions
diff --git a/include/class.h b/include/class.h index 72615e5..61d5856 100644 --- a/include/class.h +++ b/include/class.h @@ -64,14 +64,28 @@ public: * @param flags Optional flags * @param args Argument descriptions */ - void add(const char *name, void(T::*method)(), int flags = Public, const Arguments &args = {}) { ClassBase::add(name, static_cast<method_callback_0>(method), flags, args); } - void add(const char *name, void(T::*method)(Parameters ¶ms), int flags = Public, const Arguments &args = {}) { ClassBase::add(name, static_cast<method_callback_1>(method), flags, args); } - void add(const char *name, bool(T::*method)(), int flags = Public, const Arguments &args = {}) { ClassBase::add(name, static_cast<method_callback_2>(method), flags, args); } - void add(const char *name, bool(T::*method)(Parameters ¶ms), int flags = Public, const Arguments &args = {}) { ClassBase::add(name, static_cast<method_callback_3>(method), flags, args); } - void add(const char *name, void(T::*method)(), const Arguments &args = {}) { ClassBase::add(name, static_cast<method_callback_0>(method), Public, args); } - void add(const char *name, void(T::*method)(Parameters ¶ms), const Arguments &args = {}) { ClassBase::add(name, static_cast<method_callback_1>(method), Public, args); } - void add(const char *name, bool(T::*method)(), const Arguments &args = {}) { ClassBase::add(name, static_cast<method_callback_2>(method), Public, args); } - void add(const char *name, bool(T::*method)(Parameters ¶ms), const Arguments &args = {}) { ClassBase::add(name, static_cast<method_callback_3>(method), Public, args); } + void method(const char *name, void(T::*method)(), int flags, const Arguments &args = {}) { ClassBase::method(name, static_cast<method_callback_0>(method), flags, args); } + void method(const char *name, void(T::*method)(Parameters ¶ms), int flags, const Arguments &args = {}) { ClassBase::method(name, static_cast<method_callback_1>(method), flags, args); } + void method(const char *name, bool(T::*method)(), int flags, const Arguments &args = {}) { ClassBase::method(name, static_cast<method_callback_2>(method), flags, args); } + void method(const char *name, bool(T::*method)(Parameters ¶ms), int flags, const Arguments &args = {}) { ClassBase::method(name, static_cast<method_callback_3>(method), flags, args); } + void method(const char *name, void(T::*method)(), const Arguments &args = {}) { ClassBase::method(name, static_cast<method_callback_0>(method), Public, args); } + void method(const char *name, void(T::*method)(Parameters ¶ms), const Arguments &args = {}) { ClassBase::method(name, static_cast<method_callback_1>(method), Public, args); } + void method(const char *name, bool(T::*method)(), const Arguments &args = {}) { ClassBase::method(name, static_cast<method_callback_2>(method), Public, args); } + void method(const char *name, bool(T::*method)(Parameters ¶ms), const Arguments &args = {}) { ClassBase::method(name, static_cast<method_callback_3>(method), Public, args); } + + /** + * Add an abstract method to the class + * + * This is only meaningful for classes that can be extended. Because the + * method is abstract, you will not have to pass an implementation. You + * can pass in flags to mark the method as protected + * + * @param name Name of the method + * @param flags Optional flags + * @param args Argument descriptions + */ + void method(const char *name, int flags, const Arguments &args = {}) { ClassBase::method(name, flags | Abstract, args); } + void method(const char *name, const Arguments &args = {}) { ClassBase::method(name, Public | Abstract, args); } /** * Add a property to the class @@ -86,15 +100,15 @@ public: * @param value Actual property value * @param flags Optional flags */ - void add(const char *name, std::nullptr_t value, int flags = Public) { ClassBase::add(name, value, flags); } - void add(const char *name, uint64_t value, int flags = Public) { ClassBase::add(name, value, flags); } - void add(const char *name, uint32_t value, int flags = Public) { ClassBase::add(name, value, flags); } - void add(const char *name, uint16_t value, int flags = Public) { ClassBase::add(name, value, flags); } - void add(const char *name, char value, int flags = Public) { ClassBase::add(name, value, flags); } - void add(const char *name, const char *value, int flags = Public) { ClassBase::add(name, value, flags); } - void add(const char *name, const std::string &value, int flags = Public) { ClassBase::add(name, value, flags); } - void add(const char *name, bool value, int flags = Public) { ClassBase::add(name, value, flags); } - void add(const char *name, double value, int flags = Public) { ClassBase::add(name, value, flags); } + void property(const char *name, std::nullptr_t value, int flags = Public) { ClassBase::property(name, value, flags); } + void property(const char *name, uint64_t value, int flags = Public) { ClassBase::property(name, value, flags); } + void property(const char *name, uint32_t value, int flags = Public) { ClassBase::property(name, value, flags); } + void property(const char *name, uint16_t value, int flags = Public) { ClassBase::property(name, value, flags); } + void property(const char *name, char value, int flags = Public) { ClassBase::property(name, value, flags); } + void property(const char *name, const char *value, int flags = Public) { ClassBase::property(name, value, flags); } + void property(const char *name, const std::string &value, int flags = Public) { ClassBase::property(name, value, flags); } + void property(const char *name, bool value, int flags = Public) { ClassBase::property(name, value, flags); } + void property(const char *name, double value, int flags = Public) { ClassBase::property(name, value, flags); } protected: /** diff --git a/include/classbase.h b/include/classbase.h index 98a430e..1cfba83 100644 --- a/include/classbase.h +++ b/include/classbase.h @@ -109,10 +109,19 @@ protected: * @param flags Optional flags * @param args Description of the supported arguments */ - void add(const char *name, method_callback_0, int flags=0, const Arguments &args = {}); - void add(const char *name, method_callback_1, int flags=0, const Arguments &args = {}); - void add(const char *name, method_callback_2, int flags=0, const Arguments &args = {}); - void add(const char *name, method_callback_3, int flags=0, const Arguments &args = {}); + void method(const char *name, method_callback_0, int flags=0, const Arguments &args = {}); + void method(const char *name, method_callback_1, int flags=0, const Arguments &args = {}); + void method(const char *name, method_callback_2, int flags=0, const Arguments &args = {}); + void method(const char *name, method_callback_3, int flags=0, const Arguments &args = {}); + + /** + * Add an abstract method to the class + * + * @param name Name of the method + * @param flags Optional flags (like public or protected) + * @param args Description of the supported arguments + */ + void method(const char *name, int flags=0, const Arguments &args = {}); /** * Add a property to the class @@ -127,15 +136,15 @@ protected: * @param value Actual property value * @param flags Optional flags */ - void add(const char *name, std::nullptr_t value, int flags = Php::Public); - void add(const char *name, int16_t value, int flags = Php::Public); - void add(const char *name, int32_t value, int flags = Php::Public); - void add(const char *name, int64_t value, int flags = Php::Public); - void add(const char *name, bool value, int flags = Php::Public); - void add(const char *name, char value, int flags = Php::Public); - void add(const char *name, const std::string &value, int flags = Php::Public); - void add(const char *name, const char *value, int flags = Php::Public); - void add(const char *name, double value, int flags = Php::Public); + void property(const char *name, std::nullptr_t value, int flags = Php::Public); + void property(const char *name, int16_t value, int flags = Php::Public); + void property(const char *name, int32_t value, int flags = Php::Public); + void property(const char *name, int64_t value, int flags = Php::Public); + void property(const char *name, bool value, int flags = Php::Public); + void property(const char *name, char value, int flags = Php::Public); + void property(const char *name, const std::string &value, int flags = Php::Public); + void property(const char *name, const char *value, int flags = Php::Public); + void property(const char *name, double value, int flags = Php::Public); private: diff --git a/include/interface.h b/include/interface.h index 7bdb5d6..38f85f3 100644 --- a/include/interface.h +++ b/include/interface.h @@ -11,11 +11,49 @@ namespace Php { /** - * @todo implementation, should be somehow an extension of a regular - * class, but without methods to define methods - * - * the flag that should be passed to the base it 0x80 + * Class definition */ +class Interface : private ClassBase +{ +public: + /** + * Constructor + * @param name + */ + Interface(const char *name) : ClassBase(name, 0x80) {} + + /** + * Destructor + */ + virtual ~Interface() {} + + /** + * Add a - of course abstract - method to the interface + * @param name Name of the method + * @param arguments Optional description of the arguments + */ + void method(const char *name, const Arguments &arguments = {}) + { + // call base + ClassBase::method(name, Abstract | Public, arguments); + } + +private: + /** + * Construct a new instance of the object + * @return Base + */ + virtual Base* construct() override + { + // this does not occur for interfaces + return nullptr; + } + + /** + * Namespaces have access to the private base class + */ + friend class Namespace; +}; /** * End namespace diff --git a/include/namespace.h b/include/namespace.h index ef625fc..4cbf43e 100644 --- a/include/namespace.h +++ b/include/namespace.h @@ -78,7 +78,6 @@ public: /** * Add a native class to the extension by moving it - * @param name Name of the class * @param type The class implementation */ template<typename T> @@ -93,7 +92,6 @@ public: /** * Add a native class to the extension by copying it - * @param name Name of the class * @param type The class implementation */ template<typename T> @@ -105,6 +103,32 @@ public: // and add it to the list of classes _classes.push_back(std::unique_ptr<ClassBase>(copy)); } + + /** + * Add an interface to the extension by moving it + * @param interface The interface properties + */ + void add(Interface &&interface) + { + // make a copy of the object + auto *copy = new Interface(std::move(interface)); + + // and add it to the list of classes + _classes.push_back(std::unique_ptr<ClassBase>(copy)); + } + + /** + * Add an interface to the extension by copying it + * @param interface The interface properties + */ + void add(const Interface &interface) + { + // make a copy of the object + auto *copy = new Interface(interface); + + // and add it to the list of classes + _classes.push_back(std::unique_ptr<ClassBase>(copy)); + } /** * Add a namespace to the extension by moving it |