GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
oct-obj.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1994-2015 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 "str-vec.h"
31 #include "Array.h"
32 
33 #include "ov.h"
34 #include "Cell.h"
35 
36 class
39 {
40 public:
41 
43  : data (), names () { }
44 
46  : data (dim_vector (1, n)), names () { }
47 
49  : data (dim_vector (1, n), val), names () { }
50 
52  : data (dim_vector (1, 1), tc), names () { }
53 
55  : data (d.as_row ()), names () { }
56 
57  octave_value_list (const Cell& tc)
58  : data (tc.as_row ()), names () { }
59 
61  : data (obj.data), names (obj.names) { }
62 
63  // Concatenation constructor.
64  octave_value_list (const std::list<octave_value_list>&);
65 
66  ~octave_value_list (void) { }
67 
68  octave_value_list& operator = (const octave_value_list& obj)
69  {
70  if (this != &obj)
71  {
72  data = obj.data;
73  names = obj.names;
74  }
75 
76  return *this;
77  }
78 
79  Array<octave_value> array_value (void) const { return data; }
80 
81  Cell cell_value (void) const { return array_value (); }
82 
83  // Assignment will resize on range errors.
84 
85  octave_value& operator () (octave_idx_type n) { return elem (n); }
86 
87  const octave_value& operator () (octave_idx_type n) const { return elem (n); }
88 
89  octave_idx_type length (void) const { return data.length (); }
90 
91  bool empty (void) const { return length () == 0; }
92 
93  void resize (octave_idx_type n, const octave_value& rfv = octave_value ())
94  {
95  data.resize (dim_vector (1, n), rfv);
96  }
97 
98  octave_value_list& prepend (const octave_value& val);
99 
100  octave_value_list& append (const octave_value& val);
101 
102  octave_value_list& append (const octave_value_list& lst);
103 
104  octave_value_list& reverse (void);
105 
107  slice (octave_idx_type offset, octave_idx_type len, bool tags = false) const
108  {
109  // linear_slice uses begin/end indices instead of offset and
110  // length. Avoid calling with upper bound out of range.
111  // linear_slice handles the case of len < 0.
112 
113  octave_value_list retval
114  = data.linear_slice (offset, std::min (offset + len, length ()));
115 
116  if (tags && len > 0 && names.length () > 0)
117  retval.names = names.linear_slice (offset, std::min (offset + len,
118  names.length ()));
119 
120  return retval;
121  }
122 
124  splice (octave_idx_type offset, octave_idx_type len,
125  const octave_value_list& lst = octave_value_list ()) const;
126 
127  bool all_strings_p (void) const;
128 
129  bool all_scalars (void) const;
130 
131  bool any_cell (void) const;
132 
133  bool has_magic_colon (void) const;
134 
135  string_vector make_argv (const std::string& = std::string ()) const;
136 
137  void stash_name_tags (const string_vector& nm) { names = nm; }
138 
139  string_vector name_tags (void) const { return names; }
140 
141  void make_storable_values (void);
142 
144  {
145  return data.xelem (i);
146  }
147 
148  void clear (void)
149  {
150  data.clear ();
151  }
152 
153 private:
154 
156 
157  // This list of strings can be used to tag each element of data with
158  // a name. By default, it is empty.
160 
162  {
163  if (n >= length ())
164  resize (n + 1);
165 
166  return data(n);
167  }
168 
170  { return data(n); }
171 
172 };
173 
174 // Make it easy to build argument lists for built-in functions or for
175 // returning values.
176 
177 inline octave_value_list
178 ovl (const octave_value& a0)
179 {
180  octave_value_list retval;
181  retval(0) = a0;
182  return retval;
183 }
184 
185 inline octave_value_list
186 ovl (const octave_value& a0, const octave_value& a1)
187 {
188  octave_value_list retval;
189  retval(1) = a1;
190  retval(0) = a0;
191  return retval;
192 }
193 
194 inline octave_value_list
195 ovl (const octave_value& a0, const octave_value& a1,
196  const octave_value& a2)
197 {
198  octave_value_list retval;
199  retval(2) = a2;
200  retval(1) = a1;
201  retval(0) = a0;
202  return retval;
203 }
204 
205 inline octave_value_list
206 ovl (const octave_value& a0, const octave_value& a1,
207  const octave_value& a2, const octave_value& a3)
208 {
209  octave_value_list retval;
210  retval(3) = a3;
211  retval(2) = a2;
212  retval(1) = a1;
213  retval(0) = a0;
214  return retval;
215 }
216 
217 inline octave_value_list
218 ovl (const octave_value& a0, const octave_value& a1,
219  const octave_value& a2, const octave_value& a3,
220  const octave_value& a4)
221 {
222  octave_value_list retval;
223  retval(4) = a4;
224  retval(3) = a3;
225  retval(2) = a2;
226  retval(1) = a1;
227  retval(0) = a0;
228  return retval;
229 }
230 
231 inline octave_value_list
232 ovl (const octave_value& a0, const octave_value& a1,
233  const octave_value& a2, const octave_value& a3,
234  const octave_value& a4, const octave_value& a5)
235 {
236  octave_value_list retval;
237  retval(5) = a5;
238  retval(4) = a4;
239  retval(3) = a3;
240  retval(2) = a2;
241  retval(1) = a1;
242  retval(0) = a0;
243  return retval;
244 }
245 
246 inline octave_value_list
247 ovl (const octave_value& a0, const octave_value& a1,
248  const octave_value& a2, const octave_value& a3,
249  const octave_value& a4, const octave_value& a5,
250  const octave_value& a6)
251 {
252  octave_value_list retval;
253  retval(6) = a6;
254  retval(5) = a5;
255  retval(4) = a4;
256  retval(3) = a3;
257  retval(2) = a2;
258  retval(1) = a1;
259  retval(0) = a0;
260  return retval;
261 }
262 
263 inline octave_value_list
264 ovl (const octave_value& a0, const octave_value& a1,
265  const octave_value& a2, const octave_value& a3,
266  const octave_value& a4, const octave_value& a5,
267  const octave_value& a6, const octave_value& a7)
268 {
269  octave_value_list retval;
270  retval(7) = a7;
271  retval(6) = a6;
272  retval(5) = a5;
273  retval(4) = a4;
274  retval(3) = a3;
275  retval(2) = a2;
276  retval(1) = a1;
277  retval(0) = a0;
278  return retval;
279 }
280 
281 inline octave_value_list
282 ovl (const octave_value& a0, const octave_value& a1,
283  const octave_value& a2, const octave_value& a3,
284  const octave_value& a4, const octave_value& a5,
285  const octave_value& a6, const octave_value& a7,
286  const octave_value& a8)
287 {
288  octave_value_list retval;
289  retval(8) = a8;
290  retval(7) = a7;
291  retval(6) = a6;
292  retval(5) = a5;
293  retval(4) = a4;
294  retval(3) = a3;
295  retval(2) = a2;
296  retval(1) = a1;
297  retval(0) = a0;
298  return retval;
299 }
300 
301 inline octave_value_list
302 ovl (const octave_value& a0, const octave_value& a1,
303  const octave_value& a2, const octave_value& a3,
304  const octave_value& a4, const octave_value& a5,
305  const octave_value& a6, const octave_value& a7,
306  const octave_value& a8, const octave_value& a9)
307 {
308  octave_value_list retval;
309  retval(9) = a9;
310  retval(8) = a8;
311  retval(7) = a7;
312  retval(6) = a6;
313  retval(5) = a5;
314  retval(4) = a4;
315  retval(3) = a3;
316  retval(2) = a2;
317  retval(1) = a1;
318  retval(0) = a0;
319  return retval;
320 }
321 
322 #endif
Definition: Cell.h:35
void clear(void)
Definition: oct-obj.h:148
octave_value_list(const Cell &tc)
Definition: oct-obj.h:57
octave_value_list(const Array< octave_value > &d)
Definition: oct-obj.h:54
octave_value_list slice(octave_idx_type offset, octave_idx_type len, bool tags=false) const
Definition: oct-obj.h:107
octave_value_list(octave_idx_type n, const octave_value &val)
Definition: oct-obj.h:48
octave_idx_type length(void) const
Definition: oct-obj.h:89
octave_value_list(const octave_value_list &obj)
Definition: oct-obj.h:60
string_vector name_tags(void) const
Definition: oct-obj.h:139
static string_vector names(const map_type &lst)
Definition: help.cc:782
F77_RET_T const double const double double * d
const octave_base_value & a2
Cell cell_value(void) const
Definition: oct-obj.h:81
const octave_value & elem(octave_idx_type n) const
Definition: oct-obj.h:169
octave_value & elem(octave_idx_type n)
Definition: oct-obj.h:161
#define OCTINTERP_API
Definition: mexproto.h:66
Array< T > linear_slice(octave_idx_type lo, octave_idx_type up) const
Extract a slice from this array as a column vector: A(:)(lo+1:up).
Definition: Array.cc:286
static int elem
Definition: __contourc__.cc:49
octave_value_list(void)
Definition: oct-obj.h:42
octave_value_list(octave_idx_type n)
Definition: oct-obj.h:45
Array< octave_value > data
Definition: oct-obj.h:155
octave_idx_type length(void) const
Number of elements in the array.
Definition: Array.h:267
bool empty(void) const
Definition: oct-obj.h:91
octave_value_list ovl(const octave_value &a0)
Definition: oct-obj.h:178
octave_value_list(const octave_value &tc)
Definition: oct-obj.h:51
Array< octave_value > array_value(void) const
Definition: oct-obj.h:79
~octave_value_list(void)
Definition: oct-obj.h:66
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
Definition: oct-obj.h:93
string_vector names
Definition: oct-obj.h:159
octave_value & xelem(octave_idx_type i)
Definition: oct-obj.h:143
charNDArray min(char d, const charNDArray &m)
Definition: chNDArray.cc:210
void stash_name_tags(const string_vector &nm)
Definition: oct-obj.h:137