This repository has been archived on 2020-06-07. You can view files and clone it, but cannot push or open issues or pull requests.
php-armadillo/src/complex.cc

62 lines
1.7 KiB
C++
Raw Normal View History

//
// php-armadillo/complex.cc
//
// @Author CismonX
//
2019-03-14 15:23:21 +00:00
#include "php_arma.hh"
#include "complex.hh"
namespace php_arma
{
PHP_ARMA_START_METHOD_ENTRY_1(complex, T)
PHP_ARMA_ME_1(Complex, T, __construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
PHP_ARMA_END_METHOD_ENTRY_1(complex, T)
template <typename T>
PHP_METHOD(Complex, __construct)
{
zval *real, *imag;
ZEND_PARSE_PARAMETERS_START(0, 2)
Z_PARAM_OPTIONAL
Z_PARAM_ZVAL(real)
Z_PARAM_ZVAL(imag)
ZEND_PARSE_PARAMETERS_END();
auto num_args = EX_NUM_ARGS();
auto has_imag = num_args > 1;
auto has_real = num_args > 0;
zval zero_val;
zval_set_scalar(&zero_val, static_cast<T>(0));
zval *current = getThis();
if (EXPECTED(has_real)) {
zval_check_scalar<T>(real);
object_set_property(Z_OBJ_P(current), 0, real);
if (EXPECTED(has_imag)) {
zval_check_scalar<T>(imag);
object_set_property(Z_OBJ_P(current), 1, imag);
} else {
object_set_property(Z_OBJ_P(current), 1, &zero_val);
}
} else {
object_set_property(Z_OBJ_P(current), 0, &zero_val);
object_set_property(Z_OBJ_P(current), 1, &zero_val);
}
}
void complex_init()
{
complex_ce = interface_register("Complex");
cx_double_ce = class_register("CxDouble", PHP_ARMA_METHOD_1(complex, double), complex_ce);
property_declare(cx_double_ce, "real");
property_declare(cx_double_ce, "imag");
}
zend_class_entry *complex_ce;
zend_class_entry *cx_double_ce;
}