GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
ov-cell.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1999-2025 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_ov_cell_h)
27#define octave_ov_cell_h 1
28
29#include "octave-config.h"
30
31#include <cstdlib>
32
33#include <iosfwd>
34#include <string>
35#include <memory>
36
37#include "mx-base.h"
38#include "str-vec.h"
39
40#include "Cell.h"
41#include "error.h"
42#include "ov-base-mat.h"
43#include "ov-typeinfo.h"
44
46
47// Cells.
48
49extern template class OCTINTERP_EXTERN_TEMPLATE_API octave_base_matrix<Cell>;
50
52{
53public:
54
56 : octave_base_matrix<Cell> (), m_cellstr_cache () { }
57
58 octave_cell (const Cell& c)
59 : octave_base_matrix<Cell> (c), m_cellstr_cache () { }
60
62 : octave_base_matrix<Cell> (Cell (str)),
63 m_cellstr_cache (new Array<std::string> (str)) { }
64
66 : octave_base_matrix<Cell> (c), m_cellstr_cache () { }
67
68 ~octave_cell () = default;
69
70 octave_base_value * clone () const { return new octave_cell (*this); }
71 octave_base_value * empty_clone () const { return new octave_cell (); }
72
73 void break_closure_cycles (const std::shared_ptr<octave::stack_frame>& frame);
74
75 octave_value subsref (const std::string& type,
76 const std::list<octave_value_list>& idx)
77 {
78 octave_value_list tmp = subsref (type, idx, 1);
79 return tmp.length () > 0 ? tmp(0) : octave_value ();
80 }
81
82 octave_value_list subsref (const std::string& type,
83 const std::list<octave_value_list>& idx,
84 int nargout);
85
86 octave_value subsref (const std::string& type,
87 const std::list<octave_value_list>& idx,
88 bool auto_add);
89
90 octave_value subsasgn (const std::string& type,
91 const std::list<octave_value_list>& idx,
92 const octave_value& rhs);
93
94 // FIXME: should we import the functions from the base class and
95 // overload them here, or should we use a different name so we don't
96 // have to do this? Without the using declaration or a name change,
97 // the base class functions will be hidden. That may be OK, but it
98 // can also cause some confusion.
100
101 void assign (const octave_value_list& idx, const Cell& rhs);
102
103 void assign (const octave_value_list& idx, const octave_value& rhs);
104
105 void delete_elements (const octave_value_list& idx);
106
107 std::size_t byte_size () const;
108
109 octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const;
110
112 sortmode mode = ASCENDING) const;
113
114 sortmode issorted (sortmode mode = UNSORTED) const;
115
116 Array<octave_idx_type> sort_rows_idx (sortmode mode = ASCENDING) const;
117
118 sortmode is_sorted_rows (sortmode mode = UNSORTED) const;
119
120 bool is_matrix_type () const { return false; }
121
122 bool isnumeric () const { return false; }
123
124 bool is_defined () const { return true; }
125
126 bool is_constant () const { return true; }
127
128 bool iscell () const { return true; }
129
131
132 bool iscellstr () const;
133
134 bool is_true () const;
135
136 bool is_full_num_matrix () const { return false; }
137
138 Cell cell_value () const { return m_matrix; }
139
140 octave_value_list list_value () const;
141
142 octave_value convert_to_str_internal (bool pad, bool, char type) const
143 { return octave_value (string_vector_value (pad), type); }
144
145 string_vector string_vector_value (bool pad = false) const;
146
147 Array<std::string> cellstr_value () const;
148
149 Array<std::string> cellstr_value (const char *fmt, ...) const;
150
151 bool print_as_scalar () const;
152
153 void print (std::ostream& os, bool pr_as_read_syntax = false);
154
155 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
156
157 bool print_name_tag (std::ostream& os, const std::string& name) const;
158
159 void short_disp (std::ostream& os) const;
160
161 bool save_ascii (std::ostream& os);
162
163 bool load_ascii (std::istream& is);
164
165 bool save_binary (std::ostream& os, bool save_as_floats);
166
167 bool load_binary (std::istream& is, bool swap,
168 octave::mach_info::float_format fmt);
169
170 bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
171
172 bool load_hdf5 (octave_hdf5_id loc_id, const char *name);
173
174 octave_value map (unary_mapper_t umap) const;
175
176 mxArray * as_mxArray (bool interleaved) const;
177
178 // This function exists to support the MEX interface.
179 // You should not use it anywhere else.
180 const void * mex_get_data () const;
181
183 simple_subsref (char type, octave_value_list& idx, int nargout);
184
185private:
186
187 void clear_cellstr_cache () const
188 { m_cellstr_cache.reset (); }
189
190 //--------
191
192 mutable std::unique_ptr<Array<std::string>> m_cellstr_cache;
193
195};
196
197#endif
N Dimensional Array with copy-on-write semantics.
Definition Array.h:130
Definition Cell.h:41
virtual void assign(const std::string &, const octave_value &)
Definition ov-base.h:363
octave_cell(const octave_cell &c)
Definition ov-cell.h:65
bool is_defined() const
Definition ov-cell.h:124
bool isnumeric() const
Definition ov-cell.h:122
bool is_constant() const
Definition ov-cell.h:126
builtin_type_t builtin_type() const
Definition ov-cell.h:130
bool is_matrix_type() const
Definition ov-cell.h:120
Cell cell_value() const
Definition ov-cell.h:138
octave_value convert_to_str_internal(bool pad, bool, char type) const
Definition ov-cell.h:142
~octave_cell()=default
bool is_full_num_matrix() const
Definition ov-cell.h:136
octave_base_value * clone() const
Definition ov-cell.h:70
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
Definition ov-cell.h:75
octave_cell(const Cell &c)
Definition ov-cell.h:58
octave_base_value * empty_clone() const
Definition ov-cell.h:71
octave_cell(const Array< std::string > &str)
Definition ov-cell.h:61
Array< std::string > cellstr_value(const char *fmt,...) const
bool iscell() const
Definition ov-cell.h:128
octave_cell()
Definition ov-cell.h:55
octave_idx_type length() const
Definition ovl.h:111
bool is_true(const std::string &s)
int64_t octave_hdf5_id
sortmode
Definition oct-sort.h:97
@ UNSORTED
Definition oct-sort.h:97
@ ASCENDING
Definition oct-sort.h:97
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA_API(API)
Definition ov-base.h:185
builtin_type_t
Definition ov-base.h:83
@ btyp_cell
Definition ov-base.h:99