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