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

78 lines
2.3 KiB
C++
Raw Normal View History

2019-03-24 08:59:29 +00:00
//
// 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)
{
2019-03-25 07:14:53 +00:00
if constexpr (IsSparse) {
2019-03-24 08:59:29 +00:00
return *to_native_object<native_t>(zobj);
} else {
return **to_native_object<native_t>(zobj);
}
}
template <typename T, bool B1, bool B2>
2019-03-31 03:19:04 +00:00
PHP_ARMA_METHOD(mapval, val, T, B1, B2)
2019-03-24 08:59:29 +00:00
{
2019-03-28 04:27:29 +00:00
auto current = Z_OBJ_P(getThis());
2019-03-24 08:59:29 +00:00
zval_set_scalar(return_value, get_val(current));
}
template <typename T, bool B1, bool B2>
2019-03-31 03:19:04 +00:00
PHP_ARMA_METHOD(mapval, setTo, T, B1, B2)
2019-03-24 08:59:29 +00:00
{
zval *val;
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_ZVAL(val)
ZEND_PARSE_PARAMETERS_END();
if (!zval_check_scalar<T>(val)) {
return;
}
2019-03-28 04:27:29 +00:00
auto current = Z_OBJ_P(getThis());
2019-03-24 08:59:29 +00:00
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);
}
}