From ca595b1d7aa8ed4a482b8a5ea598ecc1a2636083 Mon Sep 17 00:00:00 2001 From: Martijn Otto Date: Mon, 17 Feb 2014 16:20:09 +0100 Subject: Some code cleanup --- include/class.h | 17 +++--- include/classmodifier.h | 29 ++++++++++ include/const.h | 55 ++++++++++++++++++ include/flag.h | 135 --------------------------------------------- include/function.h | 7 +-- include/member.h | 66 +++++++++++----------- include/membermodifier.h | 49 ++++++++++++++++ include/membervisibility.h | 73 ------------------------ include/private.h | 55 ++++++++++++++++++ include/protected.h | 55 ++++++++++++++++++ include/public.h | 56 +++++++++++++++++++ include/type.h | 4 +- include/zend.h | 84 ---------------------------- 13 files changed, 347 insertions(+), 338 deletions(-) create mode 100644 include/classmodifier.h create mode 100644 include/const.h delete mode 100644 include/flag.h create mode 100644 include/membermodifier.h delete mode 100644 include/membervisibility.h create mode 100644 include/private.h create mode 100644 include/protected.h create mode 100644 include/public.h delete mode 100644 include/zend.h (limited to 'include') diff --git a/include/class.h b/include/class.h index 0f6a48c..b440b02 100644 --- a/include/class.h +++ b/include/class.h @@ -28,7 +28,7 @@ namespace Php { /** * Class definition of the class */ -template +template class Class { public: @@ -94,11 +94,14 @@ public: } /** - * Retrieve the int access types flags for PHP class + * Retrieve the class flags specifying whether the class + * is a regular class, abstract or final + * * @return int flags of access types for classes */ - int getFlags() { - return FlagClass(_flags); + int getFlags() + { + return _flags; } protected: @@ -113,13 +116,13 @@ protected: // C++11 analog of `typedef`. Equivalent to the following pseudocode: typedef ClassFlagged FinalClass; template -using FinalClass = Class; +using FinalClass = Class; template -using AbstractClass = Class; +using AbstractClass = Class; template -using Interface = Class; +using Interface = Class; /** * End of namespace diff --git a/include/classmodifier.h b/include/classmodifier.h new file mode 100644 index 0000000..2cebb65 --- /dev/null +++ b/include/classmodifier.h @@ -0,0 +1,29 @@ +/** + * ClassModifier.h + * + * In this file an enumeration type is defined with + * the possible class modifiers. + * + * @author Martijn Otto + * @copyright 2014 Copernica BV + */ + +/** + * Set up namespace + */ +namespace Php { + +/** + * Supported class modifiers + */ +typedef enum _ClassModifier { + regular = 0x00, + abstract = 0x20, + final = 0x40, + interface = 0x80 +} ClassModifier; + +/** + * End of namespace + */ +} diff --git a/include/const.h b/include/const.h new file mode 100644 index 0000000..4f11278 --- /dev/null +++ b/include/const.h @@ -0,0 +1,55 @@ +/** + * Const.h + * + * Class for adding constant properties to a class + * + * @author Emiel Bruijntjes + * @copyright 2013 Copernica BV + */ + +/** + * Namespace + */ +namespace Php { + +/** + * Class definition + */ +class Const : public Member +{ +public: + /** + * Constructor + * @param name Name of the property + * @param value Default value of the property + */ + Const(const char *name) : Member(name, MemberModifier::constMember) {} + Const(const char *name, std::nullptr_t value) : Member(name, MemberModifier::constMember, value) {} + Const(const char *name, int value) : Member(name, MemberModifier::constMember, value) {} + Const(const char *name, long value) : Member(name, MemberModifier::constMember, value) {} + Const(const char *name, bool value) : Member(name, MemberModifier::constMember, value) {} + Const(const char *name, char value) : Member(name, MemberModifier::constMember, value) {} + Const(const char *name, const std::string &value) : Member(name, MemberModifier::constMember, value) {} + Const(const char *name, const char *value, int size=-1) : Member(name, MemberModifier::constMember, value, size) {} + Const(const char *name, double value) : Member(name, MemberModifier::constMember, value) {} + + /** + * Constructor + * @param name Name of the property + * @param method Method to add + * @param arguments Optional argument information + */ + Const(const char *name, const _Method &method, const std::initializer_list &arguments = {}) : Member(name, MemberModifier::constMember, method, arguments) {} + + /** + * Destructor + */ + virtual ~Const() {} + +}; + +/** + * End of namespace + */ +} + diff --git a/include/flag.h b/include/flag.h deleted file mode 100644 index beb79ba..0000000 --- a/include/flag.h +++ /dev/null @@ -1,135 +0,0 @@ -/** - * flag.h - * - * flag clases for the safe transfer of a Zend flag to a Zend functions - * - * @author Valeriy_Dmitriev - */ - -#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 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 FlagClass; - /** - * class FlagClass - * For the safe transfer of a Zend access types for methods and propertyes - */ - typedef FlagTemplate 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 ea7584f..a722104 100644 --- a/include/function.h +++ b/include/function.h @@ -115,7 +115,7 @@ protected: * @var integer */ int _required; - + /** * Total number of arguments * @var integer @@ -134,14 +134,13 @@ protected: */ HiddenPointer _ptr; -protected: /** * Fill a function entry * @param entry Entry to be filled * @param classname Optional class name * @param pub Is this a public property? */ - void fill(struct _zend_function_entry *entry, const char *classname=NULL, int flags=Flag(Zend::AccMemb::PUBLIC)) const; + void fill(struct _zend_function_entry *entry, const char *classname=NULL, MemberModifier flags = publicMember) const; /** * Fill function info @@ -149,7 +148,7 @@ protected: * @param classname Optional class name */ void fill(struct _zend_internal_function_info *info, const char *classname=NULL) const; - + /** * Extension has access to the private members */ diff --git a/include/member.h b/include/member.h index 347555a..564b1b6 100644 --- a/include/member.h +++ b/include/member.h @@ -31,89 +31,89 @@ public: /** * Constructor * @param name Name of the member - * @param flags Flag access to a class member (bublic, protected etc) + * @param flags Flag access to a class member (public, protected etc) */ - Member(const char *name, const FlagMemb &&flags); + Member(const char *name, MemberModifier flags); /** * Constructor * @param name Name of the member - * @param flags Flag access to a class member (bublic, protected etc) + * @param flags Flag access to a class member (public, protected etc) * @param value The value to add */ - Member(const char *name, const FlagMemb &&flags, std::nullptr_t value); + Member(const char *name, MemberModifier flags, std::nullptr_t value); /** * Constructor * @param name Name of the member - * @param flags Flag access to a class member (bublic, protected etc) + * @param flags Flag access to a class member (public, protected etc) * @param value The value to add */ - Member(const char *name, const FlagMemb &&flags, int value); + Member(const char *name, MemberModifier flags, int value); /** * Constructor * @param name Name of the member - * @param flags Flag access to a class member (bublic, protected etc) + * @param flags Flag access to a class member (public, protected etc) * @param value The value to add */ - Member(const char *name, const FlagMemb &&flags, long value); + Member(const char *name, MemberModifier flags, long value); /** * Constructor * @param name Name of the member - * @param flags Flag access to a class member (bublic, protected etc) + * @param flags Flag access to a class member (public, protected etc) * @param value The value to add */ - Member(const char *name, const FlagMemb &&flags, bool value); + Member(const char *name, MemberModifier flags, bool value); /** * Constructor * @param name Name of the member - * @param flags Flag access to a class member (bublic, protected etc) + * @param flags Flag access to a class member (public, protected etc) * @param value The value to add */ - Member(const char *name, const FlagMemb &&flags, char value); + Member(const char *name, MemberModifier flags, char value); /** * Constructor * @param name Name of the member - * @param flags Flag access to a class member (bublic, protected etc) + * @param flags Flag access to a class member (public, protected etc) * @param value The value to add */ - Member(const char *name, const FlagMemb &&flags, const std::string &value); + Member(const char *name, MemberModifier flags, const std::string &value); /** * Constructor * @param name Name of the member - * @param flags Flag access to a class member (bublic, protected etc) + * @param flags Flag access to a class member (public, protected etc) * @param value The value to add * @param size String length */ - Member(const char *name, const FlagMemb &&flags, const char *value, int size = -1); + Member(const char *name, MemberModifier flags, const char *value, int size = -1); /** * Constructor * @param name Name of the member - * @param flags Flag access to a class member (bublic, protected etc) + * @param flags Flag access to a class member (public, protected etc) * @param value The value to add */ - Member(const char *name, const FlagMemb &&flags, double value); - + Member(const char *name, MemberModifier flags, double value); + /** * Constructor * @param name Name of the method - * @param flags Flag access to a class member (bublic, protected etc) + * @param flags Flag access to a class member (public, protected etc) * @param method The method to add */ - Member(const char *name, const FlagMemb &&flags, const _Method &method, const std::initializer_list &arguments = {}); + Member(const char *name, MemberModifier flags, const _Method &method, const std::initializer_list &arguments = {}); /** * Copy constructor * @param member The member to copy */ Member(const Member &member); - + /** * Move constructor * @param member The member to move @@ -124,14 +124,14 @@ public: * Destructor */ virtual ~Member(); - + /** * Internal method to declare the property * @param zend_class_entry * @internal */ void declare(struct _zend_class_entry *entry); - + /** * Internal method to fill a function entry * @param zend_function_entry @@ -139,19 +139,19 @@ public: * @internal */ void fill(struct _zend_function_entry *entry, const char *classname); - + /** * Is this a property member * @return bool */ bool isProperty(); - + /** * Is this a method member * @return bool */ bool isMethod(); - + private: /** @@ -159,13 +159,13 @@ private: * @var string */ std::string _name; - + /** - * Flag access to a class member (bublic, protected etc) - * @var bool + * Flag access to a class member (public, protected etc) + * @var MemberModifier */ - FlagMemb _accflag; - + MemberModifier _flags; + /** * The implementation for the member * @var MemberInfo @@ -174,7 +174,7 @@ private: }; - + /** * End of namespace */ diff --git a/include/membermodifier.h b/include/membermodifier.h new file mode 100644 index 0000000..9c6cb0d --- /dev/null +++ b/include/membermodifier.h @@ -0,0 +1,49 @@ +/** + * MemberModifier.h + * + * In this file an enumeration type is with the possible + * member modifiers + * + * @author Martijn Otto + * @copyright 2014 Copernica BV + */ + +/** + * Set up namespace + */ +namespace Php { + +/** + * Supported member modifiers + */ +typedef enum _MemberModifier { + /** + * Define whether a member has an implementation + * and whether the implementation can be overwritten + * in an extending class + * + * These properties are only useful for functions + */ + abstractMember = 0x02, + finalMember = 0x04, + + /** + * Define the access level for a member + */ + publicMember = 0x100, + protectedMember = 0x200, + privateMember = 0x400, + + /** + * Define a member that cannot be overwritten. + * Constant members are always public. + * + * This property is only useful for properties + */ + constMember = 0 +} MemberModifier; + +/** + * End namespace + */ +} diff --git a/include/membervisibility.h b/include/membervisibility.h deleted file mode 100644 index a0a11ea..0000000 --- a/include/membervisibility.h +++ /dev/null @@ -1,73 +0,0 @@ -/** - * 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 - * changed by Valeriy Dmitriev - * @copyright 2013 Copernica BV - */ - -/** - * Namespace - */ -namespace Php { - -/** - * Class definition - */ -template -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 &arguments = {}) : Member(name, FlagMemb(AccFlag), method, arguments) {} - - /** - * Destructor - */ - virtual ~MemberVisibility() {} - -}; - -typedef MemberVisibility Public; -typedef MemberVisibility Protected; -typedef MemberVisibility Private; -typedef MemberVisibility 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 Static; - - -/** - * End of namespace - */ -} - diff --git a/include/private.h b/include/private.h new file mode 100644 index 0000000..eddac69 --- /dev/null +++ b/include/private.h @@ -0,0 +1,55 @@ +/** + * Private.h + * + * Class for adding private properties to a class + * + * @author Emiel Bruijntjes + * @copyright 2013 Copernica BV + */ + +/** + * Namespace + */ +namespace Php { + +/** + * Class definition + */ +class Private : public Member +{ +public: + /** + * Constructor + * @param name Name of the property + * @param value Default value of the property + */ + Private(const char *name) : Member(name, MemberModifier::privateMember) {} + Private(const char *name, std::nullptr_t value) : Member(name, MemberModifier::privateMember, value) {} + Private(const char *name, int value) : Member(name, MemberModifier::privateMember, value) {} + Private(const char *name, long value) : Member(name, MemberModifier::privateMember, value) {} + Private(const char *name, bool value) : Member(name, MemberModifier::privateMember, value) {} + Private(const char *name, char value) : Member(name, MemberModifier::privateMember, value) {} + Private(const char *name, const std::string &value) : Member(name, MemberModifier::privateMember, value) {} + Private(const char *name, const char *value, int size=-1) : Member(name, MemberModifier::privateMember, value, size) {} + Private(const char *name, double value) : Member(name, MemberModifier::privateMember, value) {} + + /** + * Constructor + * @param name Name of the property + * @param method Method to add + * @param arguments Optional argument information + */ + Private(const char *name, const _Method &method, const std::initializer_list &arguments = {}) : Member(name, MemberModifier::privateMember, method, arguments) {} + + /** + * Destructor + */ + virtual ~Private() {} + +}; + +/** + * End of namespace + */ +} + diff --git a/include/protected.h b/include/protected.h new file mode 100644 index 0000000..977b4c4 --- /dev/null +++ b/include/protected.h @@ -0,0 +1,55 @@ +/** + * Protected.h + * + * Class for adding protected properties to a class + * + * @author Emiel Bruijntjes + * @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, MemberModifier::protectedMember) {} + Protected(const char *name, std::nullptr_t value) : Member(name, MemberModifier::protectedMember, value) {} + Protected(const char *name, int value) : Member(name, MemberModifier::protectedMember, value) {} + Protected(const char *name, long value) : Member(name, MemberModifier::protectedMember, value) {} + Protected(const char *name, bool value) : Member(name, MemberModifier::protectedMember, value) {} + Protected(const char *name, char value) : Member(name, MemberModifier::protectedMember, value) {} + Protected(const char *name, const std::string &value) : Member(name, MemberModifier::protectedMember, value) {} + Protected(const char *name, const char *value, int size=-1) : Member(name, MemberModifier::protectedMember, value, size) {} + Protected(const char *name, double value) : Member(name, MemberModifier::protectedMember, 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 &arguments = {}) : Member(name, MemberModifier::protectedMember, method, arguments) {} + + /** + * Destructor + */ + virtual ~Protected() {} + +}; + +/** + * End of namespace + */ +} + diff --git a/include/public.h b/include/public.h new file mode 100644 index 0000000..17a2468 --- /dev/null +++ b/include/public.h @@ -0,0 +1,56 @@ +/** + * Public.h + * + * Class for adding public properties to a class + * + * @author Emiel Bruijntjes + * @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, MemberModifier::publicMember) {} + Public(const char *name, std::nullptr_t value) : Member(name, MemberModifier::publicMember, value) {} + Public(const char *name, int value) : Member(name, MemberModifier::publicMember, value) {} + Public(const char *name, long value) : Member(name, MemberModifier::publicMember, value) {} + Public(const char *name, bool value) : Member(name, MemberModifier::publicMember, value) {} + Public(const char *name, char value) : Member(name, MemberModifier::publicMember, value) {} + Public(const char *name, const std::string &value) : Member(name, MemberModifier::publicMember, value) {} + Public(const char *name, const char *value, int size=-1) : Member(name, MemberModifier::publicMember, value, size) {} + Public(const char *name, double value) : Member(name, MemberModifier::publicMember, 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 &arguments = {}) : Member(name, MemberModifier::publicMember, method, arguments) {} + + /** + * Destructor + */ + virtual ~Public() {} + + +}; + +/** + * End of namespace + */ +} + diff --git a/include/type.h b/include/type.h index 25b26da..717ae90 100644 --- a/include/type.h +++ b/include/type.h @@ -1,9 +1,9 @@ /** * Type.h * - * In this file an enumeration type is defined with all supporteded variable + * In this file an enumeration type is defined with all supported variable * types. - * + * * @author Emiel Bruijntjes * @copyright 2013 Copernica BV */ diff --git a/include/zend.h b/include/zend.h deleted file mode 100644 index 9804606..0000000 --- a/include/zend.h +++ /dev/null @@ -1,84 +0,0 @@ -/** - * zend.h - * - * zend namespace - * - * @author Valeriy_Dmitriev - */ - -#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 - - //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_ */ -- cgit v1.2.3