GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Cell.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1999-2024 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 () = default;
47 
48  Cell (const Cell& c) = default;
49 
50  Cell& operator = (const Cell& c) = default;
51 
52  ~Cell () = 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 () const;
101 
102  Array<std::string> cellstr_value () const;
103 
104  string_vector string_vector_value () 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 () 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 () const { return false; }
139  bool is_true () const { return false; }
140 
141  octave_value resize_fill_value () 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 () const { return map (&octave_value::xisalnum); }
148  Cell xisalpha () const { return map (&octave_value::xisalpha); }
149  Cell xisascii () const { return map (&octave_value::xisascii); }
150  Cell xiscntrl () const { return map (&octave_value::xiscntrl); }
151  Cell xisdigit () const { return map (&octave_value::xisdigit); }
152  Cell xisgraph () const { return map (&octave_value::xisgraph); }
153  Cell xislower () const { return map (&octave_value::xislower); }
154  Cell xisprint () const { return map (&octave_value::xisprint); }
155  Cell xispunct () const { return map (&octave_value::xispunct); }
156  Cell xisspace () const { return map (&octave_value::xisspace); }
157  Cell xisupper () const { return map (&octave_value::xisupper); }
158  Cell xisxdigit () const { return map (&octave_value::xisxdigit); }
159  Cell xtolower () const { return map (&octave_value::xtolower); }
160  Cell xtoupper () const { return map (&octave_value::xtoupper); }
161 
162 private:
163 
164  typedef octave_value (octave_value::*ctype_mapper) () 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
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 xisspace() const
Definition: Cell.h:156
Cell xisupper() const
Definition: Cell.h:157
Cell xisprint() const
Definition: Cell.h:154
Cell xislower() const
Definition: Cell.h:153
bool any_element_is_nan() const
Definition: Cell.h:138
Cell xisdigit() const
Definition: Cell.h:151
Cell(const Array< octave_value > &c)
Definition: Cell.h:66
Cell(const Cell &c)=default
Cell xtolower() const
Definition: Cell.h:159
Cell reshape(const dim_vector &new_dims) const
Definition: Cell.h:119
~Cell()=default
Cell xtoupper() const
Definition: Cell.h:160
Cell xisxdigit() const
Definition: Cell.h:158
Cell()=default
Cell(octave_idx_type n, octave_idx_type m, const octave_value &val=Matrix())
Definition: Cell.h:59
Cell(const C< V > &container)
Definition: Cell.h:78
Cell xiscntrl() const
Definition: Cell.h:150
Cell(const dim_vector &dv, const octave_value &val=Matrix())
Definition: Cell.h:63
Cell xisalpha() const
Definition: Cell.h:148
Cell xisgraph() const
Definition: Cell.h:152
boolMatrix all(int=0) const
Definition: Cell.h:127
Cell xisalnum() const
Definition: Cell.h:147
bool is_true() const
Definition: Cell.h:139
Cell(const octave_value &val)
Definition: Cell.h:54
Cell xispunct() const
Definition: Cell.h:155
Cell xisascii() const
Definition: Cell.h:149
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 xisgraph() const
Definition: ov.h:1500
Cell cell_value() const
octave_value xispunct() const
Definition: ov.h:1503
octave_value xtolower() const
Definition: ov.h:1508
octave_value xisdigit() const
Definition: ov.h:1499
octave_value xisascii() const
Definition: ov.h:1497
octave_value xisalpha() const
Definition: ov.h:1496
octave_value xisalnum() const
Definition: ov.h:1495
octave_value xisxdigit() const
Definition: ov.h:1506
octave_value xisprint() const
Definition: ov.h:1502
octave_value xtoupper() const
Definition: ov.h:1509
octave_value xisspace() const
Definition: ov.h:1504
octave_value xisupper() const
Definition: ov.h:1505
octave_value xiscntrl() const
Definition: ov.h:1498
octave_value xislower() const
Definition: ov.h:1501
F77_RET_T const F77_INT const F77_INT const F77_INT const F77_DBLE const F77_DBLE F77_INT F77_DBLE * V
T octave_idx_type m
Definition: mx-inlines.cc:781
octave_idx_type n
Definition: mx-inlines.cc:761
T * r
Definition: mx-inlines.cc:781
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:219