GNU Octave  4.2.1
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
ovl.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1994-2017 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_ovl_h)
25 #define octave_ovl_h 1
26 
27 #include "octave-config.h"
28 
29 #include <string>
30 #include <vector>
31 #include <initializer_list>
32 
33 #include "str-vec.h"
34 #include "Array.h"
35 
36 #include "ov.h"
37 #include "Cell.h"
38 
39 class
42 {
43 public:
44 
46  : data (), names () { }
47 
49  : data (dim_vector (1, n)), names () { }
50 
52  : data (dim_vector (1, n), val), names () { }
53 
55  : data (dim_vector (1, 1), tc), names () { }
56 
57  template<template <typename...> class OV_Container>
58  octave_value_list (const OV_Container<octave_value>& args)
59  : data (args, dim_vector (1, args.size ())), names () { }
60 
62  : data (d.as_row ()), names () { }
63 
64  octave_value_list (const Cell& tc)
65  : data (tc.as_row ()), names () { }
66 
68  : data (obj.data), names (obj.names) { }
69 
70  // Concatenation constructor.
71  octave_value_list (const std::list<octave_value_list>&);
72 
73  ~octave_value_list (void) { }
74 
76  {
77  if (this != &obj)
78  {
79  data = obj.data;
80  names = obj.names;
81  }
82 
83  return *this;
84  }
85 
86  Array<octave_value> array_value (void) const { return data; }
87 
88  Cell cell_value (void) const { return array_value (); }
89 
90  // Assignment will resize on range errors.
91 
92  octave_value& operator () (octave_idx_type n) { return elem (n); }
93 
94  const octave_value& operator () (octave_idx_type n) const { return elem (n); }
95 
96  octave_idx_type length (void) const { return data.numel (); }
97 
98  bool empty (void) const { return length () == 0; }
99 
101  {
102  data.resize (dim_vector (1, n), rfv);
103  }
104 
105  octave_value_list& prepend (const octave_value& val);
106 
108 
110 
111  octave_value_list& reverse (void);
112 
114  slice (octave_idx_type offset, octave_idx_type len, bool tags = false) const
115  {
116  // linear_slice uses begin/end indices instead of offset and length.
117  // Avoid calling with upper bound out of range.
118  // linear_slice handles the case of len < 0.
119 
121  = data.linear_slice (offset, std::min (offset + len, length ()));
122 
123  if (tags && len > 0 && names.numel () > 0)
124  retval.names = names.linear_slice (offset, std::min (offset + len,
125  names.numel ()));
126 
127  return retval;
128  }
129 
131  splice (octave_idx_type offset, octave_idx_type len,
132  const octave_value_list& lst = octave_value_list ()) const;
133 
134  bool all_strings_p (void) const;
135 
136  bool all_scalars (void) const;
137 
138  bool any_cell (void) const;
139 
140  bool has_magic_colon (void) const;
141 
142  string_vector make_argv (const std::string& = "") const;
143 
144  void stash_name_tags (const string_vector& nm) { names = nm; }
145 
146  string_vector name_tags (void) const { return names; }
147 
148  void make_storable_values (void);
149 
150  octave_value& xelem (octave_idx_type i) { return data.xelem (i); }
151 
152  void clear (void) { data.clear (); }
153 
154 private:
155 
157 
158  // This list of strings can be used to tag each element of data with a name.
159  // By default, it is empty.
161 
163  {
164  if (n >= length ())
165  resize (n + 1);
166 
167  return data(n);
168  }
169 
171  { return data(n); }
172 
173 };
174 
175 
176 //! Construct an octave_value_list with less typing.
177 /*!
178  Historically, this made it easier to create an octave_value_list
179  from multiple octave_value arguments. It is no longer useful since
180  octave_value_list has now a constructor accepting an initializer_list
181  so all it does is save some typing. The following are equivalent:
182 
183  @code{.cc}
184  return octave_value_list ({ov0, ov1, ov2});
185  return ovl (ov0, ov1, ov2);
186  @endcode
187 */
188 template<typename... OV_Args>
189 inline octave_value_list
190 ovl (const OV_Args&... args)
191 {
192  return octave_value_list (std::initializer_list<octave_value> ({args...}));
193 }
194 
195 #endif
Definition: Cell.h:37
void clear(void)
Definition: ovl.h:152
octave_value_list(const Cell &tc)
Definition: ovl.h:64
octave_value_list(const Array< octave_value > &d)
Definition: ovl.h:61
octave_value_list slice(octave_idx_type offset, octave_idx_type len, bool tags=false) const
Definition: ovl.h:114
octave_value_list(octave_idx_type n, const octave_value &val)
Definition: ovl.h:51
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:5068
octave_idx_type length(void) const
Definition: ovl.h:96
octave_value_list(const octave_value_list &obj)
Definition: ovl.h:67
string_vector name_tags(void) const
Definition: ovl.h:146
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
Cell cell_value(void) const
Definition: ovl.h:88
const octave_value & elem(octave_idx_type n) const
Definition: ovl.h:170
JNIEnv void * args
Definition: ov-java.cc:67
octave_value & elem(octave_idx_type n)
Definition: ovl.h:162
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
Definition: utils.cc:941
#define OCTINTERP_API
Definition: mexproto.h:69
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:297
static int elem
Definition: __contourc__.cc:50
octave_value retval
Definition: data.cc:6294
bool append
Definition: load-save.cc:1582
octave_value_list(void)
Definition: ovl.h:45
octave_value_list(octave_idx_type n)
Definition: ovl.h:48
Array< octave_value > data
Definition: ovl.h:156
bool empty(void) const
Definition: ovl.h:98
octave_value_list(const octave_value &tc)
Definition: ovl.h:54
octave_value_list ovl(const OV_Args &...args)
Construct an octave_value_list with less typing.
Definition: ovl.h:190
Array< octave_value > array_value(void) const
Definition: ovl.h:86
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
~octave_value_list(void)
Definition: ovl.h:73
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
Definition: ovl.h:100
OCTAVE_EXPORT octave_value_list any number nd example oindent prints the prompt xample Pick a any number!nd example oindent and waits for the user to enter a value The string entered by the user is evaluated as an so it may be a literal a variable or any other valid Octave code The number of return their size
Definition: input.cc:871
octave_value_list(const OV_Container< octave_value > &args)
Definition: ovl.h:58
string_vector names
Definition: ovl.h:160
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
octave_value & xelem(octave_idx_type i)
Definition: ovl.h:150
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854
charNDArray min(char d, const charNDArray &m)
Definition: chNDArray.cc:205
octave_lvalue & operator=(const octave_lvalue &vr)
Definition: oct-lvalue.h:51
void stash_name_tags(const string_vector &nm)
Definition: ovl.h:144