Implement `print()` `rawPrint()` and test cases.
This commit is contained in:
parent
dcae143cc2
commit
87187d4fdd
39
src/base.cc
39
src/base.cc
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "base.hh"
|
||||
#include "mat.hh"
|
||||
#include "stream_utils.hh"
|
||||
|
||||
#include <armadillo>
|
||||
#include <zend_interfaces.h>
|
||||
|
@ -133,13 +134,47 @@ namespace php_arma
|
|||
template <typename T, typename T1>
|
||||
PHP_ARMA_METHOD(base, print, T, T1)
|
||||
{
|
||||
|
||||
zval *stream = nullptr;
|
||||
ZEND_PARSE_PARAMETERS_START(0, 1)
|
||||
Z_PARAM_OPTIONAL
|
||||
Z_PARAM_ZVAL_DEREF(stream)
|
||||
ZEND_PARSE_PARAMETERS_END();
|
||||
|
||||
auto native = THIS_NATIVE;
|
||||
if (stream == nullptr) {
|
||||
native->print();
|
||||
} else {
|
||||
#ifdef __GNUC__
|
||||
__gnu_cxx::stdio_filebuf<char> filebuf(zval_to_fd(stream), std::ios::out);
|
||||
std::ostream os(&filebuf);
|
||||
native->print(os);
|
||||
#else
|
||||
filebuf_unsupported();
|
||||
#endif // __GNUC__
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename T1>
|
||||
PHP_ARMA_METHOD(base, rawPrint, T, T1)
|
||||
{
|
||||
|
||||
zval *stream = nullptr;
|
||||
ZEND_PARSE_PARAMETERS_START(0, 1)
|
||||
Z_PARAM_OPTIONAL
|
||||
Z_PARAM_ZVAL_DEREF(stream)
|
||||
ZEND_PARSE_PARAMETERS_END();
|
||||
|
||||
auto native = THIS_NATIVE;
|
||||
if (stream == nullptr) {
|
||||
native->raw_print();
|
||||
} else {
|
||||
#ifdef __GNUC__
|
||||
__gnu_cxx::stdio_filebuf<char> filebuf(zval_to_fd(stream), std::ios::out);
|
||||
std::ostream os(&filebuf);
|
||||
native->raw_print(os);
|
||||
#else
|
||||
filebuf_unsupported();
|
||||
#endif // __GNUC__
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename T1>
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
--TEST--
|
||||
Test for `print()` and `rawPrint()`.
|
||||
--SKIPIF--
|
||||
<?php
|
||||
require_once 'includes/loaded.php';
|
||||
is_php_arma_loaded();
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require_once 'includes/assert.php';
|
||||
|
||||
$mat = Arma\CxDMat::fromString('(1,2) (3,4); (5,6) (7,8)');
|
||||
$mat->print();
|
||||
$mat->rawPrint();
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
(+1.000e+00,+2.000e+00) (+3.000e+00,+4.000e+00)
|
||||
(+5.000e+00,+6.000e+00) (+7.000e+00,+8.000e+00)
|
||||
(1,2) (3,4)
|
||||
(5,6) (7,8)
|
Reference in New Issue