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/mapval.cc
2019-03-25 15:14:53 +08:00

78 lines
2.3 KiB
C++

//
// php-armadillo/mapval.cc
//
// @Author CismonX
//
#include "mapval.hh"
#include "interfaces.hh"
#include "complex.hh"
#include <armadillo>
namespace php_arma
{
template <typename T, bool IsSparse, bool B>
zend_always_inline
T mapval<T, IsSparse, B>::get_val(zend_object *zobj)
{
if constexpr (IsSparse) {
return *to_native_object<native_t>(zobj);
} else {
return **to_native_object<native_t>(zobj);
}
}
template <typename T, bool B1, bool B2>
PHP_ARMA_FUNCTION(mapval, val, T, B1, B2)
{
zend_object *current = Z_OBJ_P(getThis());
zval_set_scalar(return_value, get_val(current));
}
template <typename T, bool B1, bool B2>
PHP_ARMA_FUNCTION(mapval, setTo, T, B1, B2)
{
zval *val;
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_ZVAL(val)
ZEND_PARSE_PARAMETERS_END();
if (!zval_check_scalar<T>(val)) {
return;
}
zend_object *current = Z_OBJ_P(getThis());
set_val(current, zval_get_scalar<T>(val));
}
template <typename T, bool B1, bool B2>
zend_always_inline
void mapval<T, B1, B2>::ce_init(const char *name, zend_class_entry *parent_ce)
{
ce = class_register(name, parent_ce, me);
ce->create_object = object_non_constructible;
object_handlers_init(&handlers);
handlers.offset = sizeof(native_t);
handlers.clone_obj = nullptr;
}
void mapval_init()
{
mapval_ce = abstract_class_register("MapVal", scalar_ce);
mapval_dense<double >::ce_init("DMapVal", mapval_ce);
mapval_dense<zend_long>::ce_init("IMapVal", mapval_ce);
mapval_dense<cx_double>::ce_init("CxDMapVal", mapval_ce);
sp_mapval_ce = abstract_class_register("SpMapVal", scalar_ce);
mapval_spmat<double >::ce_init("SpDMapVal", sp_mapval_ce);
mapval_spmat<zend_long>::ce_init("SpIMapVal", sp_mapval_ce);
mapval_spmat<cx_double>::ce_init("SpCxDMapVal", sp_mapval_ce);
spsv_mapval_ce = abstract_class_register("SpSvMapVal", scalar_ce);
mapval_sp_subview<double >::ce_init("SpSvDMapVal", spsv_mapval_ce);
mapval_sp_subview<zend_long>::ce_init("SpSvIMapVal", spsv_mapval_ce);
mapval_sp_subview<cx_double>::ce_init("SpSvCxDMapVal", spsv_mapval_ce);
}
}