GNU Octave  6.2.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-2021 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> (), cellstr_cache () { }
56 
57  octave_cell (const Cell& c)
58  : octave_base_matrix<Cell> (c), cellstr_cache () { }
59 
61  : octave_base_matrix<Cell> (Cell (str)),
62  cellstr_cache (new Array<std::string> (str)) { }
63 
65  : octave_base_matrix<Cell> (c), 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 #if 0
73  octave_base_value * try_narrowing_conversion (void);
74 #endif
75 
76  octave_value subsref (const std::string& type,
77  const std::list<octave_value_list>& idx)
78  {
79  octave_value_list tmp = subsref (type, idx, 1);
80  return tmp.length () > 0 ? tmp(0) : octave_value ();
81  }
82 
83  octave_value_list subsref (const std::string& type,
84  const std::list<octave_value_list>& idx,
85  int nargout);
86 
87  octave_value subsref (const std::string& type,
88  const std::list<octave_value_list>& idx,
89  bool auto_add);
90 
91  octave_value subsasgn (const std::string& type,
92  const std::list<octave_value_list>& idx,
93  const octave_value& rhs);
94 
95  // FIXME: should we import the functions from the base class and
96  // overload them here, or should we use a different name so we don't
97  // have to do this? Without the using declaration or a name change,
98  // the base class functions will be hidden. That may be OK, but it
99  // can also cause some confusion.
101 
102  void assign (const octave_value_list& idx, const Cell& rhs);
103 
104  void assign (const octave_value_list& idx, const octave_value& rhs);
105 
106  void delete_elements (const octave_value_list& idx);
107 
108  size_t byte_size (void) const;
109 
110  octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const;
111 
113  sortmode mode = ASCENDING) const;
114 
115  sortmode issorted (sortmode mode = UNSORTED) const;
116 
117  Array<octave_idx_type> sort_rows_idx (sortmode mode = ASCENDING) const;
118 
119  sortmode is_sorted_rows (sortmode mode = UNSORTED) const;
120 
121  bool is_matrix_type (void) const { return false; }
122 
123  bool isnumeric (void) const { return false; }
124 
125  bool is_defined (void) const { return true; }
126 
127  bool is_constant (void) const { return true; }
128 
129  bool iscell (void) const { return true; }
130 
131  builtin_type_t builtin_type (void) const { return btyp_cell; }
132 
133  bool iscellstr (void) const;
134 
135  bool is_true (void) const;
136 
137  Cell cell_value (void) const { return matrix; }
138 
139  octave_value_list list_value (void) 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 (void) const;
147 
148  Array<std::string> cellstr_value (const char *fmt, ...) const;
149 
150  bool print_as_scalar (void) 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 (void) const;
176 
177  // Unsafe. This function exists to support the MEX interface.
178  // You should not use it anywhere else.
179  void * mex_get_data (void) const;
180 
181 private:
182 
183  void clear_cellstr_cache (void) const
184  { cellstr_cache.reset (); }
185 
186  mutable std::unique_ptr<Array<std::string>> cellstr_cache;
187 
189 };
190 
191 #endif
Definition: Cell.h:43
virtual void assign(const std::string &, const octave_value &)
Definition: ov-base.h:302
Cell cell_value(void) const
Definition: ov-cell.h:137
builtin_type_t builtin_type(void) const
Definition: ov-cell.h:131
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:123
std::unique_ptr< Array< std::string > > cellstr_cache
Definition: ov-cell.h:186
octave_value convert_to_str_internal(bool pad, bool, char type) const
Definition: ov-cell.h:141
bool is_matrix_type(void) const
Definition: ov-cell.h:121
octave_base_value * empty_clone(void) const
Definition: ov-cell.h:70
void clear_cellstr_cache(void) const
Definition: ov-cell.h:183
bool is_constant(void) const
Definition: ov-cell.h:127
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
Definition: ov-cell.h:76
octave_cell(const Cell &c)
Definition: ov-cell.h:57
bool iscell(void) const
Definition: ov-cell.h:129
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:125
~octave_cell(void)=default
octave_idx_type length(void) const
Definition: ovl.h:113
QString name
bool is_true(const std::string &s)
int64_t octave_hdf5_id
sortmode
Definition: oct-sort.h:95
@ UNSORTED
Definition: oct-sort.h:95
@ ASCENDING
Definition: oct-sort.h:95
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:158
builtin_type_t
Definition: ov-base.h:72
@ btyp_cell
Definition: ov-base.h:88