Simple and Light Interfaces for C and C++ users

SLLIB – Script-Like C-language library
User’s Reference Guide Advanced Edition
Version 1.1.0 English

CREDITSSOFTWARE DEVELOPMENT:

Chisato Yamauchi
QUALITY ASSURANCE:SEC Co.,LTD.
MANUAL DOCUMENT:

Chisato Yamauchi, Sachimi Fujishima AND SEC Co.,LTD.
MANUAL TRANSLATION:Space Engineering Development Co.,LTD. AND Sakura Academia Corporation
SPECIAL THANKS:

Daisuke Ishihara, Hajime Baba, Iku Shinohara, Keiichi Matsuzaki,
Sergio Pascual AND YukioYamamoto

Web page: http://www.ir.isas.jaxa.jp/~cyamauch/sli/

2

SLLIB User’s Reference Guide Advanced Edition

Contents
1 TARRAY Template Class
1.1 How to Create an Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2 List of Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.3 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.3.1 [] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.3.2 = . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.3.3 += . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.3.4 += . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.4 The member functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.4.1 length() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.4.2 at(), at cs() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.4.3 copy() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.4.4 swap() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.4.5 init() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.4.6 assign() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.4.7 put() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.4.8 append() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.4.9 insert() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.4.10 replace() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.4.11 erase() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.4.12 clean() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.4.13 resize() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.4.14 resizeby() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.4.15 crop() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

5
5
5
7
7
7
8
8
9
9
9
10
10
11
11
12
13
13
14
15
15
16
16
17

2 ASARRAY Template Class
2.1 How to Create an Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2 List of Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.3 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.3.1 [] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.3.2 = . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4 Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4.1 length() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4.2 at(), atf() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4.3 at cs(), atf cs() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4.4 index(), indexf(), vindexf() . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4.5 key() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4.6 keys() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4.7 values() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4.8 swap() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4.9 init() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4.10 assign() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4.11 assign keys() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4.12 split keys() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4.13 append() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4.14 insert() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4.15 erase() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4.16 clean() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

18
18
18
20
20
20
21
21
21
22
23
24
24
25
25
25
26
26
27
28
29
29
30

Ver. 1.1.0

3

2.4.17 rename a key() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

30

3 CTINDEX Class
3.1 How to Create an Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.2 List of Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.3 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.3.1 = . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.4 Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.4.1 init() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.4.2 append() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.4.3 update() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.4.4 erase() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.4.5 index() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

32
32
32
34
34
34
35
35
36
37
38

4 MDARRAY Class
4.1 How to Create an Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.2 Mathematic Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.3 List of Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4.1 = . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4.2 = . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4.3 += . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4.4 += . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4.5 -= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4.6 -= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4.7 *= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4.8 *= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4.9 /= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4.10 /= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4.11 + . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4.12 + . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4.13 - . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4.14 - . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4.15 * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4.16 * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4.17 / . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4.18 / . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4.19 == . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4.20 != . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5 Member Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.1 size type() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.2 bytes() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.3 dim length() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.4 length() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.5 byte length() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.6 col length() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.7 row length() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.8 layer length() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.9 f(), d(), ld(), c(), s(), i(), l(), ll(), i16(), i32(), i64(), z(), sz(), b(), p() . . . .

40
40
42
42
47
47
47
48
49
50
51
51
52
52
53
54
54
55
55
56
57
57
58
58
59
60
60
60
61
61
62
63
63
64
64

4

SLLIB User’s Reference Guide Advanced Edition
4.5.10 f cs(), d cs(), ld cs(), c cs(), s cs(), i cs(), l cs(), ll cs(), i16 cs(), i32 cs(),
i64 cs(), z cs(), sz cs(), b cs(), p cs() . . . . . . . . . . . . . . . . . . . . . .
4.5.11 dvalue() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.12 lvalue(), llvalue() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.13 default value ptr(), assign default() . . . . . . . . . . . . . . . . . . . . . . .
4.5.14 auto resize(), set auto resize() . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.15 rounding(), set rounding() . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.16 dprint() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.17 data ptr() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.18 register extptr() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.19 get elements() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.20 put elements() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.21 getdata() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.22 putdata() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.23 reverse endian() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.24 init() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.25 assign() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.26 put() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.27 swap() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.28 move() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.29 cpy() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.30 insert() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.31 crop() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.32 erase() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.33 resize() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.34 resizeby() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.35 increase dim() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.36 decrease dim() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.37 swap() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.38 convert() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.39 ceil() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.40 floor() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.41 round() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.42 trunc() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.43 abs() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.44 compare() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.45 copy() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.46 copy() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.47 cut() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.48 cut() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.49 clean() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.50 fill() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.51 add() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.52 multiply() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.53 paste() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.54 add() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.55 subtract() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.56 multiply() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5.57 divide() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

66
68
68
69
70
71
72
72
73
74
76
77
78
79
80
82
83
84
85
86
87
88
89
90
91
92
93
93
94
95
96
96
97
98
98
99
100
102
103
104
105
107
108
109
111
112
113
114

SLLIB Reference: sli::tarray Template (Supporting the Array of Arbitrary Data Types or Classes)5

1

TARRAY Template Class

The tarray template class can handle arrays of arbitrary data types or classes.
Its function is almost the same as that of tarray tstring in the Basic Edition, except that thisclass does not include member functions specializing in string. Therefore, the EXAMPLE section
is omitted in this chapter. As for EXAMPLE, see the references of each member function of
tarray tstring in the Basic Edition.
To use the tarray template class, write the following code followed by the user code.
¨¥#include <sli/tarray.h>§¦

Additionally, write “using namespace sli;” in the code if the namespace declaration is required.

1.1

How to Create an Object

To create an object of the tarray template class, no arguments are required. Create it normally as
shown below:¨¥#include <sli/tarray.h>using namespace sli;
int main(){tarray<tarray_tstring> my_2d_array;§¦

In this example, the array of tarray tstring in the Basic Edition is created. This make it easy tohandle a two dimensional array of string as shown below.
¨
§

1.2

¥

my_2d_array[0][0] = "SLLIB";

List of Member Functions

The member functions are listed in Table 1.

¦

6SLLIB Reference: sli::tarray Template (Supporting the Arrays of Arbitrary Data Types or Classes)§1.3.1§1.3.2§1.3.3§1.3.4§1.4.1§1.4.2§1.4.3§1.4.4§1.4.5§1.4.6§1.4.7§1.4.8§1.4.9
§1.4.10§1.4.11§1.4.12§1.4.13§1.4.14§1.4.15

Function Name
[]
=
+=
+=
length()at(), at_cs()
copy()
swap()
init()
assign()put()
append()insert()replace()erase()
clean()
resize()resizeby()crop()

Description
A reference to the specified element
Substitute an array for the same type and class
Append an array
Append an element
Length of the array (the number of elements)
A reference to the specified element
Copy (a part of) the array itself to another one
Replace the array itself with that of the external object
Initialize the object completely
Initialize and substitute the object
Put a value to an arbitrary element’s point
Append an element
Insert an element
Replace an element
Erase an element
Padding of the existing values in an array by arbitrary ones
Change the length of the array
Change the length of the array relatively
Extract an array

Table 1: List of Member Functions Available in tarray Template Class.

SLLIB Reference: sli::tarray Template (Supporting the Array of Arbitrary Data Types or Classes)7

1.3
1.3.1

Operators[]

NAME[] — A reference to the specified element
SYNOPSIS
type &operator[]( size_t index ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
const type &operator[]( size_t index ) const; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
DESCRIPTIONThis operator returns a reference to an array element specified by the index. The member
functions in the type class can be called by specifying them after this operator and the “.”operator.
The member function 1 is available for read/write and corresponds to at(). The member
function 2 is available for read only and corresponds to at_cs().
When the specified index exceeds the length of the array, the member function 1 extends
the array size automatically and the member function 2 throws an exception. The initial
element index of the array is 0.
Whether the member function 1 or 2 is used depend on whether the object has the “const ”
attribute. The member function 1 is used for the object without the “const ” attribute, andthe function 2 is used with the attribute automatically.
For more information about at(), at_cs(), see §1.4.2.
PARAMETER[I] index

Array subscript that starts from 0

RETURN VALUE
A reference to the element specified by the index in the array
EXCEPTION- The member function 1 throws an exception when it fails to allocate a local buffer.
- The function 2 throws an exception when the argument index is greater than or equal to
the number of elements in this array.
1.3.2

=

NAME
= — Substitute an array for the same type and classSYNOPSIS
tarray &operator=(const tarray &obj);
DESCRIPTIONThis operator substitutes the array with the same data type or class as that of the object
itself specified by the right side of the operator (argument) into the object itself.
PARAMETER[I] obj An object containing an array of elements of the same type as those on the left
side
RETURN VALUE
A reference to itself

8SLLIB Reference: sli::tarray Template (Supporting the Arrays of Arbitrary Data Types or Classes)
EXCEPTION
The function throws an exception when it fails to allocate a local buffer, or it detects memory
corruption.

1.3.3

+=

NAME
+= — Append an array
SYNOPSIS
tarray &operator+=(const tarray &obj);
DESCRIPTIONThis operator appends the array specified by the right side of the operator (argument) tothe object itself.
PARAMETER[I] obj An object containing an array of elements of the same type as those on the left
side
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer, or it detects memory
corruption.

1.3.4

+=

NAME
+= — Append an element
SYNOPSIS
tarray &operator+=(const type &one);
DESCRIPTIONThis operator appends one element specified by the right side of the operator (argument) tothe object itself.
PARAMETER[I] one An element to be appended to this array
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer.

SLLIB Reference: sli::tarray Template (Supporting the Array of Arbitrary Data Types or Classes)9

1.4
1.4.1

The member functions
length()NAME
length() — Length of the array (the number of elements)
SYNOPSIS
size_t length() const;
DESCRIPTION
length() returns length the (number of elements) of an array.
RETURN VALUE
Length of an array
1.4.2

at(), at cs()NAMEat(), at cs() — A reference to the specified element
SYNOPSIS
type &at( size_t index ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
const type &at( size_t index ); const . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
const type &at_cs( size_t index ) const; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
DESCRIPTION
at() and at cs() return a reference to the element of an array specified by index. The
member functions in the type class can be used by placing the “.” operator immediately
after these member functions.
The member function 1 can be used for both read/write. while the member functions 2 and3 are used for read only.
As for the at() member function, whether the member function 1 or 2 is used depends onwhether the object has the const attribute. Without the const, the member function 1 isselected. With the const attribute, the member function 2 is selected automatically.
If a value equal to or greater than the length of the array is given to index for the member
function 1, a new element of array is created. No exception is thrown except when it fails toallocate a buffer.
If a value equal to or greater than the length of the array is given to index for the member
function 2 or 3, an exception is thrown.
PARAMETER[I] index Subscript specifying an array element([I] : input, [O] : output)
RETURN VALUE
A reference to the value or the object corresponding to the specified element’s index
EXCEPTION- The member function 1 throws an exception when it fails to allocate a local buffer. - The
member functions 2 and 3 throw an exception when the argument index is greater than orequal to the number of elements in this array.

10SLLIB Reference: sli::tarray Template (Supporting the Arrays of Arbitrary Data Types or Classes)
1.4.3

copy()NAME
copy() — Copy (a part of) the array itself to another one
SYNOPSIS
ssize_t copy( tarray *dest ) const; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ssize_t copy( size_t index, tarray *dest ) const; . . . . . . . . . . . . . . . . . . . . . . . . . . .
ssize_t copy( size_t index, size_t n, tarray *dest ) const; . . . . . . . . . . . . . . .
ssize_t copy( tarray &dest ) const; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ssize_t copy( size_t index, tarray &dest ) const; . . . . . . . . . . . . . . . . . . . . . . . . . . .
ssize_t copy( size_t index, size_t n, tarray &dest ) const; . . . . . . . . . . . . . . .

1
2
3
4
5
6

DESCRIPTION
copy() copies all or a part of its own array to the object specified by dest. The return value
is the number of elements written to dest.
The argument dest is available in the forms of a pointer variable for member function 1-3
and a reference for member functions 4-6. These behave exactly the same. A user’s policy
should specify which one is to be used.
The member functions 1 and 4 copy all elements in an array to dest.
The member functions 2, 3, 5 and 6 copy elements starting from the index of the element inan array, which is index. The index at the beginning of the array is 0. As for the member
functions 3 and 6, the number of elements to be copied, n, can be specified.
If the value ofindex + n exceeds the number of elements in the source array, the elements from index tothe last are copied. If the value of index exceeds the number of elements in the source array,the content of dest is deleted and they return -1.
PARAMETER[O] dest

A pointer to an instance of the class “tarray” to which a subarray of thisobject should be written[I]
index Subscript specifying the first element of the subarray[I]n
Number of elements in the subarray([I] : input, [O] : output)

RETURN VALUE
Non-negative value
Negative value (error)::

Number of elements copied
If a value equal to or greater than length of the array is specified
to index

EXCEPTION
The function throws an exception when it fails to allocate a local buffer.
1.4.4

swap()NAME
swap() — Replace the array itself with that of the external object
SYNOPSIS
tarray &swap( tarray &sobj );DESCRIPTION
swap() swaps the content of the caller with that of the object sobj.

SLLIB Reference: sli::tarray Template (Supporting the Array of Arbitrary Data Types or Classes)11
PARAMETER[I/O] sobj

An instance of the class “tarray” whose contents should be swapped withthose in this object([I] : input, [O] : output)

RETURN VALUE
A reference to itself
1.4.5

init()

NAME
init() — Initialize the object completely
SYNOPSIS
tarray &init(); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
tarray &init(const tarray &obj); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
DESCRIPTION
init() initializes the caller’s array.
The member function 1 initializes an object completely, and a memory area allocated to anarray buffer is released completely.
The member function 2 initializes with the content of the specified object obj (copies thewhole content of obj to the caller object).
PARAMETER[I] obj An instance of the class “tarray” whose contents should be copied to this object
as its initial value([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXCEPTION
Both functions throw an exception when they fail to allocate a local buffer. In addition, themember function 2 also throws an exception when it detects memory corruption.

1.4.6

assign()NAME
assign() — Initialize and substitute the object
SYNOPSIS
tarray &assign( const type &one, size_t n ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
tarray &assign( const tarray &src, size_t idx2 = 0 ); . . . . . . . . . . . . . . . . . . . . . . . 2
tarray &assign( const tarray &src, size_t idx2, size_t n2 ); . . . . . . . . . . . . . . 3
DESCRIPTION
The member function 1 initializes the caller’s array with n number of elements that have avalue specified by one.
The member functions 2 and 3 assign n2 number of elements starting from the element’s
index idx2 in the array src to the caller’s array.

12SLLIB Reference: sli::tarray Template (Supporting the Arrays of Arbitrary Data Types or Classes)
PARAMETER[I] one
A reference to a scalar with which this array is filled[I] n
Number of entries to which the scalar one is written[I] src
A reference to the object that contains an input array[I] idx2 Array subscript specifying the first element to be extracted from the input arraysrc[I] n2
Number of elements to be extracted from the input array src([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer.
1.4.7

put()

NAME
put() — Put a value to an arbitrary element’s pointSYNOPSIS
tarray &put( size_t index, const type &one, size_t n ); . . . . . . . . . . . . . . . . . . . . 1
tarray &put( size_t index, const tarray &src, size_t idx2 = 0 ); . . . . . . . . . 2
tarray &put( size_t index, const tarray &src, size_t idx2, size_t n2 ); . 3
DESCRIPTION
The member function 1 overwrites the caller’s array with n number of elements that have avalue specified by one starting from the position of the element’s index index.
The member functions 2 and 3 overwrite the caller’s array with n2 number of elements
starting from the element’s index idx2 in the array src starting from the position of theelement’s index index.
The element’s index at the beginning of the array is zero.
Arbitrary values can be given to index. If the specified argument exceeds the numberof elements in an array, the size of the array is extended automatically. When the array is
empty, for example, the results of my arr.put(0,value,6) and my arr.put(2,value,4) are
the same. When the array has four elements, my arr.put(2,value,4) makes the number of
elements in the array six. The elements after the element’s index 2 are the ones specified byvalue.
PARAMETER[I] index

Subscript specifying the first element of a subarray of this object to which thegiven data should be written[I] one
A reference to a scalar to be written to the subarray[I] nNumber of entries to which the scalar one is written[I] src
A reference to an object that contains an input array[I] idx2
Array subscript specifying the first element to be extracted from the input
array src
[I] n2
Number of elements to be extracted from the input array src([I] : input, [O] : output)

RETURN VALUE
A reference to itself

SLLIB Reference: sli::tarray Template (Supporting the Array of Arbitrary Data Types or Classes)13
EXCEPTION
The function throws an exception when it fails to allocate a local buffer.
1.4.8

append()NAME
append() — Append an element
SYNOPSIS
tarray &append( const type &one, size_t n ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
tarray &append( const tarray &src, size_t idx2 = 0 ); . . . . . . . . . . . . . . . . . . . . . . . 2
tarray &append( const tarray &src, size_t idx2, size_t n2 ); . . . . . . . . . . . . . . 3
DESCRIPTION
The member function 1 appends n number of elements that have a value specified by one tothe end of the caller’s array.
The member functions 2 and 3 append n2 number of elements starting from the element’s
index idx2 in the array src to the end of the caller’s array.
The element’s index at the beginning of the array is zero.
PARAMETER[I] one
A reference to a scalar to be written to an additional subarray of this object[I] n
Number of entries to which the scalar one is written[I] src
A reference to an object containing an input array[I] idx2 Array subscript specifying the first element to be extracted from the input arraysrc[I] n2
Number of elements to be extracted from the input array src([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer.
1.4.9

insert()NAME
insert() — Insert an element
SYNOPSIS
tarray &insert( size_t index, const type &one, size_t n ); . . . . . . . . . . . . . . . . . 1
tarray &insert( size_t index,
const tarray &src, size_t idx2 = 0 ); . . . . . . . . . . . . . . . . . . . . . . . 2
tarray &insert( size_t index,
const tarray &src, size_t idx2, size_t n2 ); . . . . . . . . . . . . . . 3
DESCRIPTION
The member function 1 inserts n number of elements that have a value specified by one tothe position of the element’s index index in the caller’s array.
The member functions 2 and 3 insert n2 number of elements starting from the element’s
index idx2 in the array src to the position of the element’s index index in the caller’s array.

14SLLIB Reference: sli::tarray Template (Supporting the Arrays of Arbitrary Data Types or Classes)
The element’s index at the beginning of the array is zero.
If a value equal to or greater than the length of the array is given to index, it is assumed
that the length of the array is given to index.
PARAMETER[I] index

Array subscript specifying an element before which a new additional arrayshould be inserted[I] one
A reference to a scalar to be written to the additional subarray of this object[I] n
Number of new entries to which the scalar one is written[I] src
A reference to an object containing an input array[I] idx2
Array subscript specifying the first element to be extracted from the input
array src
[I] n2
Number of elements to be extracted from the input array src([I] : input, [O] : output)

RETURN VALUE
A reference to itself

1.4.10replace()

NAME
replace() — Replace an element
SYNOPSIS
tarray &replace( size_t idx1, size_t n1,
const type &one, size_t n ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
tarray &replace( size_t idx1, size_t n1,
const tarray &src, size_t idx2 = 0 ); . . . . . . . . . . . . . . . . . . . . . 2
tarray &replace( size_t idx1, size_t n1,
const tarray &src, size_t idx2, size_t n2 ); . . . . . . . . . . . . . 3
DESCRIPTION
The member function 1 replaces n1 number of elements starting from the element’s index
idx1 in the caller’s array with n number of elements that have a value specified by one.
The member function 2 replaces n1 number of elements starting from the element’s index
idx1 in the caller’s array with n2 number of elements starting from the element’s index idx2
in the array src.
The element’s index at the beginning of the array is zero.
If a value equal to or greater than the length of the array is given to idx1, it performs asimilar processing to that of the append() member function (§1.4.8). When the sum of idx1
and n1 is greater than the number of elements in the array, or the extension or contractionof the array is required depending on the magnitude relation between n1 and n2, it adjusts
the number of elements automatically.
PARAMETERSLLIB Reference: sli::tarray Template (Supporting the Array of Arbitrary Data Types or Classes)15
[I]
[I]
[I]
[I]

idx1
n1
one
n

Subscript specifying the first element of a subarray in this object
Number of elements in the subarray to be replaced
A reference to a scalar that fills a new array of length n
Number of elements in the new array that replaces the original subarray in thisobject[I] src
A reference to an object containing an input array[I] idx2 Array subscript specifying the first element to be extracted from the input arraysrc[I] n2
Number of elements to be extracted from the input array src([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer.

1.4.11erase()

NAME
erase() — Erase an element
SYNOPSIS
tarray &erase(); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
tarray &erase( size_t index, size_t num_elements = 1 ); . . . . . . . . . . . . . . . . . . . . 2
DESCRIPTION
The member function 1 erases all elements in the caller’s array. (The length of the array
becomes 0.)
The member function 2 erases num elements number of elements starting from the element’s
index index.
The element’s index at the beginning of the array is zero. If num elements is not specified,
it erases one element.
If a value equal to or greater than the length of the array is given to index, it is ignored.
PARAMETER[I] index
Subscript specifying the first element of a subarray to be removed[I] num_elements Number of elements in the subarray([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer.

1.4.12clean()

NAME
clean() — Padding of the existing values in an array by arbitrary ones

16SLLIB Reference: sli::tarray Template (Supporting the Arrays of Arbitrary Data Types or Classes)
SYNOPSIS
tarray &clean(const type &one);
DESCRIPTION
clean() performs the padding of all elements in the caller’s array with the value one. The
length of the array does not change even after clean() is executed.
PARAMETER[I] one A reference to a scalar that should be written to all entries of this array([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer for elements.

1.4.13

resize()NAME
resize() — Change the length of the array
SYNOPSIS
tarray &resize( size_t new_num_elements );DESCRIPTION
resize() changes the length of the caller’s array to new num elements. When the length of
the array is contracted, the elements after new num elements are deleted.
PARAMETER[I] new_num_elements([I] : input, [O] : output)

Number of elements of this array after being resized

RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer.

1.4.14

resizeby()

NAME
resizeby() — Change the length of the array relatively
SYNOPSIS
tarray &resizeby( ssize_t len );DESCRIPTION
resizeby() changes the length of the caller’s array by adding or subtracting the length oflen.
When the length of the array is contracted, the last abs(len) number of elements are deleted.

SLLIB Reference: sli::tarray Template (Supporting the Array of Arbitrary Data Types or Classes)17
PARAMETER[I] len Number of elements to be appended to or removed from this array([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer.
1.4.15crop()

NAME
crop() — Extract an array
SYNOPSIS
tarray &crop( size_t idx, size_t len );tarray &crop( size_t idx );DESCRIPTION
crop() crops a part of the caller’s array by leaving only len number of elements startingfrom the element’s index idx. If len is omitted, it crops everything but the elements after
idx.
PARAMETER[I] idx Subscript specifying the first element of a subarray to be extracted from thisobject[I] len Number of elements in the extracted subarray([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer.

18SLLIB Reference: sli::asarray (Supporting the Associative Arrays of Arbitrary Data Types or Classes)

2

ASARRAY Template Class

The asarray template class can handle the associative arrays of arbitrary data types or classes.
Its function is almost the same as that of asarray tstring in the Basic Edition, except that
this class does not include member functions specializing in string. Therefore, the EXAMPLE
section is omitted in this chapter. As for EXAMPLE, see the references of each member functionof asarray tstring in Basic Edition.
To use the asarray template class, write the following code followed by the user code:¨¥#include <sli/asarray.h>§¦

Additionally, write “using namespace sli;” in the code if the namespace declaration is required.

2.1

How to Create an Object

To create an object of the asarray template class, no arguments are required. Create it normallyas shown below:¨¥#include <sli/asarray.h>using namespace sli;
int main(){asarray<asarray_tstring> my_2d_aarray;§¦

In this example, the array of asarray tstring in the Basic Edition is created. This make it easy tohandle a two dimensional array of string as shown below.
¨
§

2.2

¥

my_2d_aarray["CONFIG"]["OS"] = "Linux";

List of Member Functions

Member functions are listed in Table 2.

¦

SLLIB Reference: sli::asarray (supporting the associative array of arbitrary data types or classes)19§2.3.1§2.3.2§2.4.1§2.4.2Function Name[]=length()at(), atf()§2.4.3

at_cs(), atf_cs()§2.4.4§2.4.5§2.4.6§2.4.7§2.4.8§2.4.9§2.4.10§2.4.11§2.4.12§2.4.13§2.4.14§2.4.15§2.4.16

index()
key()
keys()
values()swap()
init()
assign()assign_keys()split_keys()append()insert()erase()
clean()§2.4.17

rename_a_key()

Description
A reference to an element corresponding to the specified key
Copy an object of the asarray class
Length of an associated array (the number of elements)
A reference to the element value corresponding
to specified key or element number
A reference to the element value corresponding
to specified key or element number(read only)
Acquire the element number corresponding to the key string
Acquire the key string corresponding to the element number
A reference to the array object of the key string (read only)
A reference to the array object of the value (read only)
Replace objects
Initialize an object completely
Initialize an object and substitute an element
Assign multiple strings or arrays of strings to the key
Split a string and assign to the key
Append an element
Insert an element
Erase an element (a set of a key and a value)
Padding of the total existing values in an associated arrayby arbitrary ones
Change a key string

Table 2: List of Member Functions Available in asarray Template Class

20SLLIB Reference: sli::asarray (Supporting the Associative Arrays of Arbitrary Data Types or Classes)

2.3
2.3.1

Operators[]

NAME[] — A reference to an element corresponding to the specified key
SYNOPSIS
type &operator[]( const char *key ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
const type &operator[]( const char *key ) const; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
DESCRIPTIONThis operator returns a reference to an element value in the associative array with which key
is associated. Member functions in the type class can be called by specifying them after thisoperator and the “.” operator.
The member function 1 is available for read/write and corresponds to at(). The member
function 2 is available for read only and corresponds to at_cs().
When the key string not defined in the associative array is specified, the member function 1
appends the set of the key string and the default value (depending on the type class) to thearray, and the member function 2 throws an exception.
Whether the member function 1 or 2 is used depends on whether the object has the const
attribute. The member function 1 is used for the object without the const attribute, andthe function 2 is used with the attribute automatically.
For more information about at(), at_cs(), see §2.4.2.
PARAMETER[I] key A key string of the associative array
RETURN VALUE
A reference to the value of the element corresponding to the key in the associative array
EXCEPTION- Both functions throw an exception when “NULL” is given as the argument key.
- The member function 1 throws an exception when it fails to allocate a local buffer.
- The member function 2 throws an exception when the specified key string is not found.

2.3.2

=

NAME
= — Copy an object of the asarray classSYNOPSIS
asarray &operator=(const asarray &obj);
DESCRIPTIONThis operator substitutes the asarray class object specified by the right side of the operator(argument) into the object itself.
PARAMETER[I] obj A reference to an object in the class “asarray” whose contents should be copied
to this array

SLLIB Reference: sli::asarray (supporting the associative array of arbitrary data types or classes)21
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer, or it detects memory
corruption.

2.4
2.4.1

Member Functions
length()NAME
length() — Length of an associated array (the number of elements)
SYNOPSIS
size_t length() const;
DESCRIPTION
length() returns the length (number of elements) of the caller’s associative array.
RETURN VALUE
Length of a associative array
2.4.2

at(), atf()

NAMEat(), atf() — A reference to the element value corresponding to the specified key or element
numberSYNOPSIS
type &at( const char *key ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
type &atf( const char *fmt, ... ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
type &vatf( const char *fmt, va_list ap ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
type &at( size_t index ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
const type &at( const char *key ) const; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
const type &atf( const char *fmt, ... ) const; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
const type &vatf( const char *fmt, va_list ap ) const; . . . . . . . . . . . . . . . . . . . . .
const type &at( size_t index ) const; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1
2
3
4
5
6
7
8

DESCRIPTION
at() and atf() return a reference to an element value in the associative array corresponding
to the key string (member functions 1-3, 5-7) or the element’s index (member functions 4
and 8) of the argument.
Member functions in the type class can be used by placing the “.” operator immediately
after these member functions. The member functions 1-4 can be used for both read/write,
while the member functions 5-8 are read only.
As for the member functions 2, 3, 6 and 7, a key string to be specified can be set in thesame format and variable argument as the printf() function. In the member functions 2
and 6, each elemental data in the variable length argument is converted depending on theconversion specification of fmt. In the member functions 3 and 7, the list of the variable
length argument ap is converted depending on the conversion specification of fmt. See themanual of the printf() function in libc for fmt.

22SLLIB Reference: sli::asarray (Supporting the Associative Arrays of Arbitrary Data Types or Classes)
When a given key string is not found, a combination of the specified key string and default
value (depending on the type class) is added to the associative array in the member functions
1-3, while an exception is thrown in the member functions 5-7.
If a value equal to or greater than the length of the array is given to index for the member
function 4 or 8, an exception is thrown. The element’s index at the beginning of the array is
zero.
Whether the member functions 1-4 or 5-8 are used depends on whether the object has theconst attribute. Without the const, member functions 1-4 are selected. With the attribute,the member functions 5-8 are selected automatically.
PARAMETER[I] key[I] fmt[I] ...

A key string for the associative array
A format specification for defining a key string
A variable number of arguments that should be treated according to the format
specification fmt[I] apA list of arguments of the va list type that should be treated according to
the format specification fmt[I] index Array subscript of the integer type size t([I] : input, [O] : output)

RETURN VALUE
A reference to the value of the element corresponding to the specified key or element’s index
EXCEPTION- All overloaded functions throw an exception when “NULL” is given as the argument key.
- When a given key string is not found, the member functions 5, 6, and 7 throw an exception.
- The member functions 4 and 8 throw an exception when the specified integer subscript
index is invalid.
- All overloaded functions except 4, 5, and 8 throw an exception when they fail to allocate alocal buffer.

2.4.3

at cs(), atf cs()

NAME
at cs(), atf cs() — A reference to the element value corresponding to the specified key orelement number (read only)
SYNOPSIS
const type &at_cs( const char *key ) const; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
const type &atf_cs( const char *fmt, ... ) const; . . . . . . . . . . . . . . . . . . . . . . . . . . .
const type &vatf_cs( const char *fmt, va_list ap ) const; . . . . . . . . . . . . . . . . . .
const type &at_cs( size_t index ) const; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1
2
3
4

DESCRIPTION
at cs() and atf cs() return a reference to an element value in the associative array corresponding to the key string (member function 1-3) or element’s index (member function 4) of
the argument. These member functions are for read only.
As for the member functions 2 and 3, a key string to be specified can be set in the sameformat and variable argument as the printf() function. In the member function 2, eachelemental data in the variable length argument is converted depending on the conversion

SLLIB Reference: sli::asarray (supporting the associative array of arbitrary data types or classes)23
specification of fmt. In the member function 3, the list of the variable length argument ap isconverted depending on the conversion specification of fmt. See the manual of the printf()
function in libc for fmt.
The element’s index at the beginning of the array is zero.
When a given key string or element’s index is not found, an exception is thrown.
PARAMETER[I] key[I] fmt[I] ...

A key string for the associative array
A format specification for defining a key string
A variable number of arguments that should be treated according to the format
specification fmt[I] apA list of arguments of the va list type that should be treated according to
the format specification fmt[I] index Array subscript of the integer type size t([I] : input, [O] : output)

RETURN VALUE
A reference to the value of the element corresponding to the specified key or element’s index
EXCEPTION- All overloaded functions throw an exception when “NULL” is given as the argument key.
- When a given key string is not found, the member functions 1, 2, and 3 throw an exception.
- The member function 4 throws an exception when the specified integer subscript index isinvalid.
- The member functions 2 and 3 throw an exception when they fail to allocate a local buffer.

2.4.4

index(), indexf(), vindexf()

NAME
index(), indexf(), vindexf() — Acquire the element number corresponding to the key string
SYNOPSIS
ssize_t index( const char *key ) const; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
ssize_t indexf( const char *fmt, ... ) const; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
size_t vindexf( const char *fmt, va_list ap ) const; . . . . . . . . . . . . . . . . . . . . . . . . 3
DESCRIPTION
index(), indexf() and vindexf() get the element’s index corresponding to the key string.
The element’s index at the beginning of the array is zero.
As for the member function 2 and 3, a key string to be specified can be set in the same format
and variable argument as the printf() function. In the member function 2, each elemental
data in the variable length argument is converted depending on the conversion specificationof fmt. In the member function 3, the list of the variable length argument ap is converted
depending on the conversion specification of fmt. See the manual of the printf() function
in libc for fmt.
PARAMETER

24SLLIB Reference: sli::asarray (Supporting the Associative Arrays of Arbitrary Data Types or Classes)
[I]
[I]
[I]

key
fmt
...

A key string for the associative array
A format specification for defining a key string
A variable number of arguments that should be treated according to the format
specification fmt[I] apA list of arguments list of the va list type that should be treated according to
the format specification fmt([I] : input, [O] : output)
RETURN VALUE
Non-negative value
Negative value (error)::

Corresponding element’s index (if the specified key string isfound)
If the specified key string is not found

EXCEPTION
The member functions 2 and 3 throw an exception when it fails to allocate a local buffer.
2.4.5

key()

NAME
key() — Acquire the key string corresponding to the element number
SYNOPSIS
const char *key( size_t index ) const;
DESCRIPTION
key() gets the key string corresponding to the element’s index specified by index. The
element’s index at the beginning of the array is zero.
If a value equal to or greater than the length of the array is given to index, it returns NULL.
PARAMETER[I] index Array subscript of integer type size t([I] : input, [O] : output)
RETURN VALUE
An address of an internal buffer of a key string (normal end)
NULL (error, if the specified element’s index equal to or greater than the length of an array)
2.4.6

keys()

NAME
keys() — A reference to the array object of the key string (read only)
SYNOPSIS
const tarray_tstring &keys() const;
DESCRIPTION
keys() returns a reference to an object of the key string array (tarray tstring class: See the
Basic Editon Manual) managed in the object. Member functions in the tarray tstring classcan be used by placing the “.” operator immediately after this member function. The only
available member functions in the tarray tstring class are those that do not change the string,or in other words, tthose with the const attribute.
RETURN VALUE
A reference to an array object (tarray tstring class) of a key string

SLLIB Reference: sli::asarray (supporting the associative array of arbitrary data types or classes)25
2.4.7

values()NAME
values() — A reference to the array object of the value (read only)
SYNOPSIS
const tarray<type> &values() const;
DESCRIPTION
values() returns a reference to an object of the array of the values (tarray template class:See §1) managed in the object. Member functions in the tarray template class can be usedby placing the “.” operator immediately after this member function. The only available
member functions in the tarray template class are those that do not change the string, or inother words, tthose with the const attribute.
RETURN VALUE
A reference to an array object (tarray template class) of a value

2.4.8

swap()NAME
swap() — Replace objects
SYNOPSIS
asarray &swap( asarray &sobj );DESCRIPTION
swap() swaps the caller’s content for that of object sobj.
PARAMETER[I/O] sobj

An instance of the class “asarray” that should swap its contents for thisobject([I] : input, [O] : output)

RETURN VALUE
A reference to itself
2.4.9

init()

NAME
init() — Initialize an object completely
SYNOPSIS
asarray &init(); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
asarray &init( const asarray &obj ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
DESCRIPTION
init() initializes the caller’s associative array.
The member function 1 initializes the caller completely. A memory area allocated to theassociative array buffer or elements is released completely.
The member function 2 initializes the caller with the content of the specified object obj(copies the whole content of obj to the caller object).

26SLLIB Reference: sli::asarray (Supporting the Associative Arrays of Arbitrary Data Types or Classes)
PARAMETER[I] obj An instance of the class “asarray” whose contents should be copied to this object([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXCEPTION- Both functions throw an exception when they fail to allocate a local buffer.
- The member function 2 also throws an exception when it detects memory corruption.

2.4.10assign()NAME
assign() — Initialize an object and substitute an element
SYNOPSIS
asarray &assign( const char *key, const type &val ); . . . . . . . . . . . . . . . . . . . . . . . . 1
asarray &assign( const asarray &src ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
DESCRIPTION
The member function 1 initializes the caller’s associative array with one specified element (acombination of the key and value).
The member function 2 assigns the content of the specified object src to the caller’s associative array.
PARAMETER[I] key A key string to be registered for the associative array[I] val A reference to a scalar associated with the key string[I] src An instance of the class “asarray” whose contents should be copied to this object([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer.
2.4.11

assign keys()

NAME
assign keys() — Assign multiple strings or arrays of strings to the key
SYNOPSIS
asarray &assign_keys( const char *key0, ... ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
asarray &vassign_keys( const char *key0, va_list ap ); . . . . . . . . . . . . . . . . . . . . .
asarray &assign_keys( const char *const *keys ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
asarray &assign_keys( const tarray_tstring &keys ); . . . . . . . . . . . . . . . . . . . . . . . . .

1
2
3
4

DESCRIPTION
assign keys() sets the specified multiple strings key0, ... or the string array keys to the keyof the caller’s associative array. See the Basic Edition Manual for the tarray tstring class.

SLLIB Reference: sli::asarray (supporting the associative array of arbitrary data types or classes)27
The number of keys specified by the argument is set as the number of the associative arrays.
When the elements in the associative array exceed the number of keys specified by theargument, they are deleted.
The variable argument in the member functions 1 and 2 and the pointer array keys in themember function 3 must be terminated with NULL.
PARAMETER[I] key0 A key string to be registered for the associative array[I] ...
A variable number of arguments that contain key strings and are terminated
by NULL[I] apA list of arguments of the va list type that consists of key strings and is
terminated by NULL
[I] keys An array of character strings whose last entry should be NULL for the member
function 3([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer.

2.4.12

split keys()

NAME
split keys() — Split a string and assign to the key
SYNOPSIS
asarray &split_keys( const char *src_str, const char *delims,
bool zero_str, const char *quotations,int escape, bool rm_escape ); . . . . . . . . . . . . . . . . . . . . . . . . . .
asarray &split_keys( const char *src_str, const char *delims,
bool zero_str = false ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
asarray &split_keys( const tstring &src_str, const char *delims,
bool zero_str, const char *quotations,int escape, bool rm_escape ); . . . . . . . . . . . . . . . . . . . . . . . . . .
asarray &split_keys( const tstring &src_str, const char *delims,
bool zero_str = false ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1
2

3
4

DESCRIPTION
split keys() splits the string src str by the delimiter character delims and assigns them tothe key of the caller’s associative array. For delims, it is possible to specify with such a simple
character list as " \t" or "[A-Z]" or "[^A-Z]" used for regular expressions. Furthermore,a character class can be specified in "[...]". See the description about the trim() member
function of the tstring class in the Basic Edition Manual for specifiable character classes.
The number of keys obtained after splitting the string is set as the number of the associativearrays. (When the elements in the associative array exceed the number of keys obtained after
splitting the string, they are deleted.)
Whether or not the string of zero length is allowed can be specified with zero str. If
zero str is false, creating key element of the string of zero length is not allowed. If

28SLLIB Reference: sli::asarray (Supporting the Associative Arrays of Arbitrary Data Types or Classes)
zero str is true, creating the key element of string of the zero length is allowed. (It can beused in the csv format.) If zero str is not specified, false is assumed.
If you do not want to split a string enclosed by “specific characters” such as a quotation
mark, specify “specific characters” in quotations. For example, to exclude strings enclosed
by single quotation marks from splitting, specify as "’".
Escape characters can be specified with escape. To remove escape characters after splitting,
set true to rm escape. However, escape characters enclosed by the characters specified byquotations are not removed.
If you can not get keys successfully with this member function alone, try to create a key
string in the tarray tstring class object and set the keys by using the assign keys member
function (§2.4.11).
PARAMETER[I] src_str[I] delims[I] zero_str

A character string to be split
A character string that consists of delimiters
True if you permit the function to produce a zero-sized key string (i.e.,a key string containing no character).
[I] quotations A character string that consists of quotation marks[I] escapeAn escape character[I] rm_escape
True if the escape character should be removed([I] : input, [O] : output)

RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer.
2.4.13

append()NAME
append() — Append an element
SYNOPSIS
asarray &append( const char *key, const type &val ); . . . . . . . . . . . . . . . . . . . . . . . . 1
asarray &append( const asarray &src ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
DESCRIPTION
The member function 1 appends one specified element (a combination of the key and value)
to the caller’s associative array. The member function 2 assigns the content of the specified
object src to the caller’s associative array.
If the specified key overlaps with the existing key, a warning is output to stderr upon execution
and no processing is performed.
PARAMETER[I] key A key string to be appended to the associative array[I] val A reference to a scalar being associated with the key string[I] src An instance of the class “asarray” whose contents should be copied to this object([I] : input, [O] : output)
RETURN VALUE
A reference to itself

SLLIB Reference: sli::asarray (supporting the associative array of arbitrary data types or classes)29
EXCEPTION
The function throws an exception when it fails to allocate a local buffer.

2.4.14

insert()NAME
insert() — Insert an element
SYNOPSIS
asarray &insert( const char *key,
const char *newkey, const type &newval ); . . . . . . . . . . . . . . . . . 1
asarray &insert( const char *key, const asarray &src ); . . . . . . . . . . . . . . . . . . . . . 2
DESCRIPTION
The member function 1 inserts one specified element (a combination of the key and value)
followed by the position of the element corresponding the key key in the caller’s associativearray.
The member function 2 inserts the content of the specified object src followd by the positionof the element corresponding the key key in the caller’s associative array.
If the specified key overlaps with the existing key, a warning is output upon execution andno processing is performed.
PARAMETER[I] key

A key string specifying an element of this array before which a new element
should be inserted[I] newkey A key string to be inserted to the associative array[I] newval A reference to a scalar being associated with the key string[I] src
An instance of the class “asarray” whose contents should be copied to thisobject([I] : input, [O] : output)

RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer.

2.4.15erase()

NAME
erase() — Erase an element (a set of a key and a value)
SYNOPSIS
asarray &erase(); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
asarray &erase( const char *key, size_t num_elements = 1 ); . . . . . . . . . . . . . . . 2
DESCRIPTION
erase() erases elements in the caller’s associative array.
The member function 1 erases all elements in the caller’s associative array. (The length of
the array becomes 0.)

30SLLIB Reference: sli::asarray (Supporting the Associative Arrays of Arbitrary Data Types or Classes)
The member function 2 erases num elements number of elements starting from the element
corresponding to the key specified by key. If num elements is not specified, it erases one
element.
The array become shorter as more elements are erased.
PARAMETER[I] key
A key string specifying the first element to be removed[I] num_elements The number of elements to be removed([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer.

2.4.16clean()

NAME
clean() — Padding of the total existing values in an associated array by arbitrary ones
SYNOPSIS
asarray &clean(const type &one);
DESCRIPTION
clean() performs the padding of all elements in the caller’s associative array with the value
one. The length of the array does not change even after clean() is executed.
PARAMETER[I] one A reference to a scalar that should be written to all entries of the associativearray([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer for elements.

2.4.17

rename a key()

NAME
rename a key() — Change a key string
SYNOPSIS
asarray &rename_a_key( const char *org_key, const char *new_key );DESCRIPTION
rename a key() changes the key string org key in the caller’s associative array to the string
specified by new key.
If the key string specified by org key is not found in the associative array, or if new key
overlaps with the existing key, an error message is output to the standard error output.

SLLIB Reference: sli::asarray (supporting the associative array of arbitrary data types or classes)31
PARAMETER[I] org_key Original key string replaced by new key[I] new_key A new key string replacing org key([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer.

32

3

SLLIB Reference: sli::ctindex (Managing the Relation between Key Strings and Indexes)

CTINDEX Class

The ctindex class manages the relationship between the key string and the index. Once therelationship between a string (key) and a number (index) is registered, the index can be retrieved
quickly by using key string. Its behavior is similar to that of hash, but no collision occurs because
this class manages the relationship between the key string and the index with a dictionary.

object

key
"AZR"
"ABA"
"AZ"
"ABC"

A
objectB NULL . . . .

NULL

Z

index
1
2
3
4

3

objectobjectA NULL C

R

4

1

2

Figure 1: Outline of ctindex Class. Each node is a ctindex-class object and a part of the tree
structure. The circled number is the index stored. The right table shows the set of key strings andindexes.
A working principle of the ctindex class is shown in Figure 1. As shown in the figure, when the
key string is registered, multiple ctindex objects constitute a tree structure and the index is savedin the buffer of each node (object). Therefore, the time it takes to retrieve the index with the key
string is proportional to the length of the string without exception.
To use the ctindex class, write the following code followed by the user code:¨¥#include <sli/ctindex.h>§¦

Additionally, write “using namespace sli;” in the code if the namespace declaration is required.

3.1

How to Create an Object

To create an object of the ctindex class, no arguments are required. Create it normally as shown
below:¨¥#include <sli/ctindex.h>using namespace sli;
int main(){ctindex my_index;§

3.2

List of Member Functions

Member functions are listed in Table 3.

¦

SLLIB Reference: sli::ctindex (Managing the Relation between Key Strings and Indexes)§3.3.1§3.4.1§3.4.2§3.4.3§3.4.4§3.4.5Function Name=init()
append()update()erase()
index()

Description
Substitute the ctindex object
Initialize of an object completely
Append a pair of a key and an index
Update an index
Erase a pair of a key and an index
Acquire an index value

Table 3: List of Member Functions Available in ctindex Class

33

34

3.3
3.3.1

SLLIB Reference: sli::ctindex (Managing the Relation between Key Strings and Indexes)

Operators=

NAME= — Substitute the ctindex object
SYNOPSIS
ctindex &operator=(const ctindex &obj);
DESCRIPTIONThis operator substitutes the ctindex-class object specified by the right side of the operator(argument) into the object itself.
PARAMETER[I] obj An object belonging to the ctindex class
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer, or it detects memory
corruption.
EXAMPLEThe following code substitutes the ctindex object my idx into the object my idx1 and prints
each index of the key string rose and cosmos to stdout. For more information about index()
and append(), see §3.4.5 and §3.4.2.
stdstreamio sio;
ctindex my_idx;
ctindex my_idx1;
my_idx.append("rose",0);my_idx.append("cosmos",1);
my_idx1 = my_idx;
sio.printf("my_idx1.index... [%zd]\n", my_idx1.index("rose"));sio.printf("my_idx1.index... [%zd]\n", my_idx1.index("cosmos"));
Output:my idx1.index...
my idx1.index...

3.4

[0]
[1]

Member Functions

General Notice
Multiple indexes can be assigned to one key string. The search of the key string becomesslow in proportion to the number of indexes.
When the key string is not found when retrieving the index, -1 is returned.
The index can be retrieved from the key string, but the key string cannot be retrieved fromthe index.

SLLIB Reference: sli::ctindex (Managing the Relation between Key Strings and Indexes)
3.4.1

35

init()

NAME
init() — Initialize of an object completely
SYNOPSIS
ctindex &init(); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
ctindex &init(const ctindex &obj); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
DESCRIPTION
init() initializes an object.
The member function 1 initializes an object completely, and a memory area allocated to adictionary buffer in the object is released completely.
The member function 2 initializes with the content of the ctindex class object obj.
PARAMETER[I] obj An object belonging to the class “ctindex”([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXCEPTION- Both functions throw an exception when they fail to allocate a local buffer.
- The member function 2 also throws an exception when it detects memory corruption.
EXAMPLEThe following code initializes the ctindex-class object my idx1 by my idx and prints the index
to stdout. For more information about index() and append(), see §3.4.5 and §3.4.2.
stdstreamio sio;
ctindex my_idx;
ctindex my_idx1;
my_idx.append("Morning glory",0);my_idx.append("Gentiana",1);
my_idx1.init(my_idx);
sio.printf("my_idx1.index... [%zd]\n", my_idx1.index("Morning glory"));sio.printf("my_idx1.index... [%zd]\n", my_idx1.index("Gentiana"));Output:my idx1.index...
my idx1.index...

3.4.2

[0]
[1]

append()NAME
append() — Append a pair of a key and an index

36

SLLIB Reference: sli::ctindex (Managing the Relation between Key Strings and Indexes)SYNOPSIS
int append( const char *key, size_t index );DESCRIPTION
append() appends the key string key and the corresponding index index to a ctindex object.
PARAMETER[I] key
A key string to be appended[I] index Value of the index specifying the key string([I] : input, [O] : output)
RETURN VALUE
0
Negative value(error)::

Normal end
If the same combination of a key and an index exist
If a key is NULLEXCEPTION
The function throws an exception when it fails to allocate a local buffer.
EXAMPLEThe following code appends "Pansy", 2 and "Violet", 4 to the ctindex-class object my idx
and prints the indexes of "Pansy" and "Violet" to stdout for confirmation. For the information about index(), see §3.4.5:
stdstreamio sio;
ctindex my_idx;
my_idx.append("Pansy",2);
my_idx.append("Violet",4);
sio.printf("my_idx.index... [%zd]\n", my_idx.index("Pansy"));sio.printf("my_idx.index... [%zd]\n", my_idx.index("Violet"));Output:my idx.index...
my idx.index...

3.4.3

[2]
[4]

update()NAME
update() — Update an index
SYNOPSIS
int update( const char *key, size_t current_index, size_t new_index );DESCRIPTION
update() changes a value of the index corresponding to the key string key.
PARAMETER[I] key
A key string[I] current_index Current value of the index for the key[I] new_index
Updated value of the index for the key([I] : input, [O] : output)

SLLIB Reference: sli::ctindex (Managing the Relation between Key Strings and Indexes)
RETURN VALUE
0
Negative value(error)

:
:

37

Normal end
If a key is NULL

EXAMPLEThe following code changes the index of the key "Pansy" in the ctindex-class object my idx
from 2 to 1 and prints the index to stdout twice before and after update() for confirmation.
For more information about index(), see §3.4.5.
stdstreamio sio;
ctindex my_idx;
my_idx.append("Pansy",2);
my_idx.append("Violet",4);
sio.printf("my_idx.index... [%zd]\n", my_idx.index("Pansy"));my_idx.update("Pansy", 2, 1);
sio.printf("my_idx.index... [%zd]\n", my_idx.index("Pansy"));Output:my idx.index...
my idx.index...

3.4.4

[2]
[1]

erase()

NAME
erase() — Erase a pair of a key and an index
SYNOPSIS
int erase( const char *key, size_t index );DESCRIPTION
erase() erases the key string key and the corresponding index index.
PARAMETER[I] key
A key string to be removed[I] index Value of the index for the key([I] : input, [O] : output)
RETURN VALUE
Value more than 0
Negative value (error)::

Normal end
If the combination of the specified key and index does not exist
If the specified key does not exist
If the specified key is NULLEXCEPTION
The function throws an exception when it fails to allocate a local buffer.
EXAMPLEThe following code erases the set of the key "Pansy" and the value 2 in the ctindex-classobject my idx and prints the index to stdout after erase() for confirmation. For more
information about index() and append(), see §3.4.5 and §3.4.2.

38

SLLIB Reference: sli::ctindex (Managing the Relation between Key Strings and Indexes)
stdstreamio sio;
my_idx.append("Pansy",2);
my_idx.append("Violet",4);
my_idx.append("Pansy",6);
my_idx.erase("Pansy", 2);
sio.printf("my_idx.index... [%zd]\n", my_idx.index("Pansy"));Output:my idx.index...

3.4.5

[6]

index()

NAME
index() — Acquire an index value
SYNOPSIS
ssize_t index( const char *key, int index_of_index = 0 ) const;
DESCRIPTION
index() gets on index value of the key string key.
If the key string key has multiple indexes, set n to index of index to get n-th value of theindex. index of index starts from zero.
PARAMETER[I] key[I] index_of_index

A key string
Subscript of integer type specifying one of the several indices forthe key([I] : input, [O] : output)

RETURN VALUE
Non-negative value
Negative value(error)::

A value of index
If the index corresponding to the specified key does not exist

EXAMPLEThe following code registers the same key with a different index to the ctindex-class object
my idx and prints the index to stdout. For more information about append(), see §3.4.2.
stdstreamio sio;
ctindex my_idx;
my_idx.append("Pansy",2);
my_idx.append("Violet",4);
my_idx.append("Pansy",6);
int i = 0 ;while ( 0 < my_idx.index("Pansy",i) ) {sio.printf("my_idx.index[Pansy]... [%zd]\n", my_idx.index("Pansy",i));i++;}

SLLIB Reference: sli::ctindex (Managing the Relation between Key Strings and Indexes)
Output:my idx.index[Pansy]...
my idx.index[Pansy]...

[2]
[6]

39

40

SLLIB Reference: sli::Mdarray

4

MDARRAY Class

The mdarry class can handle multidimensional arrays of types in C or structures.
It has features as follows:• It has two operating modes:“Automatic Resize Mode”, in which the memory area is allocated automatically as necessary when users access an element of arrays and “Manual Resize
Mode”, which is suitable for handling an image data.
• Operators “+”, “-”, “*”, “/”, “+=”, “-=”, “*=”, “/=”, and “=” are available for scalar values
and the whole array.
• Mathematic functions (sin(), log(), etc.) to carry out an operation to the whole array areprepared. (Almost all functions defined in math.h of libc are available.)¨

To use the classes, write the following code followed by the user code:#include <sli/mdarray.h>#include <sli/mdarray_math.h>§¥¦mdarray_math.h is not necessary when only using classes, but it is necessary when using mathematic functions on the whole array. Additionally, write using namespace sli; in the code whennamespace declaration is required.
Brief example of use is shown following.
¨¥#include <sli/stdstreamio.h>#include <sli/mdarray.h>using namespace sli;
int main(){
stdstreamio sio;mdarray my_mdarr(INT_ZT);/* declare an array of integer */my_mdarr.i(0) = 10;
my_mdarr.i(1) = 20;/* the array size is automatically set *//* access an integer
via the member function i() */my_mdarr.i(0,1) = 30;/* extended to the 2x2(2-dimension) array */return 0;
}
§

4.1

¦

How to Create an Object

Create a mdarray class object by using the following constructor:
Automatic Resize Modemdarray(); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
mdarray( ssize_t sz_type, void **extptr_ptr = NULL ); . . . . . . . . . . . . . . . . . . . . . . . 2
Manual Resize Modemdarray( ssize_t sz_type, size_t naxis0 ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
mdarray( ssize_t sz_type, size_t naxis0, size_t naxis1 ); . . . . . . . . . . . . . . . . . . 4

SLLIB Reference: sli::Mdarray41

mdarray( ssize_t sz_type, size_t naxis0, size_t naxis1, size_t naxis2 );5mdarray( ssize_t sz_type, const size_t naxisx[], size_t ndim ); . . . . . . . . . . . 6
The member functions 3-5 are used to create one-, two- and three- dimensional arrays, respectively. The member function 6 is used to create n dimensional array. As for the member functions
1 and 2, while the number of dimensions and the length of the array are both 0 immediately
after the object is created, the number of dimensions and the length of the array are extended
automatically when the element is accessed.
Give the integer (type-specfic) that represents type in C to the argument sz_type. The constantfor this integer is defined in “sli/size types.h” for your use (Table 4). Use the constant name insteadof using the actual value directly in the code.
Data Type in C
float
doublefcomplex

Constant Identifier
FLOAT ZTDOUBLE ZTFCOMPLEX ZT

Value
-4
-8
-7

dcomplex

DCOMPLEX ZT-15

unsigned char
short
int
long
long long
int16 tint32 tint64 tsize tssize tbool
uintptr t

UCHAR ZTSHORT ZTINT ZT
LONG ZTLLONG ZT
INT16 ZT
INT32 ZT
INT64 ZTSIZE ZTSSIZE ZTBOOL ZTUINTPTR ZT

1system-dependent
system-dependent
system-dependent
system-dependent2
48
system-dependent
system-dependent
system-dependent
system-dependent

Description
Single-precision floating-point number
Souble-precision floating-point number
Single-precision floating-point complex
Number (unusable, unaccomplished)
Double-precision floating-point complex
Number (unusable, unaccomplished)
Unsigned 1-byte integer
Signed integer
Signed integer
Signed integer
Signed integer
Signed 2-byte integer
Signed 4-byte integer
Signed 8-byte integer
Snsigned integer
Signed integer
Boolean
Unsigned integer corresponding
To the address width

Table 4: List of Constants Defined in sli/size types.h
To handle an array of the structure, give the byte size of the structure to sz_type. If theargument sz_type is not given (in case of the member function 1), it is assumed that UCHAR ZT isgiven.
The mdarray class has two kinds of operating modes: (1)Automatic Resize Mode and (2)Manual
Resize Mode. In the Automatic Resize Mode, the number of dimensions and size of arrays areextended automatically as necessary when you access the element of the array by using assign(),etc., or carry out an operation of the array by using the operators “+=”, “-=”, etc. On the other
hand, in the Manual Resize Mode, the buffer size is not changed unless expressly specified to be
resized (thus, this mode is suitable for handling an image data).
The operating mode is decided when the object is initialized by the constructors or the init()
member function (§4.5.24). It works in the Automatic Resize Mode when the number of thearrays is not given and in the Manual Resize Mode when the number of the arrays is given upon
initialization.

42

4.2

SLLIB Reference: sli::Mdarray

Mathematic Functions

The available mathematic functions are shown in Table 5.

4.3

List of Member Functions

A list of member functions is shown in Table 6.

SLLIB Reference: sli::Mdarray
Function Prototype
mdarray cbrt( const mdarray &obj );mdarray sqrt( const mdarray &obj );mdarray asin( const mdarray &obj );mdarray acos( const mdarray &obj );mdarray atan( const mdarray &obj );mdarray acosh( const mdarray &obj );mdarray asinh( const mdarray &obj );mdarray atanh( const mdarray &obj );mdarray exp( const mdarray &obj );mdarray exp2( const mdarray &obj );mdarray expm1( const mdarray &obj );mdarray log( const mdarray &obj );mdarray log1p( const mdarray &obj );mdarray log10( const mdarray &obj );mdarray sin( const mdarray &obj );mdarray cos( const mdarray &obj );mdarray tan( const mdarray &obj );mdarray sinh( const mdarray &obj );mdarray cosh( const mdarray &obj );mdarray tanh( const mdarray &obj );mdarray erf( const mdarray &obj );mdarray erfc( const mdarray &obj );mdarray ceil( const mdarray &obj );mdarray floor( const mdarray &obj );mdarray round( const mdarray &obj );mdarray trunc( const mdarray &obj );mdarray fabs( const mdarray &obj );mdarray hypot( const mdarray &obj, float v );mdarray hypot( const mdarray &obj, double v );mdarray hypot( float v, const mdarray &obj );mdarray hypot( double v, const mdarray &obj );mdarray hypot( const mdarray &src0,
const mdarray &src1 );mdarray pow( const mdarray &obj, float v );mdarray pow( const mdarray &obj, double v );mdarray pow( float v, const mdarray &obj );mdarray pow( double v, const mdarray &obj );mdarray pow( const mdarray &src0,
const mdarray &src1 );mdarray fmod( const mdarray &obj, float v );mdarray fmod( const mdarray &obj, double v );mdarray fmod( float v, const mdarray &obj );mdarray fmod( double v, const mdarray &obj );mdarray fmod( const mdarray &src0,
const mdarray &src1 );mdarray remainder( const mdarray &obj, float v );mdarray remainder( const mdarray &obj, double v );mdarray remainder( float v, const mdarray &obj );mdarray remainder( double v, const mdarray &obj );mdarray remainder( const mdarray &src0,
const mdarray &src1 );43
Description
Cubic root
Square root
Arc sine
Arc cosine
Arc tangent
Arc hyperbolic cosine
Arc hyperbolic sine
Arc hyperbolic tangent
Exponential function with base e
Exponential function with base 2
Exponent of argument minus 1
Natural logarithmic function
Logarithm of 1 plus argument
Logarithm with base 10
Sine
CosineTangent
Hyperbolic sine
Hyperbolic cosine
Hyperbolic tangent
Error function
Complementary error function
Smallest integer not less than argument
Largest integer not greater than argument
Round a number to the nearest integer
Truncate a number to the next nearest
integer towards 0
Absolute value
Euclidean distance function

Power

Modulo arithmetic

Remainder

Table 5: List of Available Mathematic Functions

44

SLLIB Reference: sli::Mdarray

Function Name

Description§4.4.1§4.4.2§4.4.3§4.4.4§4.4.5§4.4.6§4.4.7§4.4.8§4.4.9§4.4.10§4.4.11

=
=
+=
+=
-=
-=
*=
*=
/=
/=
+

§4.4.12+§4.4.13§4.4.14-Substitute an array (initialization of an object)
Substitute a scalar value
Add an array to itself
Add a scalar value to itself
Subtract an array from itself
Subtract a scalar value from itself
Multiply itself by an array
Multiply itself by a scalar value
Divide itself by an array
Divide itself by a scalar value
Return the object which stores the resultof adding an array to itself
Return the object which stores the resultof adding a scalar value to itself
Return the object which stores the resultof subtracting an array from itself
Return the object which stores the resultof subtracting a scalar value from itself
Return the object which stores the resultof multiplying itself by an array
Return the object which stores the resultof multiplying itself by a scalar value
Return the object which stores the resultof dividing itself by an array
Return the object which stores the resultof dividing itself by a scalar value
CompareCompare (negative form)
Integer representing a data type
Number of bytes of an element
Number of dimensions of an array
Number of elements (in a dimension)
Total byte size of elements (in a dimension)in an array
The length of the array’s column
The length of the array’s row
The layer number of the array
A reference to specified value of the element
Read specified value of the element
The value of the element converted into double typeThe value of the element converted into longor long long type§4.4.15*§4.4.16*§4.4.17/§4.4.18/§4.4.19§4.4.20§4.5.1§4.5.2§4.5.3§4.5.4§4.5.5==!=size_type()
bytes()
dim_length()length()byte_length()§4.5.6§4.5.7§4.5.8§4.5.9§4.5.10§4.5.11§4.5.12col_length()row_length()layer_length()f(), ...
f_cs(), ...
dvalue()lvalue(),llvalue()

Table 6: List of Member Functions Available in mdarray Class (cont’d)Operating Mode
Support

°
°
°
°

°

SLLIB Reference: sli::Mdarray§4.5.13

Function Name

Description

default_value_ptr()

The acquisition and the settingof the initial value
The acquisition and the settingof the resize mode
The acquisition and the settingof the rounding off possibility
Output of the object information
to the stderr output(for user’s debug)
The acquisition of the specified
element’s address
Register a user pointer variable
Copy the array itself to the user’s buffer
Copy the array in the user’s buffer
to the array itself
Copy the array itself to the user’s buffer
Copy the array in the user’s buffer
to the array itself
Reverse the endian if necessary
The initialization of the array
Substitute a value for an element(high level)
Set a value to an arbitrary element’s point
Replace values between elements
Copy values between elements
Copy values between elements(with automatic expansion)
Insert an element
Extract an element
Erase an element
Change the length of the array
Change the length of the array relatively
The expansion of the dimension number
The reduction of the dimension number
Replace the object by another one
Convert the type of the array
Raise decimals to the next whole number
in a double type value
Devalue decimals in a double type value
Round off decimals in a double type value
Omit decimals in a double type value
Absolute value of all elements
Compare array objects§4.5.16

assign_default()
auto_resize(),
set_auto_resize()rounding()
set_rounding()
dprint()§4.5.17

data_ptr()§4.5.18§4.5.19§4.5.20

register_extptr()
get_elements()
put_elements()§4.5.21§4.5.22

getdata()putdata()§4.5.23§4.5.24§4.5.25§4.5.26§4.5.27§4.5.28§4.5.29

reverse_endian()
init()
assign()put()
swap()
move()
cpy()§4.5.30§4.5.31§4.5.32§4.5.33§4.5.34§4.5.35§4.5.36§4.5.37§4.5.38§4.5.39

insert()crop()
erase()
resize()resizeby()
increase_dim()decrease_dim()swap()
convert()ceil()§4.5.40§4.5.41§4.5.42§4.5.43§4.5.44

floor()
round()
trunc()
abs()
compare()§4.5.14§4.5.1545

Operating Mode
Support°°

Table 6: List of Member Functions Available in mdarray Class (cont’d)46

SLLIB Reference: sli::Mdarray§4.5.45§4.5.46

Function Namecopy()
copy()§4.5.47cut()§4.5.48cut()§4.5.49

clean()§4.5.50§4.5.51§4.5.52§4.5.53§4.5.54§4.5.55§4.5.56§4.5.57

fill()
add()
multiply()
paste()
add()
subtract()
multiply()
divide()Description
Copy an array into another object
Copy a part of an array into another object(for image data)
Cut all values in an array and copy theminto another object
Cut a part of values in an array and copy theminto another object (for image data)
Padding existing values in an arrayby default ones (for image data)
Rewrite element values (for image data)
Add element values (for image data)
Multiply element values (for image data)
Paste up an array object (for image data)
Add an array object (for image data)
Subtract an array object (for image data)
Multiply an array object (for image data)
Divide an array object (for image data)

Operating Mode Support

Table 6: List of Member Functions Available in mdarray ClassSLLIB Reference: sli::Mdarray

4.4
4.4.1

47

Operators=

NAME= — Initialize of an object
SYNOPSIS
mdarray &operator=(const mdarray &obj);
DESCRIPTIONThis operator initializes the object itself and copies all the contents and attributes (the lengthof arrays and the data types, etc.) of obj to the object itself.
PARAMETER[I] obj An object belonging to the class “mdarray”([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer, or it detects memory
corruption.
EXAMPLEThe following code initializes the object my mdarr of the mdarray class by area mdarr andprints the result to stdout. For more information about ll() and length(), see §4.5.9 and§4.5.4.
stdstreamio sio;mdarray my_mdarr;
mdarray area_mdarr(LLONG_ZT);
area_mdarr.ll(0) = 17090000;
area_mdarr.ll(1) = 9980000;
area_mdarr.ll(2) = 9620000;
my_mdarr = area_mdarr;for ( size_t i=0 ; i < my_mdarr.length() ; i++ ) {sio.printf("my_mdarr value[%zu]... [%lld]\n", i, my_mdarr.ll(i));}
Output:my mdarr value[0]...
my mdarr value[1]...
my mdarr value[2]...

4.4.2[17090000][9980000][9620000]=NAME= — Substitute of a scalar value

48

SLLIB Reference: sli::Mdarray

SYNOPSIS
mdarray &operator=(double v); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
mdarray &operator=(long long v); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
mdarray &operator=(long v); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
mdarray &operator=(int v); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1
2
3
4

DESCRIPTIONThis operator substitutes the value (scalar value) specified by the right side of the operator(argument) into the object itself. The array size is not extended automatically, so it isnecessary to set the number of elements and to reserve the buffer area in advance.
PARAMETER[I] v A real or integer scalar([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXAMPLEThe following code substitutes the scalar value, 125, into the object mdarr with a onedimension array and prints the result to stdout. For more information about length() andc(), see §4.5.4 and §4.5.9.
stdstreamio sio;mdarray my_mdarr(UCHAR_ZT, 2);
my_mdarr = 125;for ( size_t i=0 ; i < my_mdarr.length() ; i++ ) {sio.printf("my_mdarr value[%zu]... [%hhu]\n", i, my_mdarr.c(i));}
Output:my mdarr value[0]...
my mdarr value[1]...

4.4.3

[125]
[125]

+=

NAME
+= — Add an array to itself
SYNOPSIS
mdarray &operator+=(const mdarray &obj);
DESCRIPTIONThis operator adds the object array of the mdarray class specified by the right side of theoperator (argument) to the object itself. When object with the different data type fromthat of the object itself is specified, cast operations are executed just like a normal scalar
operation.
In the Automatic Resize Mode, the array size is extended automatically if each dimension
size of obj is larger than that of the object itself.

SLLIB Reference: sli::Mdarray

49

PARAMETER[I] obj An object belonging to the class “mdarray”([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer, or it detects memory
corruption.
4.4.4

+=

NAME
+= — Add a scalar value to itself
SYNOPSIS
mdarray &operator+=(double v);
mdarray &operator+=(long long v);
mdarray &operator+=(long v);
mdarray &operator+=(int v);
DESCRIPTIONThis operator adds the scalar value specified by the right side of the operator (argument) toall elements of the object itself. When the data type of the argument is different from thatof the object itself, cast operations are executed just like a normal scalar operation.
PARAMETER[I] v A real or integer scalar([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXAMPLEThe following code adds the scalar value, 50, to the object my mdarr of the mdarray classand prints the result to stdout. For more information about length() and c(), see §4.5.4
and §4.5.9.
stdstreamio sio;mdarray my_mdarr(UCHAR_ZT, 2);
my_mdarr = 25;
my_mdarr += 50;
for ( size_t i=0 ; i < my_mdarr.length() ; i++ ) {sio.printf("my_mdarr value[%zu]... [%hhu]\n", i, my_mdarr.c(i));}
Output:my mdarr value[0]...
my mdarr value[1]...

[75]
[75]

50
4.4.5

SLLIB Reference: sli::Mdarray-=

NAME−= — Subtract an array from itself
SYNOPSIS
mdarray &operator-=(const mdarray &obj);
DESCRIPTIONThis operator subtracts the object array of the mdarray class specified by the right side of
the operator (argument) from the object itself. When the object, with the different data
type from that of the object itself is specified, cast operations are executed just like a normal
scalar operation.
In the Automatic Resize Mode, the array size is extended automatically if each dimension
size of obj is larger than that of the object itself.
PARAMETER[I] obj An object belonging to the class “mdarray”([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer, or it detects memory
corruption.
EXAMPLEThe following code subtracts the object subst mdarr from the object my mdarr of the mdarray class and prints the result to stdout. For more information about length() and c(), see§4.5.4 and §4.5.9.
stdstreamio sio;mdarray my_mdarr(UCHAR_ZT, 2);
my_mdarr = 100;mdarray subst_mdarr(UCHAR_ZT, 2);
subst_mdarr.c(0) = 10;
subst_mdarr.c(1) = 20;
my_mdarr -= subst_mdarr;for ( size_t i=0 ; i < my_mdarr.length() ; i++ ) {sio.printf("my_mdarr value[%zu]... [%hhu]\n", i, my_mdarr.c(i));}
Output:my mdarr value[0]...
my mdarr value[1]...

[90]
[80]

SLLIB Reference: sli::Mdarray
4.4.6

51

-=

NAME
−= — Subtract a scalar value from itself
SYNOPSIS
mdarray &operator-=(double v);
mdarray &operator-=(long long v);
mdarray &operator-=(long v);
mdarray &operator-=(int v);
DESCRIPTIONThis operator subtracts the scalar value specified by the right side of the operator(argument)from all elements of the object itself. In case that the data type of the argument is different
from that of the object itself, cast operations are executed like a normal scalar operation.
PARAMETER[I] v a real or integer scalar([I] : input, [O] : output)
RETURN VALUE
A reference to itself
4.4.7

*=

NAME
∗= — Multiply itself by an array
SYNOPSIS
mdarray &operator*=(const mdarray &obj);
DESCRIPTIONThis operator multiplies the object itself by the object array of the mdarray class specified
by the right side of the operator (argument). When the object with the different data typefrom that of the object itself is specified, cast operations are executed just like a normal
scalar operation.
In the Automatic Resize Mode, the array size is extended automatically if each dimension
size of obj is larger than that of the object itself.
PARAMETER[I] obj An object belonging to the class “mdarray”([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer, or it detects memory
corruption.
EXAMPLEThe following code multiplies the object my mdarr of the mdarray class by the object mdarrPlus
and prints the result to stdout. For more information about length() and l(), see §4.5.4
and §4.5.9.

52

SLLIB Reference: sli::Mdarray
stdstreamio sio;mdarray my_mdarr(LONG_ZT, 2);
my_mdarr = 50;
mdarray multi_mdarr(LONG_ZT);
multi_mdarr.l(0) = 10;
multi_mdarr.l(1) = 20;
multi_mdarr.l(2) = 30;
my_mdarr *= multi_mdarr;for ( size_t i=0 ; i < my_mdarr.length() ; i++ ) {sio.printf("my_mdarr value[%zu]... [%ld]\n", i, my_mdarr.l(i));}
Output:my mdarr value[0]...
my mdarr value[1]...

4.4.8

[500]
[1000]*=

NAME∗= — Multiply itself by a scalar value
SYNOPSIS
mdarray &operator*=(double v);
mdarray &operator*=(long long v);
mdarray &operator*=(long v);
mdarray &operator*=(int v);
DESCRIPTIONThis operator multiplies all elements of the object itself by the scalar value specified by theright side of the operator (argument). When the data type of the argument is different fromthat of the object itself, cast operations are executed just like a normal scalar operation.
PARAMETER[I] v A real or integer scalar([I] : input, [O] : output)
RETURN VALUE
A reference to itself

4.4.9

/=

NAME
/= — Divide itself by an array
SYNOPSIS
mdarray &operator/=(const mdarray &obj);

SLLIB Reference: sli::Mdarray

53

DESCRIPTIONThis operator divides the object itself by the object array of the mdarray class specified by
the right side of the operator (argument). When the object with the different data type fromthat of the object itself is specified, cast operations are executed just like a normal scalar
operation.
In cthe Automatic Resize Mode, the array size is extended automatically if each dimension
size of obj is larger than that of the object itself.
PARAMETER[I] obj An object belonging to the class “mdarray”([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer, or it detects memory
corruption.
EXAMPLEThe following code divides the object my mdarr of the mdarray class by the object div mdarr
and prints the result to stdout. For more information about length() and l(), see §4.5.4
and §4.5.9.
stdstreamio sio;mdarray my_mdarr(LONG_ZT, 2);
my_mdarr = 50;
mdarray div_mdarr(LONG_ZT);
div_mdarr.l(0) = 1;
div_mdarr.l(1) = 2;
div_mdarr.l(2) = 5;
my_mdarr /= div_mdarr;for ( size_t i=0 ; i < my_mdarr.length() ; i++ ) {sio.printf("my_mdarr value[%zu]... [%ld]\n", i, my_mdarr.l(i));}
Output:my mdarr value[0]...
my mdarr value[1]...
4.4.10

[50]
[25]

/=

NAME
/= — Divide itself by a scalar value
SYNOPSIS
mdarray &operator/=(double v);
mdarray &operator/=(long long v);
mdarray &operator/=(long v);
mdarray &operator/=(int v);

54

SLLIB Reference: sli::Mdarray

DESCRIPTIONThis operator divides all elements of the object itself by the scalar value specified by theright side of the operator (argument). When the data type of the argument is different fromthat of the object itself, cast operations are executed just like a normal scalar operation.
PARAMETER[I] v A real or integer scalar([I] : input, [O] : output)
RETURN VALUE
A reference to itself
4.4.11+NAME+ — Return the object that stores the result of adding an array to itself
SYNOPSIS
mdarray operator+(const mdarray &obj);
DESCRIPTIONThis operator returns the object that stores the result of adding the object array of themdarray class specified by the right side of the operator (argument) to the object itself. The
argument is the base class (mdarray class). Thus, the object with the different data type fromthat of the object itself can be specified to the argument and cast operations are executed
just like a normal scalar operation.
The returned operation mode and rounding attribute are identical to those of the object
itself.
PARAMETER[I] obj A object belonging to the class “mdarray”([I] : input, [O] : output)
RETURN VALUE
An object including the calculation result
EXCEPTION
The function throws an exception when it fails to allocate a local buffer, or it detects memory
corruption.

4.4.12+NAME+ — Return the object that stores the result of adding a scalar value to itself
SYNOPSIS
mdarray operator+(double v);
mdarray operator+(float v);
mdarray operator+(long long v);
mdarray operator+(long v);
mdarray operator+(int v);

SLLIB Reference: sli::Mdarray

55

DESCRIPTIONThis operator returns the object that stores the result of adding the scalar value specified by
the right side of the operator (argument) to all elements of the object itself. When the data
type of the argument is different from that of the object itself, cast operations are executed
just like a normal scalar operation.
The returned operation mode and rounding attributes are identical to those of the object
itself.
PARAMETER[I] v A real or integer scalar([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer.

4.4.13-NAME− — Return the object that stores the result of subtracting an array from itself
SYNOPSIS
mdarray operator-(const mdarray &obj);
DESCRIPTIONThis operator returns the object that stores the result of subtracting the object array of themdarray class specified by the right side of the operator (argument) from the object itself.
The argument is the base class (mdarray class). Thus, with the different data type from thatof the object itself can be specified to the argument and cast operations are executed justlike a normal scalar operation.
The returned operation mode and rounding attribute are identical to those of the object
itself.
PARAMETER[I] obj A object belonging to the class “mdarray”([I] : input, [O] : output)
RETURN VALUE
An object including the calculation result
EXCEPTION
The function throws an exception when it fails to allocate a local buffer, or it detects memory
corruption.

4.4.14-NAME− — Return the object that stores the result of subtracting a scalar value from itself

56

SLLIB Reference: sli::Mdarray

SYNOPSIS
mdarray operator-(double v);
mdarray operator-(float v);
mdarray operator-(long long v);
mdarray operator-(long v);
mdarray operator-(int v);
DESCRIPTIONThis operator returns the object that stores the result of subtracting the scalar value specified
by the right side of the operator (argument) from all elements of the object itself. Whenthe data type of the argument is different from that of the object itself, cast operations are
executed just like a normal scalar operation.
The returned operation mode and rounding attributes are identical to those of the object
itself.
PARAMETER[I] v A real or integer scalar([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer.
4.4.15*NAME∗ — Return the object that stores the result of multiplying itself by an array
SYNOPSIS
mdarray operator*(const mdarray &obj);
DESCRIPTIONThis operator returns the object that stores the result of multiplying the object itself by
the object array of the mdarray class specified by the right side of the operator (argument).
The argument is the base class (mdarray class). Thus, the object with the different data
type from that of the object itself can be specified to the argument and cast operations are
executed just like a normal scalar operation.
The returned operation mode and rounding attribute are identical to those of the object
itself.
PARAMETER[I] obj A object belongings to the class “mdarray”([I] : input, [O] : output)
RETURN VALUE
An object including the calculation result
EXCEPTION
The function throws an exception when it fails to allocate a local buffer, or it detects memory
corruption.

SLLIB Reference: sli::Mdarray
4.4.1657*

NAME∗ — Return the object that stores the result of multiplying itself by a scalar value
SYNOPSIS
mdarray operator*(double v);
mdarray operator*(float v);
mdarray operator*(long long v);
mdarray operator*(long v);
mdarray operator*(int v);
DESCRIPTIONThis operator returns the object that stores the result of multiplying all elements of theobject itself by the scalar value specified by the right side of the operator (argument). Whenthe data type of the argument is different from that of the object itself, cast operations are
executed like a normal scalar operation.
The returned operation mode and rounding attribute are identical to those of the object
itself.
PARAMETER[I] v A real or integer scalar([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer.
4.4.17/NAME/ — Return the object that stores the result of dividing itself by an array
SYNOPSIS
mdarray operator/(const mdarray &obj);
DESCRIPTIONThis operator returns the object that stores the result of dividing the object itself by theobject array of the mdarray class specified by the right side of the operator (argument).
The argument is the base class (mdarray class). Thus, the object with the different data
type from that of the object itself can be specified to the argument and cast operations are
executed just like a normal scalar operation.
The returned operation mode and rounding attributes are identical to those of the object
itself.
PARAMETER[I] obj An object that belonging to the class “mdarray”([I] : input, [O] : output)
RETURN VALUE
An object including the calculation result

58

SLLIB Reference: sli::Mdarray

EXCEPTION
The function throws an exception when it fails to allocate a local buffer, or it detects memory
corruption.

4.4.18/NAME/ — Return the object that stores the result of dividing itself by a scalar value
SYNOPSIS
mdarray operator/(double v);
mdarray operator/(float v);
mdarray operator/(long long v);
mdarray operator/(long v);
mdarray operator/(int v);
DESCRIPTIONThis operator returns the object that stores the result of dividing all elements of the object
itself by the scalar value specified by the right side of the operator (argument). When thedata type of the argument is different from that of the object itself, cast operations are
executed just like a normal scalar operation.
The returned operation mode and rounding attribute are identical to those of the object
itself.
PARAMETER[I] v A real or integer scalar([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer.

4.4.19==NAME== — Compare
SYNOPSIS
bool operator==(const mdarray &obj) const;
DESCRIPTIONThis operator compares the object of the mdarray class specified by the right side of theoperator (argument) with the object itself. If the array size and elements of the argument
obj are identical to those of the object itself, it returns true. Otherwise, it returns false.
This member function uses the compare() function (§4.5.44) internally.
PARAMETER[I] obj A object belonging to the class “mdarray”([I] : input, [O] : output)

SLLIB Reference: sli::Mdarray

59

RETURN VALUE
true : If the sizes and values of the elements on the arrays are identicalfalse : If the sizes and one of the values of the elements on the arrays are not identical
EXAMPLEThe following code compares the object my mdarr of the mdarray class with the object
comp mdarr and prints the result to stdout:
stdstreamio sio;mdarray my_mdarr(UCHAR_ZT, 3);
my_mdarr = 20;
mdarray comp_mdarr(LONG_ZT);
comp_mdarr = 20;
if (my_mdarr == comp_mdarr) {sio.printf("true\n");} else {sio.printf("false\n");}Output:false
4.4.20!=

NAME!= — Compare (negative form)
SYNOPSIS
bool operator!=(const mdarray &obj) const;
DESCRIPTIONThis operator compares the object of mdarray (derived) class specified by the right side of
the operator (argument) with the object itself. If the argument obj is not identical to theobject itself, it returns true. Otherwise, it returns false. This member function uses thecompare() function (§4.5.44) internally.
PARAMETER[I] obj A object belonging to the class “mdarray”([I] : input, [O] : output)
RETURN VALUE
true : If the sizes and one of the values of the elements on the arrays are not identicalfalse : If the sizes and values of the elements on the arrays are identical
EXAMPLEThe following code compares the object my mdarr of the mdarray class with the object
comp mdarr and prints the result to stdout:
stdstreamio sio;mdarray my_mdarr(UCHAR_ZT, 3);

60

SLLIB Reference: sli::Mdarray
my_mdarr = 20;
mdarray comp_mdarr(LONG_ZT);
comp_mdarr = 20;
if (my_mdarr != comp_mdarr) {sio.printf("true\n");} else {sio.printf("false\n");}Output:
true

4.5
4.5.1

Member Functions
size type()

NAME
size type() — Integer representing a data type (type-specific)
SYNOPSIS
ssize_t size_type() const;
DESCRIPTIONThis member function returns an integer number corresponding to the data type. The data
type of arrays in the object itself is identified by the number.
When the information of the data type is used in the code, use the constant identifier inTable 4, not a raw number such as -4.
RETURN VALUE
An integer representing a type of the object
EXAMPLEThe following code creates the object my mdarr as the int32 t array and prints the size typeof my mdarr to stdout:
stdstreamio sio;mdarray my_mdarr(INT32_ZT);
sio.printf("*** my_mdarr size_type... [%zd]\n", my_mdarr.size_type());
Output:*** my_mdarr size_type... [4]4.5.2

bytes()

NAME
bytes() — Number of bytes of an element
SYNOPSIS
size_t bytes() const;

SLLIB Reference: sli::Mdarray

61

DESCRIPTIONThis member function returns the byte size of an element in the array of the object itself.
RETURN VALUE
A byte length of one element
EXAMPLEThe following code creates the object my mdarr as a double-precision floating-point array andprints the byte size of an element in the array to stdout:
stdstreamio sio;mdarray my_mdarr(DOUBLE_ZT);
sio.printf("*** my_mdarr bytes... [%zu]\n", my_mdarr.bytes());
Output:*** my_mdarr bytes... [8]4.5.3

dim length()NAME
dim length() — Number of dimensions of an array
SYNOPSIS
size_t dim_length() const;
DESCRIPTIONThis member function returns the number of dimensions for the array of the object itself.
RETURN VALUE
The number of dimensions of the array
EXAMPLEThe following code prints the number of dimensions for the array of the object my mdarr3dim
to stdout:
stdstreamio sio;mdarray my_mdarr3dim(FLOAT_ZT, 3, 4, 5);
sio.printf("*** my_mdarr3dim dim... [%zu]\n", my_mdarr3dim.dim_length());
Output:*** my_mdarr3dim dim... [3]
4.5.4

length()NAME
length() — Number of elements
SYNOPSIS
size_t length() const; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
size_t length( size_t dim_index ) const; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

62

SLLIB Reference: sli::Mdarray

DESCRIPTIONThis member function returns the total number of elements in the arrays of the object itself.
When the argument is not specified, the number of elements in dimension 1 × in dim. 2 × indim. 3 ... is returned. When dim index is passed to the argument, the number of elementsin the dimension with the index dim index is returned. dim index starts from 0.
PARAMETER[I] dim_index The integer number (≥ 0) that specifies one of the dimensions of the array([I] : input, [O] : output)
RETURN VALUE
The number of elements
EXAMPLEThe following code prints the total number of elements in the object my mdarr3dim and thenumber of elements in the dimension with the index 0 to stdout:
stdstreamio sio;mdarray my_mdarr3dim(FLOAT_ZT, 3, 4, 5);
sio.printf("*** my_mdarr3dim length... [%zu]\n", my_mdarr3dim.length());
sio.printf("*** my_mdarr3dim length 1dim... [%zu]\n", my_mdarr3dim.length(0));
Output:*** my_mdarr3dim length... [60]*** my_mdarr3dim length 1dim... [3]4.5.5

byte length()

NAME
byte length() — Total byte size of elements (in a dimension) in an array
SYNOPSIS
size_t byte_length() const; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
size_t byte_length( size_t dim_index ) const; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
DESCRIPTIONThis member function returns the total byte size of arrays in the object itself. Whendim index is passed to the argument, the byte size of an array for the dimension with theindex dim index is returned.
PARAMETER[I] dim_index The integer number (≥0) that specifies one of the dimensions of the array([I] : input, [O] : output)
RETURN VALUE
The whole byte size of the array or the byte size of the elements in the specified dimension
EXAMPLEThe following code prints the total byte size of the arrays in a three-dimension array my mdarr3dim
and the byte size of an array for the third dimension (dimension index: 2) to stdout:

SLLIB Reference: sli::Mdarray63

stdstreamio sio;mdarray my_mdarr3dim(FLOAT_ZT, 3, 4, 5);
sio.printf("*** my_mdarr3dim byte_length... [%zu]\n",my_mdarr3dim.byte_length());
sio.printf("*** my_mdarr3dim byte_length 3dim... [%zu]\n",my_mdarr3dim.byte_length(2));
Output:*** mdarr3dim byte_length... [240]*** mdarr3dim byte_length 3dim... [20]4.5.6

col length()

NAME
length() — The length of the array’s column
SYNOPSIS
size_t col_length() const;
DESCRIPTIONThis member function returns the length of the columns for the array of the object itself.
RETURN VALUE
A column length of the array
EXAMPLEThe following code prints the length of the columns for a three-dimension array my mdarr3dim
to stdout:
stdstreamio sio;mdarray my_mdarr3dim(FLOAT_ZT, 3, 4, 5);
sio.printf("*** my_mdarr3dim col... [%zu]\n", my_mdarr3dim.col_length());
Output:*** my_mdarr3dim col... [3]4.5.7

row length()NAME
row length() — The length of the array’s row
SYNOPSIS
size_t row_length() const;
DESCRIPTIONThis member function returns the length of the rows for the array of the object itself.
RETURN VALUE
A row length of the array

64

SLLIB Reference: sli::Mdarray

EXAMPLEThe following code prints the length of the rows for a three-dimension array my mdarr3dim
to stdout:
stdstreamio sio;mdarray my_mdarr3dim(FLOAT_ZT, 3, 4, 5);
sio.printf("*** my_mdarr3dim row... [%zu]\n", my_mdarr3dim.row_length());
Output:*** my_mdarr3dim row... [4]4.5.8

layer length()

NAME
layer length() — The number of the layers of the array
SYNOPSIS
size_t layer_length() const;
DESCRIPTIONThis member function returns the length of the layers for the array of the object itself. Whenthe dimension of the array is 1 or 2, 1 is returned. When the dimension of the array is 3
or more, after the array dimension is reduced to three, the length of the layers for the third
dimension (dimension index: 2) is returned.
RETURN VALUE
The number of dimensions of the array
EXAMPLEThe following code prints the length of the layers for a three-dimension array my mdarr3dim
to stdout:
stdstreamio sio;mdarray my_mdarr3dim(FLOAT_ZT, 3, 4, 5);
sio.printf("*** my_mdarr3dim layer... [%zu]\n", my_mdarr3dim.layer_length());
Output:*** my_mdarr3dim layer... [5]4.5.9f(), d(), ld(), c(), s(), i(), l(), ll(), i16(), i32(), i64(), z(), sz(), b(), p()NAMEf(), d(), ld(), etc. — A reference to the specified value of the element
SYNOPSIS
float &f( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
double &d( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

SLLIB Reference: sli::Mdarray65

long double &ld( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
unsigned char &c( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
short &s( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
int &i( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6long &l( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7long long &ll( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
int16_t &i16( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
int32_t &i32( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
int64_t &i64( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
size_t &z( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
ssize_t &sz( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
bool &b( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
uintptr_t &p( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
For each member function, the alternative function with the const attribute is available.
They work in the same manner as the member functions in §4.5.10.
DESCRIPTIONThis member function sets/gets the element specified by the arguments idx0, idx1, and idx2
to/from the array. Different member functions are used depending on the data type of thearray in the object itself.
When reading/writing a value with the member function 1 in the Automatic Resize Mode,
the size of an array is resized according to the specified index. In the Manual Resize Mode,
the substitution of a value into an element beyond the array size does not cause any error.
The operation is ignored. In order to substitute a value into an element beyond the arraysize, the array size has to be extended by a member function (e.g. resize()) in advance. For
more information about resize(), see §4.5.33.
When reading the element beyond the array size in Manual Resize Mode, NAN is returned
for floating-point numbers, and any one of INDEF UCHAR, INDEF INT16, INDEF INT32, or
INDEF INT64 is returned for integer numbers according to the data type of the element,
respectively. The value of each INDEF is the minimum integer value of the data type.
For the function at(), whether the member function 1 or 2 is used depends on whether theobject has the “const ” attribute. The member function 1 is used for the object without the“const ” attribute, and the function 2 is used with the attribute automatically.
Do not specify MDARRAY INDEF for an argument explicitly.
PARAMETER

66

SLLIB Reference: sli::Mdarray[I] idx0 Subscript for the first dimension being designated as 0
[I] idx1 Subscript for the second dimension being designated as 1 (optional)[I] idx2 Subscript for the third dimension being designated as 2 (optional)([I] : input, [O] : output)

RETURN VALUE
A reference to the value of the element according to the called member function
EXCEPTION
These member functions throw an exception when they fail to allocate a local buffer in the
Automatic Resize Mode, or the byte-size of each element in the array object is smaller thanthat of the return value of the functions.
EXAMPLEThe following code sets values to the elements of the object my fmdarr with a floating-point
number array via the member function f() and prints the values of elements to stdout by f():stdstreamio sio;mdarray my_fmdarr(FLOAT_ZT);
my_fmdarr.f(0) = 1000.1;
my_fmdarr.f(1) = 2000.2;
for ( size_t i = 0 ; i < my_fmdarr.length() ; i++ ) {sio.printf("my_fmdarr value[%zu]... [%5.1f]\n", i, my_fmdarr.f(i));}
Output:my fmdarr value[0]...
my fmdarr value[1]...
4.5.10[1000.1][2000.2]f cs(), d cs(), ld cs(), c cs(), s cs(), i cs(), l cs(), ll cs(), i16 cs(), i32 cs(),
i64 cs(), z cs(), sz cs(), b cs(), p cs()

NAME
f cs(), d cs(), ld cs(), etc. — Read one specified value of the element
SYNOPSIS
const float &f_cs( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ) const; . . . . . . . . . . . . . . . . . . .
const double &d_cs( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ) const; . . . . . . . . . . . . . . . . . .
const long double &ld_cs( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ) const; . . . . . . . . . . . . . . . . . . .
const unsigned char &c_cs( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ) const; . . . . . . . . . . . . . . . . . .
const short &s_cs( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ) const; . . . . . . . . . . . . . . . . . . .
const int &i_cs( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ) const; . . . . . . . . . . . . . . . . . .
const long &l_cs( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ) const; . . . . . . . . . . . . . . . . . . .

1
2
3
4
5
6
7

SLLIB Reference: sli::Mdarray67

const long long &ll_cs( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ) const; . . . . . . . . . . . . . . . . . . 8
const int16_t &i16_cs( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ) const; . . . . . . . . . . . . . . . . . . . 9
const int32_t &i32_cs( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ) const; . . . . . . . . . . . . . . . . . 10
const int64_t &i64_cs( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ) const; . . . . . . . . . . . . . . . . . . 11
const size_t &z_cs( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ) const; . . . . . . . . . . . . . . . . . 12
const ssize_t &sz_cs( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ) const; . . . . . . . . . . . . . . . . . . 13
const bool &b_cs( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ) const; . . . . . . . . . . . . . . . . . 14
const uintptr_t &p_cs( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ) const; . . . . . . . . . . . . . . . . . 15
For the object with “const” attribution, “_cs” in the member function name can be omitted.
DESCRIPTIONThis member function gets the element specified by the arguments idx0, idx1, and idx2
from the array. This function cannot set the element to the array.
When reading the element beyond the array size, NAN is returned for floating-point numbers,
and any one of INDEF UCHAR, INDEF INT16, INDEF INT32, or INDEF INT64 is returned for
integer numbers according to the data type of the element, respectively. The value of each
INDEF is the minimum integer value of the data type.
Do not specify MDARRAY INDEF for an argument explicitly.
PARAMETER[I] idx0 Subscript for the first dimension being designated as 0
[I] idx1 Subscript for the second dimension being designated as 1 (optional)[I] idx2 Subscript for the third dimension being designated as 2 (optional)([I] : input, [O] : output)
RETURN VALUE
A reference to the value of the element according to the called member function
EXCEPTION
The member functions throw an exception when the byte-size of each element in the arrayobject is smaller than that of the return value of the functions.
EXAMPLEThe following code sets values to the object my llmdarr with a long long array and prints
the values to stdout.
:
stdstreamio sio;mdarray my_llmdarr(LLONG_ZT);
my_llmdarr.ll(0) = 60000;
my_llmdarr.ll(1) = 70000000;
for ( size_t i = 0 ; i < my_llmdarr.length() ; i++ ) {sio.printf("my_llmdarr value[%zu]... [%lld]\n", i, my_llmdarr.ll_cs(i));

68

SLLIB Reference: sli::Mdarray}
Output:my llmdarr value[0]...
my llmdarr value[1]...

4.5.11[60000][70000000]

dvalue()NAME
dvalue() — The value of the element converted into the double typeSYNOPSIS
double dvalue( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ) const;
DESCRIPTIONThis member function casts the element in the array of the object itself to a double-precision
floating-point value and returns it.
When the specified index exceeds the array size, NAN is returned.
Do not specify MDARRAY INDEF for an argument explicitly.
PARAMETER[I] idx0 Subscript for the first dimension being designated as 0
[I] idx1 Subscript for the second dimension being designated as 1 (optional)[I] idx2 Subscript for the third dimension being designated as 2 (optional)([I] : input, [O] : output)
RETURN VALUE
A value converted to the double type
NAN(error)::

Normal end
When the type of the element is not supported
When the index of the elements exceeding thesize of the array is specified

EXAMPLEThe following code sets a value to the mdarray float-class object my mdarry and gets thevalue as a double-precision floating-point number, and prints it to stdout:
stdstreamio sio;mdarray_float my_mdarry;
my_mdarry[0] = 123.456;
sio.printf("my_mdarry dvalue... [\%6.3f]\n", my_mdarry.dvalue(0));
Output:my mdarry dvalue...

4.5.12[123.456]

lvalue(), llvalue()

NAME
lvalue(), llvalue() — The value of the element converted into the long or long long type

SLLIB Reference: sli::Mdarray

69

SYNOPSIS
long lvalue( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ) const; . . . . . . . . . . . . . . . . . . . . . . . . . . 1long long llvalue( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ) const; . . . . . . . . . . . . . . . . . . . 2
DESCRIPTIONThis member function casts the element in the array of the object itself to a long or long
long value and returns it.
When the data type of the array is floating-point, the value is truncated to the whole number
by default. In order to round it to the whole number, it requires the use of the set rounding()
function in advance. For more information about set rounding(), see §4.5.15.
When the specified index exceeds the array size, INDEF LONG or INDEF LLONG is returned,
respectively. The value of each INDEF is the minimum integer value of the data type.
Do not specify MDARRAY INDEF for an argument explicitly.
PARAMETER[I] idx0 Subscript for the first dimension being designated as 0
[I] idx1 Subscript for the second dimension being designated as 1 (optional)[I] idx2 Subscript for the third dimension being designated as 2 (optional)([I] : input, [O] : output)
RETURN VALUE
A value converted to the long or long long type
INDEF LONG or INDEF LLONG::

Normal end
When the type of the element is notsupported
When the index of the elemnts exceeding the size of the array is specified

EXAMPLEThe following code sets a value to the object my mdarry with a float array and gets the value
as a long number and as a long long number, and prints them to stdout:
stdstreamio sio;mdarray my_mdarry(FLOAT_ZT);
my_mdarry.f(0) = 123.556;
sio.printf("my_mdarry lvalue... [%ld]\n", my_mdarry.lvalue(0));
my_mdarry.set_rounding(true);sio.printf("my_mdarry llvalue... [%lld]\n", my_mdarry.llvalue(0));
Output:my mdarry lvalue... [123]my mdarry llvalue... [124]4.5.13default value ptr(), assign default()

NAME
default value ptr(), assign default() — Acquire and set the initial value upon size expansion

70

SLLIB Reference: sli::Mdarray

SYNOPSIS
const void *default_value_ptr() const; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
mdarray &assign_default( const void *value_ptr ); . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
mdarray &assign_default( double value ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
DESCRIPTION
The member function 1 returns the initial value for size extension. When the value is not set
up yet, NULL is returned.
The member functions 2 and 3 set up the initial value for size extension. The value does not
apply to the existing elements. When the array size is extended, it is applied to the array.
RETURN VALUE
The member function 1 returns an address including the default value in expanding the sizes(or NULL when the default value is not defined).
The member functions 2 and 3 return a reference to itself.
EXCEPTION
The functions 2 and 3 throw an exception when they fail to allocate a local buffer.
EXAMPLEThe following code prints the initial value of the object my mdarr with a float array for size
extension to stdout:
stdstreamio sio;mdarray my_mdarr;
my_mdarr.init(FLOAT_ZT);
my_mdarr.assign_default(50);
sio.printf("*** my_mdarr defval... [%f]\n",*((const float *)my_mdarr.default_value_ptr()));
Output:*** my_mdarr defval... [50.000000]

4.5.14

auto resize(), set auto resize()

NAME
auto resize(), set auto resize() — Acquire and set the resize mode
SYNOPSIS
bool auto_resize() const; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
mdarray &set_auto_resize( bool tf ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
DESCRIPTION
The member function 1 returns the resize mode by boolean type. The member function 2
sets up the resize mode by boolean type.
The Automatic Resize Mode corresponds to true (=1) and the Manual Resize Mode corresponds to false (=0).
See the Operation Mode Support box in Table 6 to find out which member functions support
the operation modes.

SLLIB Reference: sli::Mdarray

71

RETURN VALUE
The member function 1 returns an operation mode (or true in the Automatic Resize Mode).
The member function 2 returns a reference to itself.
EXAMPLEThe following code creates mdarr0dim in the Automatic Resize Mode and creates mdarr3dimin the Manual Resize Mode, and prints the resize modes of the arrays to stdout:
stdstreamio sio;mdarray my_mdarr0dim;
sio.printf("*** my_mdarr0dim auto_resize... [%d]\n",(int)(my_mdarr0dim.auto_resize()));
mdarray my_mdarr3dim(FLOAT_ZT, 3, 4, 5);
sio.printf("*** my_mdarr3dim auto_resize... [%d]\n",(int)(my_mdarr3dim.auto_resize()));
Output:*** my_mdarr0dim auto\_resize... [1]*** my_mdarr3dim auto\_resize... [0]4.5.15rounding(), set rounding()

NAME
rounding(), set rounding() — Acquire and set the rounding off possibility
SYNOPSIS
bool rounding() const; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
mdarray &set_rounding( bool tf ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
DESCRIPTION
The member function 2 sets up the rounding mode. Either the floating-point numbers aretruncated or rounded to the whole number in some high-level member functions. The member
function 1 returns true in the round mode and false in the truncate mode.
Upon creation of the mdarray class object, it is set to the truncate mode.
When objects are copied by the operator “=” or the init() member function, the rounding
attribution is also copied. For more information about init(), see §4.5.24.
The member functions that support the rounding attribution are: lvalue(), llvalue() (§4.5.12),
assign default() (§4.5.13), assign() (§4.5.25), convert()(§4.5.38), and all member functions forimages.
RETURN VALUE
The member function 1 returns an attribute of the operation on rounding.
The member function 2 returns a reference to itself.
EXAMPLEThe following code creates the object my mdarr with a long long array and sets a real number
twice before and after setting the rounding mode. Then the code prints the substituted values
to stdout for confirmation.

72

SLLIB Reference: sli::Mdarray
stdstreamio sio;mdarray my_mdarr(LLONG_ZT);
my_mdarr.assign(1.618, 0);
sio.printf("my_mdarr value[0]... [%lld]\n", my_mdarr.ll(0));
my_mdarr.set_rounding(true);
my_mdarr.assign(1.618, 1);
sio.printf("my_mdarr value[1]... [%lld]\n", my_mdarr.ll(1));
Output:my imdarr value[0]...
my imdarr value[1]...

4.5.16[1][2]

dprint()NAME
dprint() — Output of the object information to the standarderr output (for user’s debug)
SYNOPSIS
void dprint() const;
DESCRIPTIONThis member function prints the information of the object itself to stderr.
This is a function for debugging a user program.
EXAMPLEThe following code prints the information on the object my array to stderr. The address ofthe object in [] is system-dependent.
mdarray my_array(INT_ZT, 3,2,1);
my_array.i(2,0,0) = 100;
my_array.i(0,1,0) = 200;
my_array.dprint();
Output:sli::mdarray[obj=0x7fbffff630, sz_type=4, dim=(3,2,1)] = {{ { 0,0,100 },{ 200,0,0 } }}4.5.17

data ptr()

NAME
data ptr() — Acquire the specified element’s address
SYNOPSIS
void *data_ptr(); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
void *data_ptr( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
const void *data_ptr() const; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

SLLIB Reference: sli::Mdarray73

const void *data_ptr( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ) const; . . . . . . . . . . . . . . . 4
const void *data_ptr_cs( ssize_t idx0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ) const; . . . . . . . . . . . . 5
const void *data_ptr_cs() const; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
DESCRIPTION
These member functions get the address of the element specified by the index in the arrayof the object itself. Member functions 3 to 6 get the address for read only.
For the function data ptr(), whether the member functions 1, 2 or 3, 4 are used depends
on whether the oobject has the “const ” attribute. The member function 1 or 2 is used forthe object without the “const ” attribute, and the function 3 or 4 is used with the attributeautomatically.
Do not specify MDARRAY INDEF for an argument explicitly.
PARAMETER[I] idx0 Subscript for the first dimension being designated as 0
[I] idx1 Subscript for the second dimension being designated as 1 (optional)[I] idx2 Subscript for the third dimension being designated as 2 (optional)([I] : input, [O] : output)
RETURN VALUE
An address of the specified element
EXAMPLEThe following code gets the address of the value at (0, 1) in the object my fmdarr with a
two-dimension array and prints the value to stdout:
stdstreamio sio;mdarray my_fmdarr(FLOAT_ZT, 2,2);
my_fmdarr.f(0,0) = 1000;
my_fmdarr.f(1,0) = 2000;
my_fmdarr.f(0,1) = 3000;
my_fmdarr.f(1,1) = 4000;
const float *mycarray_ptr = (float *)my_fmdarr.data_ptr_cs(0, 1);
sio.printf("*** my_fmdarr carray[0] ---> [%f] *** \n", mycarray_ptr[0]);Output:*** my_fmdarr carray[0] ---> [3000.000000] ***4.5.18register extptr()

NAME
register extptr() — Register a user pointer variable
SYNOPSIS
mdarray &register_extptr(void *extptr_ptr);

74

SLLIB Reference: sli::Mdarray

DESCRIPTION
These member functions register the pointer of a user’s variable to the object itself.
The initial address of the buffer managed by the object can be held in the pointer of a user’s
variable by this function.
Do not forget to put the operator “&” on the pointer variable, which is passed to the argument.
(sees EXAMPLE below.)
PARAMETER[I] extptr_ptr Address of the user’s pointer([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXAMPLEThe following code registers the pointer of tokyoStock_ptr to the object tokyoStock_buf
and allocates memory for the buffer. It enables the direct access to the buffer by tokyoStock_ptr.
Then the code prints the values of tokyoStock_buf to stdout for confirmation.
stdstreamio sio;
struct tokyoStock {short id;long stock;};
struct tokyoStock *tokyoStock_ptr;
mdarray tokyoStock_buf(sizeof(struct tokyoStock));
tokyoStock_buf.register_extptr(&tokyoStock_ptr);/* the operator "&" is needed */tokyoStock_buf.resize(6);tokyoStock_ptr[0].id = 3407;
tokyoStock_ptr[0].stock = 438;
tokyoStock_ptr[1].id = 4951;
tokyoStock_ptr[1].stock = 1058;
for ( size_t i = 0 ; i < tokyoStock_buf.length(0) ; i++ ) {sio.printf("tokyoStock_buf stock[%zu]... [%ld]\n", i,tokyoStock_ptr[i].stock);}
Output:tokyoStock buf stock[0]...
tokyoStock buf stock[1]...

4.5.19[438][1058]

get elements()

NAME
get elements () — Copy the array itself to the user’s buffer

SLLIB Reference: sli::Mdarray

75

SYNOPSIS
ssize_t get_elements( void *dest_buf, size_t elem_size,
ssize_t idx0 = 0, ssize_t idx1 = MDARRAY_INDEF,
ssize_t idx2 = MDARRAY_INDEF ) const;
DESCRIPTIONThis member function copies the contents of the array for the object itself to the user buffer
specified by dest buf. The size of the buffer elem size is set by the number of elements.
The source is specified by the arguments idx0, idx1, and idx2.
Do not specify MDARRAY INDEF for an argument explicitly.
PARAMETER[O] dest_buf[I]elem_size[I]
idx0

Address of user’s buffer
The number of elements to be copied
Subscript of this array for its first dimension being designated as 0 (optional)[I]
idx1
Subscript of this array for its second dimension being designated as 1
(optional)[I]
idx2
Subscript of this array for its third dimension being designated as 2
(optional)([I] : input, [O] : output)

RETURN VALUE
The number of the elements copied when the user buffer length is enough.
EXCEPTION
The function throws an exception when it detects memory corruption.
EXAMPLEThe following code copies the contents of the object my fmdarr with a two-dimension array to the user buffer myfloat and prints the values of elements in myfloat to stdout for
confirmation:
stdstreamio sio;mdarray my_fmdarr(FLOAT_ZT, 2,2);
my_fmdarr.f(0,0) = 1000;
my_fmdarr.f(1,0) = 2000;
my_fmdarr.f(0,1) = 3000;
my_fmdarr.f(1,1) = 4000;
float myfloat[4];my_fmdarr.get_elements((void *)myfloat, sizeof(myfloat)/sizeof(float));for ( int i = 0 ; i < sizeof(myfloat)/sizeof(float) ; i++ ) {sio.printf("myfloat value[%d]... [%f]\n", i, myfloat[i]);}Output:myfloat value[0]...
myfloat value[1]...
myfloat value[2]...
myfloat value[3]...

[1000.000000][2000.000000][3000.000000][4000.000000]

76

SLLIB Reference: sli::Mdarray

4.5.20put elements()

NAME
put elements () — Copy the array in the user’s buffer to the array itself
SYNOPSIS
ssize_t put_elements( const void *src_buf, size_t elem_size, ssize_t idx0 = 0,
ssize_t idx1 = MDARRAY_INDEF, ssize_t idx2 = MDARRAY_INDEF );DESCRIPTIONThis member function copies the contents of the user buffer specified by src buf to the arrayfor the object itself. The size of the buffer elem_size is set by the number of elements. The
destination is specified by the arguments idx0, idx1, and idx2.
Do not specify MDARRAY INDEF for an argument explicitly.
PARAMETER[I] src_buf[I] elem_size[I] idx0

Address of the user’s buffer
Number of elements to be copied
Subscript of this array for its first dimension being designated as 0 (optional)[I] idx1
Subscript of this array for its second dimension being designated as 1
(optional)[I] idx2
Subscript of this array for its third dimension being designated as 2 (optional)([I] : input, [O] : output)

RETURN VALUE
The number of the elements copied when the user buffer length is enough
EXCEPTION
The function throws an exception when it detects memory corruption.
EXAMPLEThe following code copies the contents of the user buffer my float to the object my fmdarr
with a two-dimension array and prints the values of elements in my fmdarr to stdout for
confirmation:
stdstreamio sio;mdarray my_fmdarr(FLOAT_ZT, 2,2);
float my_float[] = {1000, 2000, 3000, 4000};my_fmdarr.put_elements((const void *)my_float, sizeof(my_float)/sizeof(float));for ( size_t j = 0 ; j < my_fmdarr.length(1) ; j++ ) {for ( size_t i = 0 ; i < my_fmdarr.length(0) ; i++ ) {sio.printf("my_fmdarr value(%zu,%zu)... [%f]\n",i, j, my_fmdarr.f(i, j));}}Output:my fmdarr value(0,0)...

[1000.000000]

SLLIB Reference: sli::Mdarray
my fmdarr value(1,0)...
my fmdarr value(0,1)...
my fmdarr value(1,1)...
4.5.2177[2000.000000][3000.000000][4000.000000]

getdata()NAME
getdata() — Copy the array itself to the user’s buffer
SYNOPSIS
ssize_t getdata( void *dest_buf, size_t buf_size, ssize_t idx0 = 0,
ssize_t idx1 = MDARRAY_INDEF, ssize_t idx2 = MDARRAY_INDEF ) const;
DESCRIPTIONThis member function copies the contents of the array for the object itself to the user buffer
specified by dest buf. The size of the buffer buf size is set by the byte unit. The source is
specified by the arguments idx0, idx1, and idx2.
Do not specify MDARRAY INDEF for an argument explicitly.
PARAMETER[O] dest_buf[I]buf_size[I]
idx0

Address of user’s buffer
Size of the buffer in bytes
Subscript of this array for its first dimension being designated as 0 (optional)[I]
idx1
Subscript of this array for its second dimension being designated as 1
(optional)[I]
idx2
Subscript of this array for its third dimension being designated as 2 (optional)([I] : input, [O] : output)

RETURN VALUE
A size of the buffer copied when the user buffer size (buf size) is enough.
EXCEPTION
The function throws an exception when memory corruption is detected.
EXAMPLEThe following code copies the contents of the object my fmdarr with a two-dimension array to the user buffer myfloat and prints the values of elements in myfloat to stdout for
confirmation:
stdstreamio sio;mdarray my_fmdarr(FLOAT_ZT, 2,2);
my_fmdarr.f(0,0) = 1000;
my_fmdarr.f(1,0) = 2000;
my_fmdarr.f(0,1) = 3000;
my_fmdarr.f(1,1) = 4000;
float myfloat[4];my_fmdarr.getdata((void *)myfloat, sizeof(myfloat));for ( int i = 0 ; i < sizeof(myfloat)/sizeof(float) ; i++ ) {78

SLLIB Reference: sli::Mdarraysio.printf("myfloat value[%d]... [%f]\n", i, myfloat[i]);}Output:myfloat value[0]...
myfloat value[1]...
myfloat value[2]...
myfloat value[3]...

4.5.22[1000.000000][2000.000000][3000.000000][4000.000000]

putdata()NAME
putdata() — Copy the array in the user’s buffer to the array itself
SYNOPSIS
ssize_t putdata( const void *src_buf, size_t buf_size, ssize_t idx0 = 0,
ssize_t idx1 = MDARRAY_INDEF, ssize_t idx2 = MDARRAY_INDEF );DESCRIPTIONThis member function copies the contents of the user buffer specified by src buf to the arrayfor the object itself. The size of the buffer buf_size is set by the byte unit. The destinationis specified by the arguments idx0, idx1, and idx2.
Do not specify MDARRAY INDEF for an argument explicitly.
PARAMETER[I] src_buf[I] buf_size[I] idx0

Address of user’s buffer
Size of the user’s buffer in bytes
Subscript of this array for its first dimension being designated as 0 (optional)[I] idx1
Subscript of this array for its second dimension being designated as 1
(optional)[I] idx2
Subscript of this array for its third dimension being designated as 2 (optional)([I] : input, [O] : output)

RETURN VALUE
A size of the buffer copied when the user buffer size (buf size) is enough
EXCEPTION
The function throws an exception when it detects memory corruption.
EXAMPLEThe following code copies the contents of the user buffer my float to the object my fmdarr
with a two-dimension array and prints the values of elements in my fmdarr to stdout for
confirmation:
stdstreamio sio;mdarray my_fmdarr(FLOAT_ZT, 2,2);
float my_float[] = {1000, 2000, 3000, 4000};my_fmdarr.putdata((const void *)my_float, sizeof(my_float));SLLIB Reference: sli::Mdarray79

for ( size_t j = 0 ; j < my_fmdarr.length(1) ; j++ ) {for ( size_t i = 0 ; i < my_fmdarr.length(0) ; i++ ) {sio.printf("my_fmdarr value(%zu,%zu)... [%f]\n",i, j, my_fmdarr.f(i, j));}}Output:my fmdarr value(0,0)...
my fmdarr value(1,0)...
my fmdarr value(0,1)...
my fmdarr value(1,1)...

4.5.23[1000.000000][2000.000000][3000.000000][4000.000000]

reverse endian()

NAME
reverse endian() — Reverse endian if necessary
SYNOPSIS
mdarray_type &reverse_endian( bool is_little_endian, ssize_t sz_type = 0 );DESCRIPTIONThis member function is called to save the array of the object itself as a binary data in a fileor load a binary data in a file to the array of the object itself.
To save data in a file, convert the endian of the data to the appropriate form for storingby this member function. Next, write the content by the stream writing function with theaddress obtained from the function such as data ptr()(§4.5.17). Then call this function again
for turning back the endian.
To load data from a file, read the content by the stream reading function with the address
obtained from the functions such as data ptr()(§4.5.17). Then convert the endian to theappropriate form for the system by this member function.
In both cases shown above, if the data to be stored on a file is big endian, the first argument
is set to false (if little endian, set to true).
For this member function, users do not have to be conscious of the difference in systemarchitecture. For instance, a user specifies false to the argument is little endian andcalls this function so that a data in big endian is saved in a file. If the machine is a big endiansystem, the inversion process is not executed in practice. (With a little endian system, theinversion process is executed.) Next, the user saves binary data in the object in a file in astraightforward way, and the binary file in the specified byte order is created. And then, theuser calls this member function with the same arguments again in order to turn back theendian if it was inverted.
This means that to save in a file this member function must be called twice with the same
arguments.
The endian inversion of a data type in the byte unit can be executed by specifying theconstant identifier (see the table in §4) of the data type to sz type.

80

SLLIB Reference: sli::Mdarray

PARAMETER[I] is_little_endian[I] sz_type([I] : input, [O] : output)

True when the ordering of data in a computer’s memory should
be little endian after one conversion
Type specifier (optional)

RETURN VALUE
A reference to itself
EXAMPLEThe following code outputs the binary file that contains the data of the object my mdarr witha two-dimension array in big endian:
stdstreamio sio;mdarray my_mdarr(INT_ZT, 2,2);
my_mdarr.i(0,0) = 10;
my_mdarr.i(1,0) = 20;
my_mdarr.i(0,1) = 30;
my_mdarr.i(1,1) = 40;
my_mdarr.reverse_endian(false);
const void *mydata_ptr = my_mdarr.data_ptr();if ( fio.openf("w", "%s", "binary.dat") < 0 ) {// Error Handling}if ( fio.write(mydata_ptr, my_mdarr.byte_length()) < 0 ) {// Error Handling}my_mdarr.reverse_endian(false);
fio.close();
Output:Contents of binary.dat:"00 00 00 0A""00 00 00 14""00 00 00 1E""00 00 00 28"

4.5.24init()

NAME
init() — Initialize the array
SYNOPSIS
mdarray &init(); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
mdarray &init( ssize_t sz_type ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
mdarray &init( ssize_t sz_type, const size_t naxisx[], size_t ndim ); . . . . 3

SLLIB Reference: sli::Mdarraymdarray &init( ssize_t sz_type, size_t naxis0 ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
mdarray &init( ssize_t sz_type, size_t naxis0, size_t naxis1 ); . . . . . . . . . . .
mdarray &init( ssize_t sz_type, size_t naxis0, size_t naxis1,
size_t naxis2 ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
mdarray &init( const mdarray &obj ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

81
4
5
6
7

DESCRIPTIONThis member function initializes the array of the object itself.
The member functions 1 and 2 initialize the objects in the Auto matic ResizeMode. The
member functions 3, 4, 5, and 6 initialize the objects in the Manual Resize Mode. The
member function 7 copies all the contents and attributes of obj to the object itself.
The member function 1 initializes the object with the array size 0 and does not change thedata type.
For the member function 2, the data type of the array is specified by sz type.
For the member function 3, the data type of the array is specified by sz type and the numberof dimensions is specified by ndim and the number of elements in each dimension is specified
by naxisx[].
For creating the object with a one-dimension array by the member function 4, the data typeof the array is specified by sz type and the number of elements in the first dimension is
specified by naxis0.
For creating the object with a two-dimension array by the member function 5, the data
type of the array is specified by sz type and the number of elements in the first dimension
is specified by naxis0 and the number of elements in the second dimension is specified bynaxis1.
For creating the object with a three-dimension array by the member function 5, the data
type of the array is specified by sz type and the number of elements in the first dimension
is specified by naxis0 and the number of elements in the second dimension is specified bynaxis1 and the number of elements in the third dimension is specified by naxis2.
See Table 4 for the values that are passed to the argument sz type.
PARAMETER[I] sz_type[I] ndim[I] naxisx[][I] naxis0[I] naxis1[I] naxis2[I] obj

A type specifier for each element of the array
Number of dimensions of the array
Number of elements along each dimension
Number of elements along the first dimension being designated as 0
Number of elements along the second dimension being designated as 1
Number of elements along the third dimension being designated as 2
A reference to an input array whose contents should be copied to thisobject([I] : input, [O] : output)

RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer, or it detects memory
corruption.
EXAMPLEThe following code initializes the object my mdarr with the 2×3 integer array and prints thelengths of dimensions to stdout:

82

SLLIB Reference: sli::Mdarray
stdstreamio sio;mdarray my_mdarr;
my_mdarr.init(INT_ZT, 2,3);
sio.printf("*** my_mdarr 0 dim length ====> [%zu] *** \n",my_mdarr.length(0));
sio.printf("*** my_mdarr 1st dim length ====> [%zu] *** \n",my_mdarr.length(1));
Output:*** my_mdarr 0 dim length ====> [2] ****** my_mdarr 1st dim length ====> [3] ***4.5.25assign()NAME
assign() — Substitute a value for an element(high level)
SYNOPSIS
mdarray &assign( double value, ssize_t idx0,
ssize_t idx1 = MDARRAY_INDEF, ssize_t idx2 = MDARRAY_INDEF );DESCRIPTIONThis member function assigns a value to the element specified by idxn in the array of theobject itself. When a floating-point number is assigned to an element with the data type
integer, it is truncated by default. To round it, call set rounding() in advance. For more
information about set rounding(), see §4.5.15.
In the Automatic Resize Mode, the size of the arrays are resized according to the specified
element index automatically.
In the Manual Resize Mode, assigning a value to an element beyond the array size does notcause any error. The operation is ignored. In order to assign a value to an element beyond
the array size, the array size has to be extended by the member function resize() in advance.
For more information about resize(), see §4.5.33.
Do not specify MDARRAY INDEF for an argument explicitly.
PARAMETER[I] value A real scalar in double precision[I] idx0
Subscript for the first dimension being designated as 0
[I] idx1
Subscript for the second dimension being designated as 1 (optional)[I] idx2
Subscript for the third dimension being designated as 2 (optional)([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer in the Automatic
Resize Mode.
EXAMPLEThe following code sets the value to the element specified by index 1 in the object my mdarr
with the float array and prints the values of elements to stdout:

SLLIB Reference: sli::Mdarray83

stdstreamio sio;mdarray my_mdarr(FLOAT_ZT);
my_mdarr.assign(200.0, 1);for ( size_t i = 0 ; i < my_mdarr.length() ; i++ ) {sio.printf("my_mdarr lvalue[%zu]... [%ld]\n", i, my_mdarr.lvalue(i));}
Output:my mdarr lvalue[0]...
my mdarr lvalue[1]...

4.5.26

[0]
[200]

put()

NAME
put() — Set a value to an arbitrary element’s pointSYNOPSIS
mdarray_type &put( type value, ssize_t idx, size_t len ); . . . . . . . . . . . . . . . . . . 1
mdarray_type &put( type value,
size_t dim_index, ssize_t idx, size_t len ); . . . . . . . . . . . 2
DESCRIPTIONThis member function puts len straight value(s) pointed by the address value ptr to thearray at the element index idx in the object itself. The element index and the dimension
index start from 0.
Any values can be set to idx and len. In the Automatic Resize Mode, if the length of thearray in the object is lower than the specified argument, the array is resized automatically.
The additional part in which the value is not set is filled with the default value. In the
Automatic Resize Mode, the writing operation is not executed for the elements beyond thearray size.
The member function 1 writes one value pointed by the address value ptr to elements lentimes in a row from idx in the array.
The member function 2 writes one value by the address value ptr to elements len times in a
row from idx in the dimension index dim index of the arrays in the object. When dim index
is 1 or over, values are written to all elements in the lower dimensions.
PARAMETER[I] value_ptr A pointer to a scalar[I] idx
Subscript for the first element of a subarray to which the scalar is written[I] len
Number of entries to which the scalar is written[I] dim_index An integer number specifying one of the dimensions of the array([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer in the Automatic
Resize Mode, or it detects memory corruption.

84

SLLIB Reference: sli::Mdarray

EXAMPLEThe following code puts two values to the array elements starting with index 1 in the object
my smdarr with a one-dimension array and prints the values of elements to stdout:
stdstreamio sio;short s12 = 12;
const void *ptr_s12 = (const void *)&s12;
mdarray my_smdarr(SHORT_ZT, 3);
my_smdarr.put(ptr_s12, 1,2);
for ( size_t i = 0 ; i < my_smdarr.length() ; i++ ) {sio.printf("my_smdarr value[%zu]... [%hd]\n", i, my_smdarr.s(i));}
Output:my smdarr value[0]...
my smdarr value[1]...
my smdarr value[2]...
4.5.27

[0]
[12]
[12]

swap()NAME
swap() — Replace values between elements
SYNOPSIS
mdarray &swap( ssize_t idx_src, size_t len, ssize_t idx_dst );mdarray &swap( size_t dim_index,
ssize_t idx_src, size_t len, ssize_t idx_dst );............ 1............ 2

DESCRIPTIONThis member function swaps values in the array of the object itself.
The member function 1 swaps len elements from the index idx src for len elements fromthe index idx dst. If idx dst + len exceeds the size of the array, the process is executedfor up to the size of the array.
The member function 2 swaps len elements from the index idx src in the dimension with
the index dim index for len elements from the index idx dst. If idx dst + len exceeds
the size of the array, the process is executed for up to the size of the array.
When the area for swapping is overlapped, only the non-overlapped area in the source area
is swapped.
PARAMETER[I] idx_src

Subscript specifying the first element of one of the two subarrays to be
swapped with each other[I] len
Number of elements in the subarray[I] idx_dst
Subscript specifying the first element of the other subarray[I] dim_index The integer number that specifies one of the dimensions of the array([I] : input, [O] : output)

RETURN VALUE
A reference to itself

SLLIB Reference: sli::Mdarray

85

EXAMPLEThe following code swaps one element specified by index 0 in the second dimension (dimension
index: 1) for the element with the index 1 in the object my cmdarr with the unsigned chararray and prints the values of elements to stdout. For more information about putdata(),see §4.5.22.
stdstreamio sio;mdarray my_cmdarr(UCHAR_ZT, 2, 2);
unsigned char my_char[] = {51, 52, 101, 102};
my_cmdarr.putdata((const void *)my_char, sizeof(my_char));my_cmdarr.swap( 1, 0, 1, 1 );for ( size_t j = 0 ; j < my_cmdarr.length(1) ; j++ ) {for ( size_t i = 0 ; i < my_cmdarr.length(0) ; i++ ) {sio.printf("my_cmdarr value(%zu,%zu)... [%hhu]\n",i, j, my_cmdarr.c(i, j));}}Output:my cmdarr value(0,0)...
my cmdarr value(1,0)...
my cmdarr value(0,1)...
my cmdarr value(1,1)...

4.5.28

[101]
[102]
[51]
[52]

move()

NAME
move() — Copy values between elements
SYNOPSIS
mdarray &move( ssize_t idx_src, size_t len, ssize_t idx_dst,
bool clr ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
mdarray &move( size_t dim_index, ssize_t idx_src, size_t len, ssize_t idx_dst,
bool clr ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
DESCRIPTIONThis member function moves values in the array of the object itself.
When false is passed to the argument clr, the values of the source remain. For true, thevalues of the source do not remain and they are filled with the default values. If the value
exceeding the existing array size is specified to the argument idx dst, the size is not changed.
This operation is different from that of the member function cpy(). (See §4.5.29.)
For the member function 1, the moving operation is always applied to the elements in thefirst dimension (dimension index: 0). For the member function 2, the moving operation isapplied to the elements in the dimension with the index dim index.
PARAMETER86

SLLIB Reference: sli::Mdarray
[I]
[I]
[I]

idx_srclen
idx_dstSubscript specifying the first element of an input subarray in this object
Number of elements in the input subarray
Subscript specifying the first element of another subarray to which the
input subarray is written[I] clr
True if the contents of the input subarray may be lost[I] dim_index The integer number that specifies one of the dimensions of the array([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXAMPLEThe following code copies values inside the array of the object my cmdarr with the unsigned
char array and prints the values of elements to stdout for confirmation. The values of thesource are cleared.
stdstreamio sio;mdarray my_cmdarr(UCHAR_ZT, 3);
my_cmdarr.c(0) = 99;
my_cmdarr.c(1) = 98;
my_cmdarr.c(2) = 97;
my_cmdarr.move( 2, 1, 0, true );for ( size_t i = 0 ; i < my_cmdarr.length() ; i++ ) {sio.printf("my_cmdarr value[%zu]... [%hhu]\n",i, my_cmdarr.c(i));}
Output:my cmdarr value[0]...
my cmdarr value[1]...
my cmdarr value[2]...

4.5.29

[97]
[98]
[0]

cpy()

NAME
cpy() — Copy values between elements (with automatic expansion)SYNOPSIS
mdarray &cpy( ssize_t idx_src, size_t len, ssize_t idx_dst,
bool clr ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
mdarray &cpy( size_t dim_index, ssize_t idx_src, size_t len, ssize_t idx_dst,
bool clr ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
DESCRIPTIONThis member function moves values in the array of the object itself.
When false is passed to the argument clr, the values of the source remain. For true, thevalues of the source do not remain and they are filled with the default values. If the value
exceeding the existing array size is specified to the argument idx dst, the size is not changed.
This operation is different from that of the member function cpy(). (See §4.5.29.)

SLLIB Reference: sli::Mdarray

87

For the member function 1, the moving operation is always applied to the elements in thefirst dimension (dimension index: 0). For the member function 2, the moving operation isapplied to the elements in the dimension with the index dim index.
PARAMETER[I] idx_src[I] len[I] idx_dst

Subscript specifying the first element of an input subarray in this object
Number of elements in the input subarray
Subscript specifying the first element of another subarray to which the
input subarray is written[I] clr
True if the contents of the input subarray may be lost[I] dim_index The integer number that specifies one of the dimensions of the array([I] : input, [O] : output)

RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer.
EXAMPLEThe following code copies values inside the array of the object my lmdarr with the long longarray and prints the values of elements to stdout for confirmation. The values of the source
remain.
stdstreamio sio;mdarray my_lmdarr(LLONG_ZT);
my_lmdarr.ll(0) = -2147483646;
my_lmdarr.ll(1) = 2147483647;
my_lmdarr.cpy(1, 1, 2, false);for ( size_t i = 0 ; i < my_lmdarr.length(0) ; i++ ) {sio.printf("my_lmdarr value[%zu]... [%lld]\n", i, my_lmdarr.ll(i));}
Output:my lmdarr value[0]...
my lmdarr value[1]...
my lmdarr value[2]...

4.5.30[-2147483646][2147483647][2147483647]

insert()NAME
insert() — Insert an element
SYNOPSIS
mdarray &insert( ssize_t idx, size_t len ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
mdarray &insert( size_t dim_index, ssize_t idx, size_t len ); . . . . . . . . . . . . . 2
DESCRIPTIONThis member function inserts len values to the index idx in the array of the object itself.
The values are default values.

88

SLLIB Reference: sli::Mdarray
For the member function 1, the insertion is always applied to the elements in the first dimension (dimension index: 0). For the member function 2, the insertion is applied to theelements in the dimension with the index dim index.

PARAMETER[I] idx

Array subscript specifying an element before which new entries should be
inserted[I] len
Number of elements to be inserted[I] dim_index The integer number that specifies one of the dimensions of the array([I] : input, [O] : output)

RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer.
EXAMPLEThe following code inserts two default values (0) before the first element in the long array ofthe object my mdarr and prints the result to stdout for confirmation:
stdstreamio sio;mdarray my_mdarr(LONG_ZT, 2);
my_mdarr.l(0) = -2147483646;
my_mdarr.l(1) = 2147483647;
my_mdarr.insert( 1, 2 );for ( size_t i = 0 ; i < my_mdarr.length(0) ; i++ ) {sio.printf("my_mdarr value[%zu]... [%ld]\n", i,my_mdarr.l(i));}
Output:my mdarr value[0]...
my mdarr value[1]...
my mdarr value[2]...
my mdarr value[3]...
4.5.31[-2147483646][0][0][2147483647]

crop()

NAME
crop() — Extract an element
SYNOPSIS
mdarray &crop( ssize_t idx, size_t len ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
mdarray &crop( size_t dim_index, ssize_t idx, size_t len ); . . . . . . . . . . . . . . . 2
DESCRIPTIONThis member function extracts len values from the index idx in the array of the object itself.
For the member function 1, the extraction is always applied to the elements in the first
dimension (dimension index: 0). For the member function 2, the extraction is applied to theelements in the dimension with the index dim index.

SLLIB Reference: sli::Mdarray

89

PARAMETER[I] idx
Array subscript specifying the first element to be extracted[I] len
Number of elements to be extracted[I] dim_index The integer number that specifies one of the dimensions of the array([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer.
EXAMPLEThe following code extracts one-dimension elements specified by index 1 in the first dimension(dimension index: 0) from the object my cmdarr with the unsigned char array and prints thevalues of elements to stdout for confirmation:
stdstreamio sio;mdarray my_cmdarr(UCHAR_ZT, 2, 3);
my_cmdarr.c(0,0) = 124;
my_cmdarr.c(1,0) = 125;
my_cmdarr.c(0,1) = 126;
my_cmdarr.c(1,1) = 127;
my_cmdarr.crop( 0, 1, 1 );for ( size_t j = 0 ; j < my_cmdarr.length(1) ; j++ ) {for ( size_t i = 0 ; i < my_cmdarr.length(0) ; i++ ) {sio.printf("my_cmdarr value(%zu, %zu)... [%hhu]\n",i, j, my_cmdarr.c(i, j));}}Output:my cmdarr value(0, 0)...
my cmdarr value(0, 1)...
my cmdarr value(0, 2)...
4.5.32

[125]
[127]
[0]

erase()

NAME
erase() — Erase an element
SYNOPSIS
mdarray &erase( ssize_t idx, size_t len ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
mdarray &erase( size_t dim_index, ssize_t idx, size_t len ); . . . . . . . . . . . . . . 2
DESCRIPTIONThis member function erases the specified elements from the array of the object itself. The
length of the array is reduced by len.
For the member function 1, the erasing operation is always applied to the elements in thefirst dimension (dimension index: 0). For the member function 2, the erasing operation isapplied to the elements in the dimension with the index dim index.

90

SLLIB Reference: sli::Mdarray

PARAMETER[I] idx
Array subscript specifying the first element to be removed[I] len
Number of elements to be removed[I] dim_index The integer number that specifies one of the dimensions of the array([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer.
EXAMPLEThe following code erases one element specified by index 1 in the object my mdarr with a
one-dimension array and prints the values of elements to stdout:
stdstreamio sio;mdarray my_mdarr(LLONG_ZT, 3);
my_mdarr.ll(0) = 0;
my_mdarr.ll(1) = 2147483646;
my_mdarr.ll(2) = 2147483647;
my_mdarr.erase( 1, 1 );for ( size_t i = 0 ; i < my_mdarr.length() ; i++ ) {sio.printf("my_mdarr value[%zu]... [%lld]\n", i, my_mdarr.ll(i));}
Output:my mdarr value[0]...
my mdarr value[1]...

4.5.33[0][2147483647]

resize()NAME
resize() — Change the length of the array
SYNOPSIS
mdarray_type &resize( size_t len ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
mdarray_type &resize( size_t dim_index, size_t len ); . . . . . . . . . . . . . . . . . . . . . . . 2
mdarray_type &resize( const mdarray &src ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
DESCRIPTIONThis member function resizes the length of the array in the object itself.
For extension, new values of the elements are filled with the default values. For reduction,
elements after the index len are removed.
For the member function 1, the resizing operation is always applied to the elements in thefirst dimension (dimension index: 0). For the member function 2, the resizing operation isapplied to the elements in the dimension with the index dim index. For the member function
3, the number of dimensions and the length of the array are conformed to that of the object
src.

SLLIB Reference: sli::Mdarray

91

PARAMETER[I] len
Number of elements after being resized[I] dim_index The integer number that specifies one of the dimensions of the array([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer.
EXAMPLEThe following code resizes the length of the array for the second dimension (dimension index:
1) in the object my cmdarr with a two-dimension array to 3 and prints the result to stdout
for confirmation:
stdstreamio sio;mdarray my_cmdarr(UCHAR_ZT, 2, 2);
my_cmdarr.c(0,0) = 70;
my_cmdarr.c(1,0) = 71;
my_cmdarr.c(0,1) = 36;
my_cmdarr.c(1,1) = 37;
my_cmdarr.resize( 1, 3 );for ( size_t j = 0 ; j < my_cmdarr.length(1) ; j++ ) {for ( size_t i = 0 ; i < my_cmdarr.length(0) ; i++ ) {sio.printf("my_cmdarr value(%zu, %zu)... [%hhu]\n",i, j, my_cmdarr.c(i, j));}}Output:my cmdarr value(0, 0)...
my cmdarr value(1, 0)...
my cmdarr value(0, 1)...
my cmdarr value(1, 1)...
my cmdarr value(0, 2)...
my cmdarr value(1, 2)...

4.5.34

[70]
[71]
[36]
[37]
[0]
[0]

resizeby()

NAME
resizeby() — Change the length of the array relatively
SYNOPSIS
mdarray_type &resizeby( ssize_t len ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
mdarray_type &resizeby( size_t dim_index, ssize_t len ); . . . . . . . . . . . . . . . . . . . 2
DESCRIPTIONThis member function resizes the length of the array in the object itself by len.

92

SLLIB Reference: sli::Mdarray
For reduction, a negative value is passed to the argument len. The size of the resized arrayis the original size plus len.
For the member function 1, the resizing operation is always applied to the elements in thefirst dimension (dimension index: 0). For the member function 2, the resizing operation isapplied to the elements in the dimension with the index dim index.

PARAMETER[I] len
Number of elements to be increased or decreased[I] dim_index The integer number that specifies one of the dimensions of the array([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer.
EXAMPLEThe following code resizes the length of the array in the object my cmdarr with a onedimension array and prints the values to stdout for confirmation:
stdstreamio sio;mdarray my_cmdarr(UCHAR_ZT, 3);
my_cmdarr.resizeby( -2 );for ( size_t i = 0 ; i < my_cmdarr.length(0) ; i++ ) {sio.printf("my_cmdarr value[%d]... [%hhu]\n", i, my_cmdarr.c(i));}
Output:my cmdarr value[0]...
4.5.35[0]increase dim()

NAME
increase dim() — Expand the number of dimensions
SYNOPSIS
mdarray_type &increase_dim();DESCRIPTIONThis member function increments the dimension of the array in the object itself.
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer.
EXAMPLEThe following code increments the dimension of the array in the object my mdarr with athree-dimension array and prints the number of dimensions to stdout:

SLLIB Reference: sli::Mdarray93

stdstreamio sio;mdarray my_mdarr(UCHAR_ZT, 1, 2, 3);
my_mdarr.increase_dim();sio.printf("my_mdarr dim... [%zu]\n",
Output:my mdarr dim...

4.5.36

my_mdarr.dim_length());[4]

decrease dim()NAME
decrease dim() — Reduce the number of dimensions
SYNOPSIS
mdarray_type &decrease_dim();DESCRIPTIONThis member function decrements the dimension of the array in the object itself.
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer, or it detects memory
corruption.
EXAMPLEThe following code decrements the dimension of the array in the object my mdarr with athree-dimension array and prints the number of dimensions to stdout:
stdstreamio sio;mdarray my_mdarr(UCHAR_ZT, 1, 2, 3);
my_mdarr.decrease_dim();sio.printf("my_mdarr dim... [%zu]\n",
Output:my mdarr dim...

4.5.37

my_mdarr.dim_length());[2]swap()NAME
swap() — Replace the object by another one
SYNOPSIS
mdarray_type &swap( mdarray_type &sobj );DESCRIPTIONThis member function swaps the specified object sobj for the object itself. All attributes
such as the size of arrays are exchanged.

94

SLLIB Reference: sli::Mdarray

PARAMETER[I/O] sobj Object belonging to the same class as this instance([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXAMPLEThe following code swaps the object my fmdarr with a one-dimension array for the object
swap mdarr and prints the values of elements in the my fmdarr to stdout:
stdstreamio sio;mdarray my_fmdarr(FLOAT_ZT, 2);
my_fmdarr.f(0) = 1000;
my_fmdarr.f(1) = 2000;
mdarray swap_mdarr(DOUBLE_ZT, 2);
swap_mdarr.d(0) = 100;swap_mdarr.d(1) = 200;
my_fmdarr.swap(swap_mdarr);for ( size_t i = 0 ; i < my_fmdarr.length(0) ; i++ ) {sio.printf("my_fmdarr value[%zu]... [%g]\n", i,my_fmdarr.dvalue(i));}
output:my fmdarr value[0]...
my fmdarr value[1]...
4.5.38

[100]
[200]

convert()NAME
convert() — Convert the type of the array
SYNOPSIS
mdarray &convert( ssize_t sz_type ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
mdarray &convert( ssize_t sz_type, void (*func)(const void *,void *,void *),void *user_ptr ); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
DESCRIPTIONThis member function converts the data type of the array in the object itself into the data
type specified by sz type. Underflow or overflow occurs depending on the combination of
the source data type and the destination data type.
For the member function 2, the behavior of converting is customizable by a user-defined
function. The first argument of the user-defined function is the address of the original
element in the array, the second is the address of the converted element, and the third isuser ptr.
PARAMETER[I] func
Address of user-defined function[I] user_ptr The pointer that is given to the above function as its last argument([I] : input, [O] : output)

SLLIB Reference: sli::Mdarray

95

RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer.
EXAMPLEThe following code converts the data type of the object my fmdarr with a one-dimension arrayfrom floating-point into integer and prints the values of elements to stdout for confirmation.
stdstreamio sio;mdarray my_fmdarr(FLOAT_ZT);
my_fmdarr.f(0) = 1000.1;
my_fmdarr.f(1) = -2000.6;
my_fmdarr.convert(INT_ZT);
for ( size_t i = 0 ; i < my_fmdarr.length() ; i++ ) {sio.printf("my_fmdarr value[%zu]... [%d]\n", i, my_fmdarr.i(i));}
output:my fmdarr value[0]...
my fmdarr value[1]...
4.5.39[1000][-2000]ceil()

NAME
ceil() — Raise decimals to the next whole number in a double type value
SYNOPSIS
mdarray_type &ceil();
DESCRIPTIONThis member function rounds up all elements (floating-point number) of the array in theobject itself to the nearest integer.
RETURN VALUE
A reference to itself
EXAMPLEThe following code sets the values with decimal places to the object my fmdarr with a onedimension array and rounds them up, and prints the values of elements to stdout for confirmation:
stdstreamio sio;mdarray my_fmdarr(FLOAT_ZT);
my_fmdarr.f(0) = 1000.1;
my_fmdarr.f(1) = 2000.6;
my_fmdarr.ceil();

96

SLLIB Reference: sli::Mdarrayfor ( size_t i = 0 ; i < my_fmdarr.length() ; i++ ) {sio.printf("my_fmdarr value[%zu]... [%f]\n", i, my_fmdarr.f(i));}
Output:my fmdarr value[0]...
my fmdarr value[1]...
4.5.40[1001.000000][2001.000000]

floor()

NAME
floor() — Devalue decimals in a double type value
SYNOPSIS
mdarray_type &floor();DESCRIPTIONThis member function rounds down all elements (floating-point number) of the array in theobject itself to the nearest integer.
RETURN VALUE
A reference to itself
EXAMPLEThe following code sets the values with decimal places to the object my fmdarr with a onedimension array and rounds them down, and prints the values of elements to stdout for
confirmation:
stdstreamio sio;mdarray my_fmdarr(FLOAT_ZT);
my_fmdarr.f(0) = 1000.1;
my_fmdarr.f(1) = 2000.9;
my_fmdarr.floor();for ( size_t i = 0 ; i < my_fmdarr.length(0) ; i++ ) {sio.printf("my_fmdarr value[%zu]... [%f]\n", i, my_fmdarr.f(i));}
Output:my fmdarr value[0]...
my fmdarr value[1]...
4.5.41[1000.000000][2000.000000]

round()

NAME
round() — Round off decimals in a double type value
SYNOPSIS
mdarray_type &round();SLLIB Reference: sli::Mdarray

97

DESCRIPTIONThis member function rounds all elements (floating-point number) of the array in the object
itself to the nearest integer.
RETURN VALUE
A reference to itself
EXAMPLEThe following code sets the values with decimal places to the object mdarrf with a onedimension array and rounds them to the nearest integer, and prints the values of elements
to stdout for confirmation:
stdstreamio sio;mdarray my_fmdarr(FLOAT_ZT);
my_fmdarr.f(0) = 1000.5;
my_fmdarr.f(1) = -1000.5;
my_fmdarr.round();for ( size_t i = 0 ; i < my_fmdarr.length(0) ; i++ ) {sio.printf("my_fmdarr value[%zu]... [%f]\n", i, my_fmdarr.f(i));}
output:my fmdarr value[0]...
my fmdarr value[1]...
4.5.42[1001.000000][-1001.000000]

trunc()

NAME
trunc() — Omit decimals in a double type value
SYNOPSIS
mdarray_type &trunc();
DESCRIPTIONThis member function rounds down all elements (floating-point number) of the array in theobject itself to the integer which is closer to 0 than the element.
RETURN VALUE
A reference to itself
EXAMPLEThe following code sets the values with decimal places to the object my fmdarr with a onedimension array and rounds them down to the integers which are closer to 0 than the elements,
and prints the values of elements to stdout for confirmation:
stdstreamio sio;mdarray my_fmdarr(FLOAT_ZT);
my_fmdarr.f(0) = 1.7;
my_fmdarr.f(1) = -1.7;

98

SLLIB Reference: sli::Mdarraymy_fmdarr.trunc();for ( size_t i = 0 ; i < my_fmdarr.length() ; i++ ) {sio.printf("my_fmdarr value[%zu]... [%f]\n", i, my_fmdarr.f(i));}
Output:my fmdarr value[0]...
my fmdarr value[1]...

4.5.43[1.000000][-1.000000]

abs()

NAME
abs() — Absolute value of all elements
SYNOPSIS
mdarray_type &abs();
DESCRIPTIONThis member function returns the absolute values of all elements of the array in the object
itself.
RETURN VALUE
A reference to itself
EXAMPLEThe following code sets negative values to the elements of the object my fmdarr with a
one-dimension array and prints the absolute values of elements to stdout:
stdstreamio sio;mdarray my_fmdarr(FLOAT_ZT);
my_fmdarr.f(0) = -1000.1;
my_fmdarr.f(1) = -2000.6;
my_fmdarr.abs();for ( size_t i = 0 ; i < my_fmdarr.length(0) ; i++ ) {sio.printf("my_fmdarr value[%zu]... [%5.1f]\n", i, my_fmdarr.f(i));}
Output:my fmdarr value[0]...
my fmdarr value[1]...
4.5.44[1000.1][2000.6]

compare()NAME
compare() — Compare array objects
SYNOPSIS
bool compare(const mdarray &obj) const;

SLLIB Reference: sli::Mdarray

99

DESCRIPTIONThis member function compares the array of the object itself with that of the specified object
obj.
Even when the data types are not identical, this member function returns true (=1) if thelength and values of the array are identical. If not, it returns false (=0).
PARAMETER[I] obj Object belonging to the class “mdarray”([I] : input, [O] : output)
RETURN VALUE
true : If the sizes and values of the elements on the arrays are identicalfalse : If the sizes and one of the values of the elements on the arrays are not identical
EXAMPLEThe following code compares the object my fmdarr with a two-dimension array with theobject my i64mdarr with a two-dimension array and prints the result to stdout:
stdstreamio sio;mdarray my_fmdarr(FLOAT_ZT, 2,2);
my_fmdarr.f(0,0) = 1000;
mdarray my_i64mdarr(INT64_ZT, 2,2);
my_i64mdarr.i64(0,0) = 1000;
sio.printf("*** my_fmdarr compare [%d] *** \n",(int)my_fmdarr.compare(my_i64mdarr));
output:*** my_fmdarr compare [1] ***4.5.45copy()NAME
copy() — Copy a part of an array into another object (for image data)
SYNOPSIS
ssize_t copy( mdarray *dest ) const;
ssize_t copy( mdarray &dest ) const;
DESCRIPTIONThis member function copies all the contents of the object itself to the specified object dest.
All attributes such as the data type, the length, and values of the source array are copied
to the destination array. This member function does not affect the array of the object itself(source).
PARAMETER[O] dest

an object in the class “mdarray” to which the whole contents of this array is
written([I] : input, [O] : output)

100

SLLIB Reference: sli::Mdarray

RETURN VALUE
The number of copied elements (column × row × layer)
EXCEPTION
The function throws an exception when it fails to allocate a buffer, or it detects memory
corruption.
EXAMPLEThe following code copies the object my cmdarr with a two-dimension array to the object
my fmdarr and prints the values of elements to stdout for confirmation:
stdstreamio sio;mdarray my_fmdarr(FLOAT_ZT);
mdarray my_cmdarr(UCHAR_ZT, 2, 2);
unsigned char my_char[] = {99, 101, 98, 102};
my_cmdarr.putdata((const void *)my_char, sizeof(my_char));ssize_t copy_size = my_cmdarr.copy( my_fmdarr );for ( size_t j = 0 ; j < my_fmdarr.length(1) ; j++ ) {for ( size_t i = 0 ; i < my_fmdarr.length(0) ; i++ ) {sio.printf("my_fmdarr value(%zu,%zu)... [%hhu]\n",i, j, my_fmdarr.c(i, j));}}Output:my fmdarr value(0,0)...
my fmdarr value(1,0)...
my fmdarr value(0,1)...
my fmdarr value(1,1)...

4.5.46

[98]
[99]
[101]
[102]

copy()NAME
copy() — Copy a part of an array into another object (for image data)
SYNOPSIS
ssize_t copy( mdarray *dest,
ssize_t col_idx, size_t col_len=MDARRAY_ALL,
ssize_t row_idx=0, size_t row_len=MDARRAY_ALL,
ssize_t layer_idx=0, size_t layer_len=MDARRAY_ALL ) const;
ssize_t copy( mdarray &dest,
ssize_t col_idx, size_t col_len=MDARRAY_ALL,
ssize_t row_idx=0, size_t row_len=MDARRAY_ALL,
ssize_t layer_idx=0, size_t layer_len=MDARRAY_ALL ) const;
DESCRIPTIONThis member function is for image data and copies a part of contents of the object itself tothe specified object dest.

SLLIB Reference: sli::Mdarray

101

The element values and the data types of the source arrays are copied to the destinationarrays. This member function does not affect the array of the object itself (source).
Image data is copied by copy() as shown below:
layer_len .
(col_idx,row_idx)

...

dest
col_lencopy

row_lenlayer_idx.
...

The shaded area in the figure is specified by the second or higher arguments, and it is copied
to the dest.
Do not specify MDARRAY ALL for an argument explicitly.
PARAMETER[O] dest

An instance of the class “mdarray type” to which a subarray of thisobject should be written[I]
col_idx
Subscript specifying the first column of the subarray[I]
col_len
Number of columns in the subarray[I]
row_idx
Subscript specifying the first row of the subarray[I]
row_len
Number of rows in the subarray[I]layer_idx Subscript specifying the first layer of the subarray[I]layer_len Number of layers in the subarray([I] : input, [O] : output)

RETURN VALUE
The number of copied elements (column × row × layer)
EXCEPTION
The function throws an exception when it fails to allocate a local buffer, or it detects memory
corruption.
EXAMPLEThe following code copies the object my cmdarr with a two-dimension array to the object
my fmdarr and prints the values of elements to stdout for confirmation. For more information
about putdata(), see §4.5.22.
stdstreamio sio;mdarray my_cmdarr(UCHAR_ZT, 2,2);
unsigned char my_char[] = {98, 99, 101, 102};
my_cmdarr.putdata((const void *)my_char, sizeof(my_char));mdarray my_dmdarr(DOUBLE_ZT ,2,2);
double my_d[] = {-501, 501, -502, 502};
my_dmdarr.putdata((const void *)my_d, sizeof(my_d));ssize_t ret_size = my_cmdarr.copy( my_dmdarr, 1, 1, 1, 1 );for ( size_t j = 0 ; j < my_dmdarr.length(1) ; j++ ) {102

SLLIB Reference: sli::Mdarrayfor ( size_t i = 0 ; i < my_dmdarr.length(0) ; i++ ) {/* The data type of my_dmdarr is changed into *//* unsigned char by copy. */sio.printf("my_dmdarr value(%zu,%zu)... [%hhu]\n",i, j, my_dmdarr.c(i, j));}}Output:my ldmdarr value(0,0)...

4.5.47

[102]

cut()

NAME
cut() — Cut all values in an array and copy them into another object
SYNOPSIS
mdarray_type &cut( mdarray_type *dest );mdarray_type &cut( mdarray_type &dest );DESCRIPTIONThis member function cuts all contents of the array of the object itself and copies it to thespecified object dest.
Since all contents of the array of the object itself are cut, the length of the array (source) is
set to 0.
PARAMETER[O] dest The object to which this array is written([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a buffer, or it detects memory
corruption.
EXAMPLEThe following code cuts the object my cmdarr with a two-dimension array and copies itto the object my mdarr, and prints the length of the array of the my cmdarr to stdout for
confirmation. For more information about putdata(), see §4.5.22.
stdstreamio sio;mdarray my_mdarr;
mdarray my_cmdarr(UCHAR_ZT, 2, 2);
unsigned char my_char[] = {51, 101, 52, 102};
my_cmdarr.putdata((const void *)my_char, sizeof(my_char));my_cmdarr.cut( my_mdarr );sio.printf("my_cmdarr length()... [%zu]\n", my_cmdarr.length());

SLLIB Reference: sli::Mdarray
Output:my cmdarr length()...
4.5.48

103

[0]

cut()

NAME
cut() — Cut a part of values in an array and copy them into another object (for image data)
SYNOPSIS
mdarray &cut( mdarray *dest,
ssize_t col_idx, size_t col_len=MDARRAY_ALL,
ssize_t row_idx=0, size_t row_len=MDARRAY_ALL,
ssize_t layer_idx=0, size_t layer_len=MDARRAY_ALL );mdarray &cut( mdarray &dest,
ssize_t col_idx, size_t col_len=MDARRAY_ALL,
ssize_t row_idx=0, size_t row_len=MDARRAY_ALL,
ssize_t layer_idx=0, size_t layer_len=MDARRAY_ALL );DESCRIPTIONThis member function is for image data and cuts a part of contents of the object itself, andcopies it to the specified object dest.
The length of the array of the object itself (source) is not changed and the values of the area
specified by the second or higher arguments are filled with default values.
Do not specify MDARRAY ALL for an argument explicitly.
PARAMETER[O] dest

An instance of the class “mdarray type” to which a subarray of thisobject should be written[I]
col_idx
Subscript specifying the first column of the subarray[I]
col_len
Number of columns in the subarray[I]
row_idx
Subscript specifying the first row of the subarray[I]
row_len
Number of rows in the subarray[I]layer_idx Subscript specifying the first layer of the subarray[I]layer_len Number of layers in the subarray([I] : input, [O] : output)

RETURN VALUE
A reference to itself
EXCEPTION
The function throws an exception when it fails to allocate a local buffer, or it detects memory
corruption.
EXAMPLEThe following code cuts the zeroth column of the object my cmdarr with a two-dimension
array and copies it to the object my mdarr and prints the values of elements to stdout for
confirmation. For more information about putdata(), see §4.5.22.
stdstreamio sio;mdarray my_mdarr;

104

SLLIB Reference: sli::Mdarraymdarray my_cmdarr(UCHAR_ZT, 2, 2);
unsigned char my_char[] = {51, 101, 52, 102};
my_cmdarr.putdata((const void *)my_char, sizeof(my_char));my_cmdarr.cut( my_mdarr, 0, 1 );for ( size_t j = 0 ; j < my_cmdarr.length(1) ; j++ ) {for ( size_t i = 0 ; i < my_cmdarr.length(0) ; i++ ) {sio.printf("my_cmdarr value(%zu,%zu)... [%hhu]\n",i, j, my_cmdarr.c(i, j));}}Output:my cmdarr value(0,0)...
my cmdarr value(1,0)...
my cmdarr value(0,1)...
my cmdarr value(1,1)...

4.5.49

[0]
[101]
[0]
[102]

clean()

NAME
clean() — Padding of existing values in an array by default ones (for image data)
SYNOPSIS
mdarray_type &clean( ssize_t col_index = 0, size_t col_size = MDARRAY_ALL,
ssize_t row_index = 0, size_t row_size = MDARRAY_ALL,
ssize_t layer_index = 0, size_t layer_size = MDARRAY_ALL );DESCRIPTIONThis member function fills the array elements of the object itself with default values. The
arguments are optional. When no argument is specified, the cleaning operation is applied toall elements. The length of the array is not changed by clean().
This member function is for image data.
Do not specify MDARRAY ALL for an argument explicitly.
PARAMETER[I] col_index
Subscript specifying the first column of a subarray in this object[I] col_size
Number of columns of the subarray[I] row_index
Subscript specifying the first row of the subarray[I] row_size
Number of rows of the subarray[I] layer_index Subscript specifying the first layer of the subarray[I] layer_size
Number of layers of the subarray([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXAMPLEThe following code sets values to the elements of the object my smdarr with a two-dimension
array and cleans an element, and prints the values of elements to stdout for confirmation:

SLLIB Reference: sli::Mdarray105

stdstreamio sio;mdarray my_smdarr(SHORT_ZT, 2,2);
my_smdarr.s(0,0) = 1;
my_smdarr.s(1,0) = 3;
my_smdarr.s(0,1) = 2;
my_smdarr.s(1,1) = 4;
my_smdarr.clean(1,1,1,1);for ( size_t j = 0 ; j < my_smdarr.length(1) ; j++ ) {for ( size_t i = 0 ; i < my_smdarr.length(0) ; i++ ) {sio.printf("my_smdarr value(%zu,%zu)... [%hd]\n",i, j, my_smdarr.s(i, j));}}Output:my smdarr value(0,0)...
my smdarr value(1,0)...
my smdarr value(0,1)...
my smdarr value(1,1)...
4.5.50

[1]
[3]
[2]
[0]

fill()

NAME
fill() — Rewrite element values (for image data)
SYNOPSIS
mdarray &fill( double value,
ssize_t col_index = 0, size_t col_size = MDARRAY_ALL,
ssize_t row_index = 0, size_t row_size = MDARRAY_ALL,
ssize_t layer_index = 0, size_t layer_size = MDARRAY_ALL ); . . . . . . . . . . 1
mdarray &fill( double value,
double (*func)(double,double,ssize_t,ssize_t,ssize_t,mdarray *,void *),void *user_ptr,
ssize_t col_index = 0, size_t col_size = MDARRAY_ALL,
ssize_t row_index = 0, size_t row_size = MDARRAY_ALL,
ssize_t layer_index = 0, size_t layer_size = MDARRAY_ALL ); . . . . . . . . . 2
mdarray &fill( double value,
void (*func_dest2d)(const void *,void *,void *), void *user_ptr_dest2d,
void (*func_d2dest)(const void *,void *,void *), void *user_ptr_d2dest,
double (*func)(double,double,ssize_t,ssize_t,ssize_t,mdarray *,void *),void *user_ptr_func,
ssize_t col_index = 0, size_t col_size = MDARRAY_ALL,
ssize_t row_index = 0, size_t row_size = MDARRAY_ALL,
ssize_t layer_index = 0, size_t layer_size = MDARRAY_ALL ); . . . . . . . . . . 3
DESCRIPTIONThis member function rewrites the specified array elements of the object itself as the argument
value (Function 1). This member function rewrites the specified array elements of the object
itself via the user-defined function func (Function 2).

106

SLLIB Reference: sli::Mdarray
The arguments of the user-defined function are, from the left, the value of the object itself,
the value specified by value, the index of a column, the index of a row, the index of a layer,
the address of the object itself, and the user pointer user_ptr, respectively. To find out how
to specify a user-defined function, see EXAMPLE in §4.5.53.
This member function is for image data.
Do not specify MDARRAY ALL for an argument explicitly.

PARAMETER[I] value[I] user_ptr[I]

user_ptr_dest2d[I]user_ptr_d2dest

[I]
[I]
[I]
[I]
[I]
[I]
[I]
[I]

col_index
col_size
row_index
row_sizelayer_index
layer_size
func
func_dest2d[I]

func_d2dest

A real scalar to be written to a subarray of this object
The user’s pointer that is given to the function “func” as its lastargument
The user’s pointer that is given to the function “func dest2d” as
its last argument
The user’s pointer that is given to the function “func d2dest” as
its last argument
Subscript specifying the first column of the subarray
Number of columns of the subarray
Subscript specifying the first row of the subarray
Number of rows of the subarray
Subscript specifying the first layer of the subarray
Number of layers of the subarray
A pointer to the user’s function for data conversion
A pointer to the user’s function that converts raw data stored inthis object to an array of intrinsic real numbers in double precision
A pointer to the user’s function that converts an array of intrinsic
real numbers in double precision to raw data stored in this object.

([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXAMPLEThe following code fills all elements of the object my smdarr with a two-dimension array with
100 and prints the values of elements to stdout for confirmation:
stdstreamio sio;mdarray my_smdarr(SHORT_ZT, 2,2);
my_smdarr.fill(100);for ( size_t j = 0 ; j < my_smdarr.length(1) ; j++ ) {for ( size_t i = 0 ; i < my_smdarr.length(0) ; i++ ) {sio.printf("my_smdarr value(%zu,%zu).. [%hd]\n",i, j, my_smdarr.s(i, j));}}Output:my smdarr value(0,0)..
my smdarr value(1,0)..
my smdarr value(0,1)..
my smdarr value(1,1)..

[100]
[100]
[100]
[100]

SLLIB Reference: sli::Mdarray

4.5.51

107

add()

NAME
add() — Add element values (for image data)
SYNOPSIS
mdarray_type &add( double value,
ssize_t col_index = 0, size_t col_size = MDARRAY_ALL,
ssize_t row_index = 0, size_t row_size = MDARRAY_ALL,
ssize_t layer_index = 0, size_t layer_size = MDARRAY_ALL );DESCRIPTIONThis member function adds the value of the argument value to array elements of the object
itself specified by arguments. This member function is for image data.
The value 137 is added to a part of image data by add() as shown below:
layer_len(col_idx,row_idx).

...

col_lenadd

row_lenvalue=137.

...
layer_idx

The shaded area in the figure is specified by the second or later arguments, and value isadded to the area.
Do not specify MDARRAY ALL for an argument explicitly.
PARAMETER[I] value
A real scalar to be added to a subarray of this object[I] col_index
Subscript specifying the first column of the subarray[I] col_size
Number of columns of the subarray[I] row_index
Subscript specifying the first row of the subarray[I] row_size
Number of rows of the subarray[I] layer_index Subscript specifying the first layer of the subarray[I] layer_size
Number of layers of the subarray([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXAMPLEThe following code adds 10 to the value in the second column and second row of the object my smdarr with a two-dimension array and prints the values of elements to stdout for
confirmation. For more information about putdata(), see §4.5.22.
stdstreamio sio;mdarray my_smdarr(SHORT_ZT, 2,2);
short my_short[] = {1, 2, 3, 4};

108

SLLIB Reference: sli::Mdarraymy_smdarr.putdata((const void *)my_short, sizeof(my_short));my_smdarr.add(10.0, 1,1,1,1);for ( size_t j = 0 ; j < my_smdarr.length(1) ; j++ ) {for ( size_t i = 0 ; i < my_smdarr.length(0) ; i++ ) {sio.printf("my_smdarr value(%zu,%zu)... [%hd]\n",i, j, my_smdarr.s(i, j));}}Output:my smdarr value(0,0)...
my smdarr value(1,0)...
my smdarr value(0,1)...
my smdarr value(1,1)...

4.5.52

[1]
[2]
[3]
[14]

multiply()

NAME
multiply() — Multiply element values (for image data)
SYNOPSIS
mdarray_type &multiply( double value,
ssize_t col_index = 0, size_t col_size = MDARRAY_ALL,
ssize_t row_index = 0, size_t row_size = MDARRAY_ALL,
ssize_t layer_index = 0, size_t layer_size = MDARRAY_ALL );DESCRIPTIONThis member function multiplies the specified array elements of the object itself by the valueof the argument value. This member function is for image data.
Do not specify MDARRAY ALL for an argument explicitly.
PARAMETER[I] value
A real scalar to be multiplied to a subarray of this object[I] col_index
Subscript specifying the first column of the subarray[I] col_size
Number of columns of the subarray[I] row_index
Subscript specifying the first row of the subarray[I] row_size
Number of rows of the subarray[I] layer_index Subscript specifying the first layer of the subarray[I] layer_size
Number of layers of the subarray([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXAMPLEThe following code multiplies all elements of the object my fmdarr with a two-dimension
array by 50 and prints the values of elements to stdout for confirmation:
stdstreamio sio;mdarray my_fmdarr(FLOAT_ZT, 2,2);

SLLIB Reference: sli::Mdarray109

float my_float[] = {1, 3, 2, 4};
my_fmdarr.putdata((const void *)my_float, sizeof(my_float));my_fmdarr.multiply(50);for ( size_t j = 0 ; j < my_fmdarr.length(1) ; j++ ) {for ( size_t i = 0 ; i < my_fmdarr.length(0) ; i++ ) {sio.printf("my_fmdarr value(%zu,%zu)... [%f]\n",i, j, my_fmdarr.f(i, j));}}Output:my fmdarr value(0,0)...
my fmdarr value(1,0)...
my fmdarr value(0,1)...
my fmdarr value(1,1)...

4.5.53[50.000000][150.000000][100.000000][200.000000]

paste()

NAME
paste() — Paste up an array object (for image data)
SYNOPSIS
mdarray &paste( const mdarray &src,
ssize_t dest_col = 0, ssize_t dest_row = 0, ssize_t dest_layer = 0 ); . . . 1
mdarray &paste( const mdarray &src,
double (*func)(double,double,ssize_t,ssize_t,ssize_t,mdarray *,void *),void *user_ptr,
ssize_t dest_col = 0, ssize_t dest_row = 0, ssize_t dest_layer = 0 ); . . . 2
mdarray &paste( const mdarray &src,
void (*func_src2d)(const void *,void *,void *), void *user_ptr_src2d,
void (*func_dest2d)(const void *,void *,void *), void *user_ptr_dest2d,
void (*func_d2dest)(const void *,void *,void *), void *user_ptr_d2dest,
double (*func)(double,double,ssize_t,ssize_t,ssize_t,mdarray *,void *),void *user_ptr,
ssize_t dest_col = 0, ssize_t dest_row = 0, ssize_t dest_layer = 0 ); . . . 3
DESCRIPTIONThis member function pastes the element values specified by src into the specified region of
the array in the object itself (Function 1). These member functions paste the element values
converted via a user-defined function into the specified region of the array in the object itself(Functions 2, 3).
For the member functions 2 and 3, the behaviors of pasting are customizable by a user-defined
function. The arguments of the user-defined function func are, from the left, the value ofthe object itself, the value of the object src, the index of a column, the index of a row, theindex of a layer, the address of the object itself, and the user pointer user_ptr, respectively.
This member function is for image data.
PARAMETER110

SLLIB Reference: sli::Mdarray
[I]
[I]

src
func_src2d[I]

user_ptr_src2d[I]

func_dest2d[I]user_ptr_dest2d[I]

func_d2dest[I]user_ptr_d2dest

[I]

func

[I]
[I]

user_ptr
dest_col[I]

dest_row[I]

dest_layer

A object containing an input array
A pointer to the user’s function that converts raw data in the object “src” to an array of intrinsic real numbers in double precision
The user’s pointer that is given to the function “func src2d” as its
last argument
A pointer to the user’s function that converts raw data in thisobject to an array of intrinsic real numbers in double precision
The user’s pointer that is given to the function “func dest2d” as
its last argument
A pointer to the user’s function that converts an array of intrinsic
real numbers in double precision to raw data stored in this object.
The user’s pointer that is given to the function “func d2dest” as
its last argument
A pointer to the user’s function that defines an operation to be
performed on elements of two input arrays.
The user’s pointer given to the function “func” as its last argument
Subscript specifying the first column of a subarray on which the
input data should be pasted.
Subscript specifying the first row of the subarray on which the
input data should be pasted.
Subscript specifying the first layer of the subarray on which the
input data should be pasted.

([I] : input, [O] : output)
RETURN VALUE
A reference to itself
EXAMPLEThe following code pastes the object mypaste mdarr with a two-dimension array into theobject my fmdarr with a two-dimension array. In pasting, the values of the objects are
summed up and 500 is added to the values via the user-defined function. The values of
elements are printed to stdout for confirmation. For more information about putdata(), see§4.5.22:
double my_func(double self, double src, ssize_t x,
ssize_t y, ssize_t z, mdarray *myptr, void *p){
return self + src + 500;}/* main */stdstreamio sio;mdarray my_fmdarr(FLOAT_ZT, 2,2);
float my_float[] = {100, 0, 200};
my_fmdarr.putdata((const void *)my_float, sizeof(my_float));mdarray mypaste_mdarr(FLOAT_ZT, 2,2);
float mypaste_float[] = {1000, 3000, 2000, 4000};
mypaste_mdarr.putdata((const void *)mypaste_float, sizeof(mypaste_float));SLLIB Reference: sli::Mdarray111

my_fmdarr.paste(mypaste_mdarr, &my_func, NULL);
for ( size_t j = 0 ; j < my_fmdarr.length(1) ; j++ ) {for ( size_t i = 0 ; i < my_fmdarr.length(0) ; i++ ) {sio.printf("my_fmdarr value[%zu][%zu]... [%f]\n", i, j,
my_fmdarr.f(i, j));}}Output:my fmdarr value(0,0)...
my fmdarr value(1,0)...
my fmdarr value(0,1)...
my fmdarr value(1,1)...

4.5.54[1600.000000][2500.000000][3700.000000][4500.000000]

add()

NAME
add() — Add an array object (for image data)
SYNOPSIS
mdarray &add( const mdarray &src_img, ssize_t dest_col = 0,
ssize_t dest_row = 0, ssize_t dest_layer = 0 );DESCRIPTIONThis member function adds array elements of the object src img to those of the object itself.
A start position for addition can be specified separately for columns, rows, and layers. Thismember function is for image data.
Image data is added to the elements of the object itself by add() as shown below:(0,0)

dest_coldest_row

src_img

The shaded area in the figure is specified by the second or later arguments, and src img isadded to the area.
PARAMETER[I] src_img

An instance of the class “mdarray” to be added to a subarray of thisobject[I] dest_col
Subscript specifying the first column of the subarray[I] dest_row
Subscript specifying the first row of the subarray[I] dest_layer Subscript specifying the first layer of the subarray([I] : input, [O] : output)

RETURN VALUE
A reference to itself

112

SLLIB Reference: sli::Mdarray

EXAMPLEThe following code adds the object add smdarr with a two-dimension array to the object
my smdarr with a two-dimension array and prints the values of elements to stdout for confirmation. For more information about putdata(), see §4.5.22.
stdstreamio sio;mdarray my_smdarr(SHORT_ZT, 2,2);
short my_short[] = {1, 2, 3, 4};
my_smdarr.putdata((const void *)my_short, sizeof(my_short));mdarray myadd_smdarr(SHORT_ZT, 2,2);
short myadd_short[] = {9, 8, 7, 6};
myadd_smdarr.putdata((const void *)myadd_short, sizeof(myadd_short));my_smdarr.add(myadd_smdarr);for ( size_t j = 0 ; j < my_smdarr.length(1) ; j++ ) {for ( size_t i = 0 ; i < my_smdarr.length(0) ; i++ ) {sio.printf("my_smdarr value(%zu,%zu)... [%hd]\n",i, j, my_smdarr.s(i, j));}}Output:my smdarr value(0,0)...
my smdarr value(1,0)...
my smdarr value(0,1)...
my smdarr value(1,1)...

4.5.55

[10]
[10]
[10]
[10]

subtract()

NAME
subtract() — Subtract an array object (for image data)
SYNOPSIS
mdarray &subtract( const mdarray &src_img, ssize_t dest_col = 0,
ssize_t dest_row = 0, ssize_t dest_layer = 0 );DESCRIPTIONThis member function subtracts array elements of the object src img from those of theobject itself. A start position for subtraction can be specified separately for columns, rows,
and layers. This member function is for image data.
PARAMETER[I] src_img

An instance of the class “mdarray” to be subtracted from a subarray ofthis object[I] dest_col
Subscript specifying the first column of the subarray[I] dest_row
Subscript specifying the first row of the subarray[I] dest_layer Subscript specifying the first layer of the subarray([I] : input, [O] : output)

SLLIB Reference: sli::Mdarray

113

RETURN VALUE
A reference to itself
EXAMPLEThe following code subtracts the object mysubtract mdarr with a two-dimension array fromthe object my fmdarr with a two-dimension array and prints the values of elements to stdout
for confirmation. For more information about putdata(), see §4.5.22.
stdstreamio sio;mdarray my_fmdarr(FLOAT_ZT, 2,2);
mdarray mysubtract_mdarr(FLOAT_ZT, 2,2);
float my_float[] = {1000, 2000, 3000, 4000};my_fmdarr.putdata((const void *)my_float, sizeof(my_float));float mysubt_float[] = {100, 200, 300, 400};
mysubtract_mdarr.putdata((const void *)mysubt_float, sizeof(mysubt_float));my_fmdarr.subtract(mysubtract_mdarr);for ( size_t j = 0 ; j < my_fmdarr.length(1) ; j++ ) {for ( size_t i = 0 ; i < my_fmdarr.length(0) ; i++ ) {sio.printf("my_fmdarr value(%zu,%zu)... [%f]\n",i, j, my_fmdarr.f(i, j));}}Output:my fmdarr value(0,0)...
my fmdarr value(1,0)...
my fmdarr value(0,1)...
my fmdarr value(1,1)...
4.5.56[900.000000][1800.000000][2700.000000][3600.000000]

multiply()

NAME
multiply() — Multiply an array object (for image data)
SYNOPSIS
mdarray &multiply( const mdarray &src_img, ssize_t dest_col = 0,
ssize_t dest_row = 0, ssize_t dest_layer = 0 );DESCRIPTIONThis member function multiplies array elements of the object itself by those of the object
src img. A start position for multiplication can be specified separately for columns, rows,
and layers. This member function is for image data.
PARAMETER[I] src_img

An instance of the class “mdarray” by which a subarray of this object
is multiplied[I] dest_col
Subscript specifying the first column of the subarray[I] dest_row
Subscript specifying the first row of the subarray[I] dest_layer Subscript specifying the first layer of the subarray([I] : input, [O] : output)

114

SLLIB Reference: sli::Mdarray

RETURN VALUE
A reference to itself
EXAMPLEThe following code multiplies the object my fmdarr with a two-dimension array by the object
mymulti fmdarr with a two-dimension array and prints the values of elements to stdout for
confirmation:
stdstreamio sio;mdarray my_fmdarr(FLOAT_ZT, 2,2);
float my_float[] = {1, 2, 3, 4};
my_fmdarr.putdata((const void *)my_float, sizeof(my_float));mdarray mymulti_fmdarr(FLOAT_ZT, 2,2);
float mymulti_float[] = {10, 20, 30, 40};
mymulti_fmdarr.putdata((const void *)mymulti_float, sizeof(mymulti_float));my_fmdarr.multiply(mymulti_fmdarr);for ( size_t j = 0 ; j < my_fmdarr.length(1) ; j++ ) {for ( size_t i = 0 ; i < my_fmdarr.length(0) ; i++ ) {sio.printf("my_fmdarr value(%zu,%zu)... [%f]\n",i, j, my_fmdarr.f(i, j));}}Output:my fmdarr value(0,0)...
my fmdarr value(1,0)...
my fmdarr value(0,1)...
my fmdarr value(1,1)...
4.5.57[10.000000][40.000000][90.000000][160.000000]

divide()NAME
divide() — Divide an array object (for image data)
SYNOPSIS
mdarray &divide( const mdarray &src_img, ssize_t dest_col = 0,
ssize_t dest_row = 0, ssize_t dest_layer = 0 );DESCRIPTIONThis member function divides array elements of the object itself by those of the object
src img. A start position for division can be specified separately for columns, rows, andlayers. This member function is for image data.
PARAMETER[I] src_img

An instance of the class “mdarray” by which a subarray of this object
is divided[I] dest_col
Subscript for the first column of the subarray[I] dest_row
Subscript for the first row of the subarray[I] dest_layer Subscript for the first layer of the subarray([I] : input, [O] : output)

SLLIB Reference: sli::Mdarray

115

RETURN VALUE
A reference to itself
EXAMPLEThe following code divides the object my fmdarr with a two-dimension array by the object
mydiv mdarrf with a two-dimension array and prints the values of elements to stdout for
confirmation. For more information about putdata(), see §4.5.22.
stdstreamio sio;mdarray my_fmdarr(FLOAT_ZT, 2,2);
float my_float[] = {1000, 2000, 3000, 4000};my_fmdarr.putdata((const void *)my_float, sizeof(my_float));mdarray mydiv_mdarrf(FLOAT_ZT, 2,2);
float mydiv_float[] = {2, 4, 6, 8};
mydiv_mdarrf.putdata((const void *)mydiv_float, sizeof(mydiv_float));my_fmdarr.divide(mydiv_mdarrf);
for ( size_t j = 0 ; j < my_fmdarr.length(1) ; j++ ) {for ( size_t i = 0 ; i < my_fmdarr.length(0) ; i++ ) {sio.printf("my_fmdarr value(%zu,%zu)... [%f]\n",i, j, my_fmdarr.f(i, j));}}Output:my fmdarr value(0,0)...
my fmdarr value(1,0)...
my fmdarr value(0,1)...
my fmdarr value(1,1)...

[500.000000][500.000000][500.000000][500.000000]