GNU Octave
3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
libinterp
corefcn
oct-obj.h
Go to the documentation of this file.
1
/*
2
3
Copyright (C) 1994-2013 John W. Eaton
4
Copyright (C) 2009 VZLU Prague
5
6
This file is part of Octave.
7
8
Octave is free software; you can redistribute it and/or modify it
9
under the terms of the GNU General Public License as published by the
10
Free Software Foundation; either version 3 of the License, or (at your
11
option) any later version.
12
13
Octave is distributed in the hope that it will be useful, but WITHOUT
14
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16
for more details.
17
18
You should have received a copy of the GNU General Public License
19
along with Octave; see the file COPYING. If not, see
20
<http://www.gnu.org/licenses/>.
21
22
*/
23
24
#if !defined (octave_oct_obj_h)
25
#define octave_oct_obj_h 1
26
27
#include <string>
28
#include <vector>
29
30
#include "
oct-alloc.h
"
31
#include "
str-vec.h
"
32
#include "
Array.h
"
33
34
#include "
ov.h
"
35
#include "
Cell.h
"
36
37
class
38
OCTINTERP_API
39
octave_value_list
40
{
41
public
:
42
43
octave_value_list
(
void
)
44
: data (),
names
() { }
45
46
explicit
octave_value_list
(
octave_idx_type
n)
47
: data (
dim_vector
(1, n)),
names
() { }
48
49
octave_value_list
(
octave_idx_type
n,
const
octave_value
& val)
50
: data (
dim_vector
(1, n), val),
names
() { }
51
52
octave_value_list
(
const
octave_value
& tc)
53
: data (
dim_vector
(1, 1), tc),
names
() { }
54
55
octave_value_list
(
const
Array<octave_value>
&
d
)
56
: data (d.as_row ()),
names
() { }
57
58
octave_value_list
(
const
Cell
& tc)
59
: data (tc.as_row ()),
names
() { }
60
61
octave_value_list
(
const
octave_value_list
& obj)
62
: data (obj.data),
names
(obj.
names
) { }
63
64
// Concatenation constructor.
65
octave_value_list
(
const
std::list<octave_value_list>&);
66
67
~octave_value_list
(
void
) { }
68
69
octave_value_list
& operator = (
const
octave_value_list
& obj)
70
{
71
if
(
this
!= &obj)
72
{
73
data = obj.
data
;
74
names
= obj.
names
;
75
}
76
77
return
*
this
;
78
}
79
80
Array<octave_value>
array_value
(
void
)
const
{
return
data; }
81
82
Cell
cell_value
(
void
)
const
{
return
array_value (); }
83
84
// Assignment will resize on range errors.
85
86
octave_value
& operator () (
octave_idx_type
n) {
return
elem
(n); }
87
88
const
octave_value
& operator () (
octave_idx_type
n)
const
{
return
elem
(n); }
89
90
octave_idx_type
length
(
void
)
const
{
return
data.length (); }
91
92
bool
empty
(
void
)
const
{
return
length
() == 0; }
93
94
void
resize (
octave_idx_type
n,
const
octave_value
& rfv =
octave_value
())
95
{
96
data.resize (
dim_vector
(1, n), rfv);
97
}
98
99
octave_value_list
& prepend (
const
octave_value
& val);
100
101
octave_value_list
& append (
const
octave_value
& val);
102
103
octave_value_list
& append (
const
octave_value_list
& lst);
104
105
octave_value_list
& reverse (
void
);
106
107
octave_value_list
108
slice (
octave_idx_type
offset,
octave_idx_type
len,
bool
tags =
false
)
const
109
{
110
octave_value_list
retval (data.linear_slice (offset, offset + len));
111
if
(tags && len > 0 &&
names
.
length
() > 0)
112
retval.
names
=
names
.
linear_slice
(offset,
113
std::min
(len,
names
.
length
()));
114
115
return
retval;
116
}
117
118
octave_value_list
119
splice (
octave_idx_type
offset,
octave_idx_type
len,
120
const
octave_value_list
& lst =
octave_value_list
())
const
;
121
122
bool
all_strings_p (
void
)
const
;
123
124
bool
all_scalars (
void
)
const
;
125
126
bool
any_cell (
void
)
const
;
127
128
bool
has_magic_colon (
void
)
const
;
129
130
string_vector
make_argv (
const
std::string& = std::string ())
const
;
131
132
void
stash_name_tags
(
const
string_vector
& nm) {
names
= nm; }
133
134
string_vector
name_tags
(
void
)
const
{
return
names
; }
135
136
void
make_storable_values (
void
);
137
138
octave_value
& xelem (
octave_idx_type
i)
139
{
140
return
data.xelem (i);
141
}
142
143
void
clear
(
void
)
144
{
145
data.clear ();
146
}
147
148
private
:
149
150
Array<octave_value>
data
;
151
152
// This list of strings can be used to tag each element of data with
153
// a name. By default, it is empty.
154
string_vector
names
;
155
156
octave_value
&
elem
(
octave_idx_type
n)
157
{
158
if
(n >=
length
())
159
resize (n + 1);
160
161
return
data(n);
162
}
163
164
const
octave_value
&
elem
(
octave_idx_type
n)
const
165
{
return
data(n); }
166
167
DECLARE_OCTAVE_ALLOCATOR
168
};
169
170
// Make it easy to build argument lists for built-in functions or for
171
// returning values.
172
173
inline
octave_value_list
174
ovl
(
const
octave_value
& a0)
175
{
176
octave_value_list
retval;
177
retval(0) = a0;
178
return
retval;
179
}
180
181
inline
octave_value_list
182
ovl
(
const
octave_value
& a0,
const
octave_value
& a1)
183
{
184
octave_value_list
retval;
185
retval(1) = a1;
186
retval(0) = a0;
187
return
retval;
188
}
189
190
inline
octave_value_list
191
ovl
(
const
octave_value
& a0,
const
octave_value
& a1,
192
const
octave_value
&
a2
)
193
{
194
octave_value_list
retval;
195
retval(2) =
a2
;
196
retval(1) = a1;
197
retval(0) = a0;
198
return
retval;
199
}
200
201
inline
octave_value_list
202
ovl
(
const
octave_value
& a0,
const
octave_value
& a1,
203
const
octave_value
&
a2
,
const
octave_value
& a3)
204
{
205
octave_value_list
retval;
206
retval(3) = a3;
207
retval(2) =
a2
;
208
retval(1) = a1;
209
retval(0) = a0;
210
return
retval;
211
}
212
213
inline
octave_value_list
214
ovl
(
const
octave_value
& a0,
const
octave_value
& a1,
215
const
octave_value
&
a2
,
const
octave_value
& a3,
216
const
octave_value
& a4)
217
{
218
octave_value_list
retval;
219
retval(4) = a4;
220
retval(3) = a3;
221
retval(2) =
a2
;
222
retval(1) = a1;
223
retval(0) = a0;
224
return
retval;
225
}
226
227
inline
octave_value_list
228
ovl
(
const
octave_value
& a0,
const
octave_value
& a1,
229
const
octave_value
&
a2
,
const
octave_value
& a3,
230
const
octave_value
& a4,
const
octave_value
& a5)
231
{
232
octave_value_list
retval;
233
retval(5) = a5;
234
retval(4) = a4;
235
retval(3) = a3;
236
retval(2) =
a2
;
237
retval(1) = a1;
238
retval(0) = a0;
239
return
retval;
240
}
241
242
inline
octave_value_list
243
ovl
(
const
octave_value
& a0,
const
octave_value
& a1,
244
const
octave_value
&
a2
,
const
octave_value
& a3,
245
const
octave_value
& a4,
const
octave_value
& a5,
246
const
octave_value
& a6)
247
{
248
octave_value_list
retval;
249
retval(6) = a6;
250
retval(5) = a5;
251
retval(4) = a4;
252
retval(3) = a3;
253
retval(2) =
a2
;
254
retval(1) = a1;
255
retval(0) = a0;
256
return
retval;
257
}
258
259
inline
octave_value_list
260
ovl
(
const
octave_value
& a0,
const
octave_value
& a1,
261
const
octave_value
&
a2
,
const
octave_value
& a3,
262
const
octave_value
& a4,
const
octave_value
& a5,
263
const
octave_value
& a6,
const
octave_value
& a7)
264
{
265
octave_value_list
retval;
266
retval(7) = a7;
267
retval(6) = a6;
268
retval(5) = a5;
269
retval(4) = a4;
270
retval(3) = a3;
271
retval(2) =
a2
;
272
retval(1) = a1;
273
retval(0) = a0;
274
return
retval;
275
}
276
277
inline
octave_value_list
278
ovl
(
const
octave_value
& a0,
const
octave_value
& a1,
279
const
octave_value
&
a2
,
const
octave_value
& a3,
280
const
octave_value
& a4,
const
octave_value
& a5,
281
const
octave_value
& a6,
const
octave_value
& a7,
282
const
octave_value
& a8)
283
{
284
octave_value_list
retval;
285
retval(8) = a8;
286
retval(7) = a7;
287
retval(6) = a6;
288
retval(5) = a5;
289
retval(4) = a4;
290
retval(3) = a3;
291
retval(2) =
a2
;
292
retval(1) = a1;
293
retval(0) = a0;
294
return
retval;
295
}
296
297
inline
octave_value_list
298
ovl
(
const
octave_value
& a0,
const
octave_value
& a1,
299
const
octave_value
&
a2
,
const
octave_value
& a3,
300
const
octave_value
& a4,
const
octave_value
& a5,
301
const
octave_value
& a6,
const
octave_value
& a7,
302
const
octave_value
& a8,
const
octave_value
& a9)
303
{
304
octave_value_list
retval;
305
retval(9) = a9;
306
retval(8) = a8;
307
retval(7) = a7;
308
retval(6) = a6;
309
retval(5) = a5;
310
retval(4) = a4;
311
retval(3) = a3;
312
retval(2) =
a2
;
313
retval(1) = a1;
314
retval(0) = a0;
315
return
retval;
316
}
317
318
#endif
Generated on Mon Dec 30 2013 03:04:27 for GNU Octave by
1.8.1.2