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