summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorMartijn Otto <martijn.otto@copernica.com>2014-02-14 16:30:23 +0100
committerMartijn Otto <martijn.otto@copernica.com>2014-02-14 16:30:23 +0100
commit06aa5fd5afaba69544b93654fb0a4f9c2651306e (patch)
tree99cd2ee120786a84531b450f9ef64e2319ef5192 /include
parent5c23fee5ce58ae66a70f3bd19a1dc2dff7220f13 (diff)
Merged pull request #14
Diffstat (limited to 'include')
-rw-r--r--include/class.h44
-rw-r--r--include/classinfo.h22
-rw-r--r--include/extension.h2
-rw-r--r--include/flag.h135
-rw-r--r--include/function.h2
-rw-r--r--include/member.h44
-rw-r--r--include/membervisibility.h73
-rw-r--r--include/protected.h55
-rw-r--r--include/public.h56
-rw-r--r--include/zend.h85
10 files changed, 373 insertions, 145 deletions
diff --git a/include/class.h b/include/class.h
index 3746cf3..201f4de 100644
--- a/include/class.h
+++ b/include/class.h
@@ -11,6 +11,7 @@
* Note that YourClass must extend from Php::Object
*
* @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
+ * changed by Valeriy Dmitriev <ufabiz@gmail.com>
* @copyright 2013 Copernica BV
*/
@@ -40,18 +41,18 @@ public:
* Constructor with initializer list to define the properties
* @param members
*/
- Class(const std::initializer_list<Member> &members) : _members(members) {}
+ Class(const std::initializer_list<Member> &members, FlagClass flags = FlagClass(Zend::AccClass::NOSET)) : _members(members), _flags(flags) {}
/**
* Move constructor
* @param that
*/
- Class(Class &&that) : _members(std::move(that._members)) {}
+ Class(Class &&that) : _members(std::move(that._members)), _flags(std::move(that._flags)) {}
/**
* Copy constructor
*/
- Class(const Class &that) : _members(that._members) {}
+ Class(const Class &that) : _members(that._members), _flags(that._flags) {}
/**
* Destructor
@@ -91,6 +92,14 @@ public:
{
return _members.methods(classname);
}
+
+ /**
+ * Retrieve the int access types flags for PHP class
+ * @return int flags of access types for classes
+ */
+ int getFlags() {
+ return _flags;
+ }
protected:
/**
@@ -99,8 +108,37 @@ protected:
*/
Members _members;
+private:
+ /**
+ * The access types flags for class
+ */
+ FlagClass _flags;
+
};
+
+/**
+ * Class definition of the ClassFlagged
+ * template ClassFlagged designed for easy instance of Class<T> for concrete flags
+ */
+template <typename T, Zend::AccClass Flags>
+class ClassFlagged : public Class<T>
+{
+public:
+ ClassFlagged() : Class<T>() {}
+ ClassFlagged(const std::initializer_list<Member> &members) : Class<T>(members, FlagClass(Flags)) {}
+};
+
+template <typename T>
+// C++11 analog of `typedef`. Equivalent to the following pseudocode: typedef ClassFlagged<T, Zend::AccClass::FINAL> FinalClass<T>;
+using FinalClass = ClassFlagged<T, Zend::AccClass::FINAL>;
+template <typename T>
+using AbstractClass = ClassFlagged<T, Zend::AccClass::ABSTRACT>;
+template <typename T>
+using Interface = ClassFlagged<T, Zend::AccClass::INTERFACE>;
+template <typename T>
+using Trait = ClassFlagged<T, Zend::AccClass::TRAIT>;
+
/**
* End of namespace
*/
diff --git a/include/classinfo.h b/include/classinfo.h
index 276bc63..070dcd5 100644
--- a/include/classinfo.h
+++ b/include/classinfo.h
@@ -52,16 +52,16 @@ public:
void initialize();
/**
- * Construct the C++ object
- * @return Base
- */
- virtual Base *construct() = 0;
-
- /**
* Initialize the class
* @param entry
*/
virtual void initialize(struct _zend_class_entry *entry) = 0;
+
+ /**
+ * Construct the C++ object
+ * @return Base
+ */
+ virtual Base *construct() = 0;
/**
* Retrieve the methods
@@ -69,6 +69,11 @@ public:
*/
virtual struct _zend_function_entry *methods() = 0;
+ /**
+ * set access types flags for class
+ */
+ void seFlags(struct _zend_class_entry *entry, int flags);
+
protected:
/**
* The class entry
@@ -130,8 +135,11 @@ public:
* Initialize the class
* @param entry
*/
- virtual void initialize(struct _zend_class_entry *entry)
+ virtual void initialize(struct _zend_class_entry *entry) override
{
+ // set access types flags for class
+ seFlags(entry, _type.getFlags());
+
// pass to the entry
_type.initialize(entry);
}
diff --git a/include/extension.h b/include/extension.h
index 862549a..1082bcb 100644
--- a/include/extension.h
+++ b/include/extension.h
@@ -178,7 +178,7 @@ public:
void add(const char *name, const Class<T> &type)
{
// construct info
- ClassInfo<T> *info = new ClassInfo<T>(name, type);
+ _ClassInfo *info = new ClassInfo<T>(name, type);
// add class
_classes.insert(std::unique_ptr<_ClassInfo>(info));
diff --git a/include/flag.h b/include/flag.h
new file mode 100644
index 0000000..beb79ba
--- /dev/null
+++ b/include/flag.h
@@ -0,0 +1,135 @@
+/**
+ * flag.h
+ *
+ * flag clases for the safe transfer of a Zend flag to a Zend functions
+ *
+ * @author Valeriy_Dmitriev <ufabiz@gmail.com>
+ */
+
+#ifndef PHPCPP_FLAG_INCLUDE_C_H_
+#define PHPCPP_FLAG_INCLUDE_C_H_
+
+/**
+ * Namespace Php
+ */
+namespace Php {
+
+
+ /**
+ * class FlagTemplate
+ * Designed for the safe transfer of a Zend flag to a Zend functions
+ */
+ template <class AccT>
+ class FlagTemplate
+ {
+ public:
+ /**
+ * Constructor
+ */
+ FlagTemplate(const AccT &zflag);
+
+ /**
+ * Copy constructor
+ * @param FlagTemplate The FlagTemplate to copy
+ */
+ FlagTemplate(const FlagTemplate &flags) : _val(flags._val) {}
+
+ /**
+ * Move constructor
+ * @param FlagTemplate The FlagTemplate to move
+ */
+ FlagTemplate(FlagTemplate &&flags) : _val(std::move(flags._val)){}
+
+ /**
+ * Assignment operator
+ */
+ FlagTemplate &operator=(const FlagTemplate &flags) {
+ if (this != &flags) {
+ _val = flags._val;
+ }
+ return *this;
+ }
+
+ /**
+ * Move operator
+ */
+ FlagTemplate &operator=(FlagTemplate &&flags) {
+ if (this != &flags) {
+ _val = std::move(flags._val);
+ }
+ return *this;
+ }
+
+ /**
+ * Bitwise OR assignment operator
+ */
+ FlagTemplate &operator|=(const FlagTemplate &flags) {
+ _val |= flags._val;
+ return *this;
+ }
+
+ /**
+ * Bitwise OR operator
+ */
+ FlagTemplate operator|(const FlagTemplate &flags) {
+ return FlagTemplate (_val | flags._val);
+ }
+
+ /**
+ * Cast to a int
+ * @return int
+ */
+ operator int () const {
+ return _val;
+ }
+
+ /**
+ * Destructor
+ */
+ ~FlagTemplate () {}
+
+ private:
+
+ /**
+ * Private constructor
+ * @param int val
+ */
+ FlagTemplate(const int &val) :_val(val) {}
+
+ /**
+ * Private constructor
+ * @param void
+ */
+ FlagTemplate() {}
+
+ /**
+ * value of flag
+ */
+ int _val;
+ };
+
+ /**
+ * class FlagClass
+ * For the safe transfer of a Zend Class flags to a Zend functions
+ */
+ typedef FlagTemplate<Zend::AccClass> FlagClass;
+ /**
+ * class FlagClass
+ * For the safe transfer of a Zend access types for methods and propertyes
+ */
+ typedef FlagTemplate<Zend::AccMemb> FlagMemb;
+
+
+ /**
+ * factory function
+ */
+ FlagClass Flag(const Zend::AccClass &zflag);
+ FlagMemb Flag(const Zend::AccMemb &zflag);
+
+
+/**
+ * End of namespace Php
+ */
+}
+
+#endif /* PHPCPP_FLAG_INCLUDE_C_H_ */ \ No newline at end of file
diff --git a/include/function.h b/include/function.h
index d2461ef..ea7584f 100644
--- a/include/function.h
+++ b/include/function.h
@@ -141,7 +141,7 @@ protected:
* @param classname Optional class name
* @param pub Is this a public property?
*/
- void fill(struct _zend_function_entry *entry, const char *classname=NULL, bool pub=true) const;
+ void fill(struct _zend_function_entry *entry, const char *classname=NULL, int flags=Flag(Zend::AccMemb::PUBLIC)) const;
/**
* Fill function info
diff --git a/include/member.h b/include/member.h
index bc96e52..347555a 100644
--- a/include/member.h
+++ b/include/member.h
@@ -31,82 +31,82 @@ public:
/**
* Constructor
* @param name Name of the member
- * @param pub Is this a public property (otherwise it is protected)
+ * @param flags Flag access to a class member (bublic, protected etc)
*/
- Member(const char *name, bool pub);
+ Member(const char *name, const FlagMemb &&flags);
/**
* Constructor
* @param name Name of the member
- * @param pub Is this a public property (otherwise it is protected)
+ * @param flags Flag access to a class member (bublic, protected etc)
* @param value The value to add
*/
- Member(const char *name, bool pub, std::nullptr_t value);
+ Member(const char *name, const FlagMemb &&flags, std::nullptr_t value);
/**
* Constructor
* @param name Name of the member
- * @param pub Is this a public property (otherwise it is protected)
+ * @param flags Flag access to a class member (bublic, protected etc)
* @param value The value to add
*/
- Member(const char *name, bool pub, int value);
+ Member(const char *name, const FlagMemb &&flags, int value);
/**
* Constructor
* @param name Name of the member
- * @param pub Is this a public property (otherwise it is protected)
+ * @param flags Flag access to a class member (bublic, protected etc)
* @param value The value to add
*/
- Member(const char *name, bool pub, long value);
+ Member(const char *name, const FlagMemb &&flags, long value);
/**
* Constructor
* @param name Name of the member
- * @param pub Is this a public property (otherwise it is protected)
+ * @param flags Flag access to a class member (bublic, protected etc)
* @param value The value to add
*/
- Member(const char *name, bool pub, bool value);
+ Member(const char *name, const FlagMemb &&flags, bool value);
/**
* Constructor
* @param name Name of the member
- * @param pub Is this a public property (otherwise it is protected)
+ * @param flags Flag access to a class member (bublic, protected etc)
* @param value The value to add
*/
- Member(const char *name, bool pub, char value);
+ Member(const char *name, const FlagMemb &&flags, char value);
/**
* Constructor
* @param name Name of the member
- * @param pub Is this a public property (otherwise it is protected)
+ * @param flags Flag access to a class member (bublic, protected etc)
* @param value The value to add
*/
- Member(const char *name, bool pub, const std::string &value);
+ Member(const char *name, const FlagMemb &&flags, const std::string &value);
/**
* Constructor
* @param name Name of the member
- * @param pub Is this a public property (otherwise it is protected)
+ * @param flags Flag access to a class member (bublic, protected etc)
* @param value The value to add
* @param size String length
*/
- Member(const char *name, bool pub, const char *value, int size = -1);
+ Member(const char *name, const FlagMemb &&flags, const char *value, int size = -1);
/**
* Constructor
* @param name Name of the member
- * @param pub Is this a public property (otherwise it is protected)
+ * @param flags Flag access to a class member (bublic, protected etc)
* @param value The value to add
*/
- Member(const char *name, bool pub, double value);
+ Member(const char *name, const FlagMemb &&flags, double value);
/**
* Constructor
* @param name Name of the method
- * @param pub Is this a public method (otherwise it is protected)
+ * @param flags Flag access to a class member (bublic, protected etc)
* @param method The method to add
*/
- Member(const char *name, bool pub, const _Method &method, const std::initializer_list<Argument> &arguments = {});
+ Member(const char *name, const FlagMemb &&flags, const _Method &method, const std::initializer_list<Argument> &arguments = {});
/**
* Copy constructor
@@ -161,10 +161,10 @@ private:
std::string _name;
/**
- * Is this a public property
+ * Flag access to a class member (bublic, protected etc)
* @var bool
*/
- bool _public;
+ FlagMemb _accflag;
/**
* The implementation for the member
diff --git a/include/membervisibility.h b/include/membervisibility.h
new file mode 100644
index 0000000..a0a11ea
--- /dev/null
+++ b/include/membervisibility.h
@@ -0,0 +1,73 @@
+/**
+ * membervisibility.h
+ *
+ * MemberVisibility - Template for a visibility of a property or method
+ * Instead of defining three classes Public, Protected and Private defined template class. And these classes are obtained by applying to the class template typedef MemberVisibility.
+ * In the future, so it is possible to create such a class scope `Static`
+ *
+ * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
+ * changed by Valeriy Dmitriev <ufabiz@gmail.com>
+ * @copyright 2013 Copernica BV
+ */
+
+/**
+ * Namespace
+ */
+namespace Php {
+
+/**
+ * Class definition
+ */
+template <Zend::AccMemb AccFlag>
+class MemberVisibility : public Member
+{
+public:
+ /**
+ * Constructor
+ * @param name Name of the property
+ * @param value Default value of the property
+ */
+ MemberVisibility(const char *name) : Member(name, FlagMemb(AccFlag)) {}
+ MemberVisibility(const char *name, std::nullptr_t value) : Member(name, FlagMemb(AccFlag), value) {}
+ MemberVisibility(const char *name, int value) : Member(name, FlagMemb(AccFlag), value) {}
+ MemberVisibility(const char *name, long value) : Member(name, FlagMemb(AccFlag), value) {}
+ MemberVisibility(const char *name, bool value) : Member(name, FlagMemb(AccFlag), value) {}
+ MemberVisibility(const char *name, char value) : Member(name, FlagMemb(AccFlag), value) {}
+ MemberVisibility(const char *name, const std::string &value) : Member(name, FlagMemb(AccFlag), value) {}
+ MemberVisibility(const char *name, const char *value, int size=-1) : Member(name, FlagMemb(AccFlag), value, size) {}
+ MemberVisibility(const char *name, double value) : Member(name, FlagMemb(AccFlag), value) {}
+
+ /**
+ * Constructor
+ * @param name Name of the property
+ * @param method Method to add
+ * @param arguments Optional argument information
+ */
+ MemberVisibility(const char *name, const _Method &method, const std::initializer_list<Argument> &arguments = {}) : Member(name, FlagMemb(AccFlag), method, arguments) {}
+
+ /**
+ * Destructor
+ */
+ virtual ~MemberVisibility() {}
+
+};
+
+typedef MemberVisibility<Zend::AccMemb::PUBLIC> Public;
+typedef MemberVisibility<Zend::AccMemb::PROTECTED> Protected;
+typedef MemberVisibility<Zend::AccMemb::PRIVATE> Private;
+typedef MemberVisibility<Zend::AccMemb::CONSTANT> Const;
+
+/**
+ * In the current architecture, implementation of static methods is not possible.
+ *
+ * Static properties are supported.
+ * @todo: Requires some refactoring that it became possible.
+ */
+//typedef MemberVisibility<Zend::AccMemb::STATIC> Static;
+
+
+/**
+ * End of namespace
+ */
+}
+
diff --git a/include/protected.h b/include/protected.h
deleted file mode 100644
index f3e668a..0000000
--- a/include/protected.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * Protected.h
- *
- * Class for adding public properties to a class
- *
- * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
- * @copyright 2013 Copernica BV
- */
-
-/**
- * Namespace
- */
-namespace Php {
-
-/**
- * Class definition
- */
-class Protected : public Member
-{
-public:
- /**
- * Constructor
- * @param name Name of the property
- * @param value Default value of the property
- */
- Protected(const char *name) : Member(name, false) {}
- Protected(const char *name, std::nullptr_t value) : Member(name, false, value) {}
- Protected(const char *name, int value) : Member(name, false, value) {}
- Protected(const char *name, long value) : Member(name, false, value) {}
- Protected(const char *name, bool value) : Member(name, false, value) {}
- Protected(const char *name, char value) : Member(name, false, value) {}
- Protected(const char *name, const std::string &value) : Member(name, false, value) {}
- Protected(const char *name, const char *value, int size=-1) : Member(name, false, value, size) {}
- Protected(const char *name, double value) : Member(name, false, value) {}
-
- /**
- * Constructor
- * @param name Name of the property
- * @param method Method to add
- * @param arguments Optional argument information
- */
- Protected(const char *name, const _Method &method, const std::initializer_list<Argument> &arguments = {}) : Member(name, false, method, arguments) {}
-
- /**
- * Destructor
- */
- virtual ~Protected() {}
-
-};
-
-/**
- * End of namespace
- */
-}
-
diff --git a/include/public.h b/include/public.h
deleted file mode 100644
index 12648a1..0000000
--- a/include/public.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * Public.h
- *
- * Class for adding public properties to a class
- *
- * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
- * @copyright 2013 Copernica BV
- */
-
-/**
- * Namespace
- */
-namespace Php {
-
-/**
- * Class definition
- */
-class Public : public Member
-{
-public:
- /**
- * Constructor
- * @param name Name of the property
- * @param value Default value of the property
- */
- Public(const char *name) : Member(name, true) {}
- Public(const char *name, std::nullptr_t value) : Member(name, true, value) {}
- Public(const char *name, int value) : Member(name, true, value) {}
- Public(const char *name, long value) : Member(name, true, value) {}
- Public(const char *name, bool value) : Member(name, true, value) {}
- Public(const char *name, char value) : Member(name, true, value) {}
- Public(const char *name, const std::string &value) : Member(name, true, value) {}
- Public(const char *name, const char *value, int size=-1) : Member(name, true, value, size) {}
- Public(const char *name, double value) : Member(name, true, value) {}
-
- /**
- * Constructor
- * @param name Name of the property
- * @param method Method to add
- * @param arguments Optional argument information
- */
- Public(const char *name, const _Method &method, const std::initializer_list<Argument> &arguments = {}) : Member(name, true, method, arguments) {}
-
- /**
- * Destructor
- */
- virtual ~Public() {}
-
-
-};
-
-/**
- * End of namespace
- */
-}
-
diff --git a/include/zend.h b/include/zend.h
new file mode 100644
index 0000000..66d82a2
--- /dev/null
+++ b/include/zend.h
@@ -0,0 +1,85 @@
+/**
+ * zend.h
+ *
+ * zend namespace
+ *
+ * @author Valeriy_Dmitriev <ufabiz@gmail.com>
+ */
+
+#ifndef PHPCPP_ZEND_INCLUDE_C_H_
+#define PHPCPP_ZEND_INCLUDE_C_H_
+
+/**
+ * Namespace Php
+ */
+namespace Php {
+
+ /**
+ * collection of Zend constants
+ */
+ namespace Zend {
+
+ /**
+ * access types (flags)
+ * see Zend/zend_compile.h
+ */
+
+ /**
+ * access types for methods and properties
+ * (method flags)
+ */
+ enum class AccMemb {
+ // method flags (types):
+ STATIC ,//= ZEND_ACC_STATIC, //0x01
+ ABSTRACT ,//= ZEND_ACC_ABSTRACT, //0x02
+ FINAL ,//= ZEND_ACC_FINAL, //0x04
+ //IMPLEMENTED_ABSTRACT ,//= ZEND_ACC_IMPLEMENTED_ABSTRACT, //0x08
+ //method flag (bc only), any method that has this flag can be used statically and non statically.
+ //ALLOW_STATIC ,//= ZEND_ACC_ALLOW_STATIC, //0x10000
+
+ // method flags (visibility)
+ // The order of those must be kept - public < protected < private
+ PUBLIC ,//= ZEND_ACC_PUBLIC, //0x100
+ PROTECTED ,//= ZEND_ACC_PROTECTED, //0x200
+ PRIVATE ,//= ZEND_ACC_PRIVATE, //0x400
+ PPP_MASK ,//= ZEND_ACC_PPP_MASK, //(ZEND_ACC_PUBLIC | ZEND_ACC_PROTECTED | ZEND_ACC_PRIVATE)
+
+ // method flags (special method detection)
+ //CTOR ,//= ZEND_ACC_CTOR, //0x2000
+ //DTOR ,//= ZEND_ACC_DTOR, //0x4000
+ //CLONE ,//= ZEND_ACC_CLONE, //0x8000
+
+ //shadow of parent's private method/property
+ //SHADOW ,//= ZEND_ACC_SHADOW //0x20000
+
+ // additional field for designation flag CONSTANT. Not in the Zend engine
+ CONSTANT ,//= 0 //0
+ };
+
+ /**
+ * access types for classes
+ * (class flags)
+ */
+ enum class AccClass {
+ NOSET ,//= .. , //0
+ // ZEND_ACC_IMPLICIT_ABSTRACT_CLASS is used for abstract classes (since it is set by any abstract method even interfaces MAY have it set, too).
+ //IMPLICIT_ABSTRACT ,//= ZEND_ACC_IMPLICIT_ABSTRACT_CLASS, //0x10
+ //ZEND_ACC_EXPLICIT_ABSTRACT_CLASS denotes that a class was explicitly defined as abstract by using the keyword.
+ ABSTRACT ,//= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS, //0x20
+ FINAL ,//= ZEND_ACC_FINAL_CLASS, //0x40
+ INTERFACE ,//= ZEND_ACC_INTERFACE, //0x80
+ TRAIT ,//= ZEND_ACC_TRAIT, //0x120
+
+ //class implement interface(s) flag,
+ //IMPLEMENT_INTERFACES ,//= ZEND_ACC_IMPLEMENT_INTERFACES, //0x80000
+ //IMPLEMENT_TRAITS ,//= ZEND_ACC_IMPLEMENT_TRAITS, //0x400000
+ };
+
+
+ }
+/**
+ * End of namespace Php
+ */
+}
+
+#endif /* PHPCPP_ZEND_INCLUDE_C_H_ */ \ No newline at end of file