GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ovl.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1994-2018 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
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License 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 <https://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
40 OCTINTERP_API
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) = default;
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 
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 
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 
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 
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
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:280
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(octave_idx_type n, const octave_value &val)
Definition: ovl.h:51
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
Definition: ovl.h:190
octave_value_list slice(octave_idx_type offset, octave_idx_type len, bool tags=false) const
Definition: ovl.h:114
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:4986
octave_value_list(const octave_value_list &obj)
Definition: ovl.h:67
bool empty(void) const
Definition: ovl.h:98
bool has_magic_colon(void) const
Definition: ovl.cc:200
octave_value_list splice(octave_idx_type offset, octave_idx_type len, const octave_value_list &lst=octave_value_list()) const
Definition: ovl.cc:124
void make_storable_values(void)
Definition: ovl.cc:262
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 const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
const octave_value & elem(octave_idx_type n) const
Definition: ovl.h:170
octave_value & elem(octave_idx_type n)
Definition: ovl.h:162
bool any_cell(void) const
Definition: ovl.cc:188
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
Definition: utils.cc:975
octave_value_list & reverse(void)
Definition: ovl.cc:109
Array< octave_value > array_value(void) const
Definition: ovl.h:86
string_vector make_argv(const std::string &="") const
Definition: ovl.cc:212
static int elem
Definition: __contourc__.cc:47
void resize(const dim_vector &dv, const T &rfv)
Resizing (with fill).
Definition: Array.cc:1010
octave_value retval
Definition: data.cc:6246
bool append
Definition: load-save.cc:1618
octave_value_list(void)
Definition: ovl.h:45
octave_value & operator()(octave_idx_type n)
Definition: ovl.h:92
bool all_scalars(void) const
Definition: ovl.cc:173
octave_value_list(octave_idx_type n)
Definition: ovl.h:48
Array< octave_value > data
Definition: ovl.h:156
T & xelem(octave_idx_type n)
Definition: Array.h:458
void clear(void)
Definition: Array.cc:86
string_vector name_tags(void) const
Definition: ovl.h:146
octave_value_list(const octave_value &tc)
Definition: ovl.h:54
Cell cell_value(void) const
Definition: ovl.h:88
octave_idx_type length(void) const
Definition: ovl.h:96
bool all_strings_p(void) const
Definition: ovl.cc:161
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
Definition: ovl.h:100
for i
Definition: data.cc:5264
octave_value_list(const OV_Container< octave_value > &args)
Definition: ovl.h:58
~octave_value_list(void)=default
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:366
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:888
octave_value_list & prepend(const octave_value &val)
Definition: ovl.cc:65
charNDArray min(char d, const charNDArray &m)
Definition: chNDArray.cc:204
octave_value_list & operator=(const octave_value_list &obj)
Definition: ovl.h:75
void stash_name_tags(const string_vector &nm)
Definition: ovl.h:144