summaryrefslogtreecommitdiff
path: root/include/class.h
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-02-28 10:25:01 +0100
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-02-28 10:25:01 +0100
commit71055ebdea1e8eec30747a04f36e0c10e750bff5 (patch)
tree18ed63d5fe64a936c284a38d4f72921a4ddc97df /include/class.h
parent85349bbb642a83012a7d0dbccde8b7c1eea1b914 (diff)
a lot of refactoring, to make it much easier to define classes in an extension
Diffstat (limited to 'include/class.h')
-rw-r--r--include/class.h135
1 files changed, 61 insertions, 74 deletions
diff --git a/include/class.h b/include/class.h
index b440b02..ae66277 100644
--- a/include/class.h
+++ b/include/class.h
@@ -28,102 +28,89 @@ namespace Php {
/**
* Class definition of the class
*/
-template <typename T, ClassModifier _flags = ClassModifier::regular>
-class Class
+template <typename T>
+class Class : private ClassBase
{
public:
/**
* Constructor
+ *
+ * The flags can be a combination of Php::Final and Php::Abstract. If no
+ * flags are set, a regular public class will be formed.
+ *
+ * @param name Name of the class
+ * @param flags Optional flags (final, abstract)
+ *
+ * @todo make sure flags are used
*/
- Class() {}
-
- /**
- * Constructor with initializer list to define the properties
- * @param members
- */
- Class(const std::initializer_list<Member> &members) : _members(members) {}
-
- /**
- * Move constructor
- * @param that
- */
- Class(Class &&that) : _members(std::move(that._members)) {}
-
- /**
- * Copy constructor
- */
- Class(const Class &that) : _members(that._members) {}
+ Class(const char *name, int flags = 0) : ClassBase(name, flags) {}
/**
* Destructor
*/
virtual ~Class() {}
-
+
/**
- * Construct an instance
- * @return Base
+ * Add a property to the class
+ *
+ * Every instance of this class will have this property. The property
+ * can be Php::Public, Php::Protected or Php::Private (altough setting
+ * private properties is odd as the implementation of the class is in CPP,
+ * so why use private properties while the whole implementation is already
+ * hidden)
+ *
+ * @param name Name of the property
+ * @param property Actual property value
+ * @param flags Optional flags
*/
- Base* construct()
- {
- // allocate the object
- return new T();
- }
-
+// void add(const char *name, const Property &property, int flags = Php::Public)
+// {
+// // @todo something with the flags
+// _properties[name] = property;
+// }
+
/**
- * Initialize the class
- * This will declare all members
- * @param entry
+ * Add a method to the class
+ *
+ * The method will be accessible as one of the class methods in your PHP
+ * code. When the method is called, it will automatically be forwarded
+ * to the C++ implementation. The flags can be Php::Public, Php::Protected
+ * or Php::Private (using private methods can be useful if you for example
+ * want to make the __construct() function private). The access-modified
+ * flag can be bitwise combined with the flag Php::Final or Php::Abstract).
+ *
+ * @param name Name of the method
+ * @param method The actual method
+ * @param flags Optional flags
+ * @param args Argument descriptions
*/
- void initialize(struct _zend_class_entry *entry)
- {
- // loop through the members
- for (auto iter = _members.begin(); iter != _members.end(); iter++)
- {
- iter->declare(entry);
- }
- }
-
+ void add(const char *name, void(T::*method)(), int flags = 0, const Arguments &args = {}) { ClassBase::add(name, static_cast<method_callback_0>(method), flags, args); }
+ void add(const char *name, void(T::*method)(Parameters &params), int flags = 0, const Arguments &args = {}) { ClassBase::add(name, static_cast<method_callback_1>(method), flags, args); }
+ void add(const char *name, bool(T::*method)(), int flags = 0, const Arguments &args = {}) { ClassBase::add(name, static_cast<method_callback_2>(method), flags, args); }
+ void add(const char *name, bool(T::*method)(Parameters &params), int flags = 0, 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), 0, args); }
+ void add(const char *name, void(T::*method)(Parameters &params), const Arguments &args = {}) { ClassBase::add(name, static_cast<method_callback_1>(method), 0, args); }
+ void add(const char *name, bool(T::*method)(), const Arguments &args = {}) { ClassBase::add(name, static_cast<method_callback_2>(method), 0, args); }
+ void add(const char *name, bool(T::*method)(Parameters &params), const Arguments &args = {}) { ClassBase::add(name, static_cast<method_callback_3>(method), 0, args); }
+
+private:
/**
- * Retrieve the functions
- * @param classname
- * @return zend_function_entry*
- */
- struct _zend_function_entry *methods(const char *classname)
- {
- return _members.methods(classname);
- }
-
- /**
- * Retrieve the class flags specifying whether the class
- * is a regular class, abstract or final
- *
- * @return int flags of access types for classes
+ * Construct a new instance of the object
+ * @return Base
*/
- int getFlags()
+ virtual Base* construct() override
{
- return _flags;
+ // construct an instance
+ return new T();
}
-
-protected:
+
/**
- * The initial arguments
- * @var Members
+ * Extensions have access to the private base class
*/
- Members _members;
-
+ friend class Extension;
+
};
-
-// C++11 analog of `typedef`. Equivalent to the following pseudocode: typedef ClassFlagged<T, Zend::AccClass::FINAL> FinalClass<T>;
-template <typename T>
-using FinalClass = Class<T, ClassModifier::final>;
-
-template <typename T>
-using AbstractClass = Class<T, ClassModifier::abstract>;
-
-template <typename T>
-using Interface = Class<T, ClassModifier::interface>;
-
/**
* End of namespace
*/