This commit is contained in:
CismonX 2019-03-19 13:28:45 +08:00
parent 2febfad337
commit f50d5f1b6d
4 changed files with 22 additions and 14 deletions

View File

@ -47,7 +47,7 @@ namespace php_arma
object_set_property(Z_OBJ_P(current), 1, &zero_val);
}
Z_OBJ_P(current)->handlers = PHP_ARMA_HANDLERS(complex, T);
Z_OBJ_HT_P(current) = PHP_ARMA_HANDLERS(complex, T);
}
PHP_ARMA_START_ME_1(complex, T)
@ -82,8 +82,7 @@ namespace php_arma
template <typename T>
void complex_ce_init(zend_class_entry *parent_ce)
{
PHP_ARMA_CE(complex, T) = class_register("CxDouble", PHP_ARMA_METHODS(complex, T));
zend_do_inheritance(PHP_ARMA_CE(complex, T), parent_ce);
PHP_ARMA_CE(complex, T) = class_register("CxDouble", parent_ce, PHP_ARMA_METHODS(complex, T));
property_declare(PHP_ARMA_CE(complex, T), "real");
property_declare(PHP_ARMA_CE(complex, T), "imag");
object_handlers_init(PHP_ARMA_HANDLERS(complex, T));
@ -92,7 +91,7 @@ namespace php_arma
void complex_init()
{
complex_ce = class_register("Complex", nullptr);
complex_ce = abstract_class_register("Complex");
complex_ce_init<double>(complex_ce);
}

View File

@ -11,8 +11,7 @@ namespace php_arma
{
void fill_init()
{
fill_ce = class_register("Fill", nullptr);
fill_ce->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;
fill_ce = abstract_class_register("Fill");
const_declare(fill_ce, "NONE", fill_none);
const_declare(fill_ce, "ZEROS", fill_zeros);
const_declare(fill_ce, "ONES", fill_ones);

View File

@ -4,7 +4,6 @@
// @Author CismonX
//
#include "php_arma.hh"
#include "interfaces.hh"
#define N_INT "Internal\\"

View File

@ -14,7 +14,7 @@
#include <php.h>
#include <zend_exceptions.h>
#include <type_traits>
#include <functional>
#define PHP_ARMA_VERSION "0.0.1"
@ -93,23 +93,34 @@ namespace php_arma
}
template <typename F, typename... Ts>
zend_class_entry *ce_init(const char *name, const zend_function_entry *methods, F init_func, Ts... parents)
zend_class_entry *ce_init(const char *name, const zend_function_entry *methods, F init_func, Ts... interfaces)
{
auto ce = ce_init(name, methods, init_func);
zend_class_implements(ce, sizeof...(Ts), parents...);
zend_class_implements(ce, sizeof...(Ts), interfaces...);
return ce;
}
zend_always_inline
zend_class_entry *class_register(const char *name, const zend_function_entry *methods)
zend_class_entry *class_register(const char *name, zend_class_entry *parent, const zend_function_entry *methods)
{
return ce_init(name, methods, zend_register_internal_class);
using std::placeholders::_1;
return ce_init(name, methods, std::bind(zend_register_internal_class_ex, _1, parent));
}
zend_always_inline
zend_class_entry *abstract_class_register(const char *name)
{
auto ce = ce_init(name, nullptr, zend_register_internal_class);
ce->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;
return ce;
}
template <typename... Ts>
zend_class_entry *class_register(const char *name, const zend_function_entry *methods, Ts... interfaces)
zend_class_entry *abstract_class_register(const char *name, Ts... interfaces)
{
return ce_init(name, methods, zend_register_internal_class, interfaces...);
auto ce = ce_init(name, nullptr, zend_register_internal_class, interfaces...);
ce->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;
return ce;
}
zend_always_inline