GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
Cell.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1999-2023 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_Cell_h)
27 #define octave_Cell_h 1
28 
29 #include "octave-config.h"
30 
31 #include <list>
32 #include <string>
33 
34 #include "Array.h"
35 #include "str-vec.h"
36 #include "ov.h"
37 
38 class octave_value_list;
39 
40 class
41 OCTINTERP_API
43 {
44 public:
45 
46  Cell (void) = default;
47 
48  Cell (const Cell& c) = default;
49 
50  Cell& operator = (const Cell& c) = default;
51 
52  ~Cell (void) = default;
53 
54  Cell (const octave_value& val)
55  : Array<octave_value> (dim_vector (1, 1), val) { }
56 
57  Cell (const octave_value_list& ovl);
58 
60  const octave_value& val = Matrix ())
61  : Array<octave_value> (dim_vector (n, m), val) { }
62 
63  Cell (const dim_vector& dv, const octave_value& val = Matrix ())
64  : Array<octave_value> (dv, val) { }
65 
67  : Array<octave_value> (c) { }
68 
70  : Array<octave_value> (c, dim_vector (nr, nc)) { }
71 
72  Cell (const string_vector& sv, bool trim = false);
73 
74  // Constructor for standard containers. V must be convertible to an
75  // octave_value object.
76  template <typename V, template <typename...> class C>
77  explicit
78  Cell (const C<V>& container)
79  : Array<octave_value> ()
80  {
81  std::size_t n = container.size ();
82 
83  if (n > 0)
84  {
85  resize (dim_vector (n, 1));
86 
87  octave_idx_type i = 0;
88 
89  for (const auto& val : container)
90  elem(i++, 0) = val;
91  }
92  }
93 
94  Cell (const std::list<std::string>& sl);
95 
96  Cell (const Array<std::string>& sa);
97 
98  Cell (const dim_vector& dv, const string_vector& sv, bool trim = false);
99 
100  bool iscellstr (void) const;
101 
102  Array<std::string> cellstr_value (void) const;
103 
104  string_vector string_vector_value (void) const;
105 
107 
108  Cell index (const octave_value_list& idx, bool resize_ok = false) const;
109 
111 
112  void delete_elements (const octave_value_list& idx);
113 
115 
116  void assign (const octave_value_list& idx, const Cell& rhs,
117  const octave_value& fill_val = Matrix ());
118 
119  Cell reshape (const dim_vector& new_dims) const
120  { return Array<octave_value>::reshape (new_dims); }
121 
122  octave_idx_type nnz (void) const;
123 
124  Cell column (octave_idx_type i) const;
125 
126  // FIXME
127  boolMatrix all (int /* dim */ = 0) const { return boolMatrix (); }
128 
129  // FIXME
130  boolMatrix any (int /* dim */ = 0) const { return boolMatrix (); }
131 
132  Cell concat (const Cell& rb, const Array<octave_idx_type>& ra_idx);
133 
134  Cell& insert (const Cell& a, octave_idx_type r, octave_idx_type c);
135  Cell& insert (const Cell& a, const Array<octave_idx_type>& ra_idx);
136 
137  // FIXME
138  bool any_element_is_nan (void) const { return false; }
139  bool is_true (void) const { return false; }
140 
141  octave_value resize_fill_value (void) const;
142 
143  Cell diag (octave_idx_type k = 0) const;
144 
145  Cell diag (octave_idx_type m, octave_idx_type n) const;
146 
147  Cell xisalnum (void) const { return map (&octave_value::xisalnum); }
148  Cell xisalpha (void) const { return map (&octave_value::xisalpha); }
149  Cell xisascii (void) const { return map (&octave_value::xisascii); }
150  Cell xiscntrl (void) const { return map (&octave_value::xiscntrl); }
151  Cell xisdigit (void) const { return map (&octave_value::xisdigit); }
152  Cell xisgraph (void) const { return map (&octave_value::xisgraph); }
153  Cell xislower (void) const { return map (&octave_value::xislower); }
154  Cell xisprint (void) const { return map (&octave_value::xisprint); }
155  Cell xispunct (void) const { return map (&octave_value::xispunct); }
156  Cell xisspace (void) const { return map (&octave_value::xisspace); }
157  Cell xisupper (void) const { return map (&octave_value::xisupper); }
158  Cell xisxdigit (void) const { return map (&octave_value::xisxdigit); }
159  Cell xtolower (void) const { return map (&octave_value::xtolower); }
160  Cell xtoupper (void) const { return map (&octave_value::xtoupper); }
161 
162 private:
163 
164  typedef octave_value (octave_value::*ctype_mapper) (void) const;
165 
166  Cell map (ctype_mapper) const;
167 };
168 
169 template <>
171 { return v.cell_value (); }
172 
173 #endif
ComplexNDArray concat(NDArray &ra, ComplexNDArray &rb, const Array< octave_idx_type > &ra_idx)
Definition: CNDArray.cc:418
Cell octave_value_extract< Cell >(const octave_value &v)
Definition: Cell.h:170
#define C(a, b)
Definition: Faddeeva.cc:259
static int elem
Definition: __contourc__.cc:54
OCTARRAY_OVERRIDABLE_FUNC_API Array< T, Alloc > reshape(octave_idx_type nr, octave_idx_type nc) const
Size of the specified dimension.
Definition: Array.h:635
Definition: Cell.h:43
boolMatrix any(int=0) const
Definition: Cell.h:130
Cell(const Array< octave_value > &c, octave_idx_type nr, octave_idx_type nc)
Definition: Cell.h:69
Cell xisalpha(void) const
Definition: Cell.h:148
Cell xisspace(void) const
Definition: Cell.h:156
Cell xisascii(void) const
Definition: Cell.h:149
Cell xisgraph(void) const
Definition: Cell.h:152
Cell xtolower(void) const
Definition: Cell.h:159
Cell xisupper(void) const
Definition: Cell.h:157
Cell(const Array< octave_value > &c)
Definition: Cell.h:66
Cell(const Cell &c)=default
Cell reshape(const dim_vector &new_dims) const
Definition: Cell.h:119
Cell(void)=default
Cell xisxdigit(void) const
Definition: Cell.h:158
Cell xtoupper(void) const
Definition: Cell.h:160
Cell xisalnum(void) const
Definition: Cell.h:147
Cell(octave_idx_type n, octave_idx_type m, const octave_value &val=Matrix())
Definition: Cell.h:59
Cell xisprint(void) const
Definition: Cell.h:154
Cell(const C< V > &container)
Definition: Cell.h:78
Cell(const dim_vector &dv, const octave_value &val=Matrix())
Definition: Cell.h:63
boolMatrix all(int=0) const
Definition: Cell.h:127
Cell xisdigit(void) const
Definition: Cell.h:151
bool any_element_is_nan(void) const
Definition: Cell.h:138
Cell(const octave_value &val)
Definition: Cell.h:54
~Cell(void)=default
Cell xiscntrl(void) const
Definition: Cell.h:150
Cell xislower(void) const
Definition: Cell.h:153
Cell xispunct(void) const
Definition: Cell.h:155
bool is_true(void) const
Definition: Cell.h:139
Definition: dMatrix.h:42
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:94
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
Definition: ovl.h:117
octave_value_list & operator=(const octave_value_list &obj)=default
octave_value xisxdigit(void) const
Definition: ov.h:1630
octave_value xisgraph(void) const
Definition: ov.h:1624
octave_value xisascii(void) const
Definition: ov.h:1621
octave_value xislower(void) const
Definition: ov.h:1625
octave_value xiscntrl(void) const
Definition: ov.h:1622
octave_value xisprint(void) const
Definition: ov.h:1626
octave_value xisalpha(void) const
Definition: ov.h:1620
octave_value xisupper(void) const
Definition: ov.h:1629
Cell cell_value(void) const
octave_value xispunct(void) const
Definition: ov.h:1627
octave_value xisalnum(void) const
Definition: ov.h:1619
octave_value xisdigit(void) const
Definition: ov.h:1623
octave_value xtolower(void) const
Definition: ov.h:1632
octave_value xisspace(void) const
Definition: ov.h:1628
octave_value xtoupper(void) const
Definition: ov.h:1633
F77_RET_T const F77_INT const F77_INT const F77_INT const F77_DBLE const F77_DBLE F77_INT F77_DBLE * V
class OCTAVE_API boolMatrix
Definition: mx-fwd.h:35
T octave_idx_type m
Definition: mx-inlines.cc:773
octave_idx_type n
Definition: mx-inlines.cc:753
T * r
Definition: mx-inlines.cc:773
const octave_base_value const Array< octave_idx_type > & ra_idx
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
Definition: ovl.h:211