GNU Octave  4.4.1
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-2018 John W. Eaton
4 Copyright (C) 2009-2010 VZLU Prague
5 
6 This file is part of Octave.
7 
8 Octave is free software: you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with Octave; see the file COPYING. If not, see
20 <https://www.gnu.org/licenses/>.
21 
22 */
23 
24 #if ! defined (octave_ov_cell_h)
25 #define octave_ov_cell_h 1
26 
27 #include "octave-config.h"
28 
29 #include <cstdlib>
30 
31 #include <iosfwd>
32 #include <string>
33 #include <memory>
34 
35 #include "mx-base.h"
36 #include "str-vec.h"
37 
38 #include "Cell.h"
39 #include "error.h"
40 #include "ov-base-mat.h"
41 #include "ov-typeinfo.h"
42 
43 class octave_value_list;
44 
45 // Cells.
46 
47 class
49 {
50 public:
51 
52  octave_cell (void)
53  : octave_base_matrix<Cell> (), cellstr_cache () { }
54 
55  octave_cell (const Cell& c)
56  : octave_base_matrix<Cell> (c), cellstr_cache () { }
57 
60  cellstr_cache (new Array<std::string> (str)) { }
61 
63  : octave_base_matrix<Cell> (c), cellstr_cache () { }
64 
65  ~octave_cell (void) = default;
66 
67  octave_base_value * clone (void) const { return new octave_cell (*this); }
68  octave_base_value * empty_clone (void) const { return new octave_cell (); }
69 
70 #if 0
71  octave_base_value * try_narrowing_conversion (void);
72 #endif
73 
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 
82  const std::list<octave_value_list>& idx,
83  int nargout);
84 
86  const std::list<octave_value_list>& idx,
87  bool auto_add);
88 
90  const std::list<octave_value_list>& idx,
91  const octave_value& rhs);
92 
93  void assign (const octave_value_list& idx, const Cell& rhs);
94 
95  void assign (const octave_value_list& idx, const octave_value& rhs);
96 
97  void delete_elements (const octave_value_list& idx);
98 
99  size_t byte_size (void) const;
100 
101  octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const;
102 
104  sortmode mode = ASCENDING) const;
105 
106  sortmode issorted (sortmode mode = UNSORTED) const;
107 
108  Array<octave_idx_type> sort_rows_idx (sortmode mode = ASCENDING) const;
109 
110  sortmode is_sorted_rows (sortmode mode = UNSORTED) const;
111 
112  bool is_matrix_type (void) const { return false; }
113 
114  bool isnumeric (void) const { return false; }
115 
116  bool is_defined (void) const { return true; }
117 
118  bool is_constant (void) const { return true; }
119 
120  bool iscell (void) const { return true; }
121 
122  builtin_type_t builtin_type (void) const { return btyp_cell; }
123 
124  bool iscellstr (void) const;
125 
126  bool is_true (void) const;
127 
128  Cell cell_value (void) const { return matrix; }
129 
130  octave_value_list list_value (void) const;
131 
132  octave_value convert_to_str_internal (bool pad, bool, char type) const
133  { return octave_value (string_vector_value (pad), type); }
134 
135  string_vector string_vector_value (bool pad = false) const;
136 
137  Array<std::string> cellstr_value (void) const;
138 
139  Array<std::string> cellstr_value (const char *fmt, ...) const;
140 
141  bool print_as_scalar (void) const;
142 
143  void print (std::ostream& os, bool pr_as_read_syntax = false);
144 
145  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
146 
147  bool print_name_tag (std::ostream& os, const std::string& name) const;
148 
149  void short_disp (std::ostream& os) const;
150 
151  bool save_ascii (std::ostream& os);
152 
153  bool load_ascii (std::istream& is);
154 
155  bool save_binary (std::ostream& os, bool& save_as_floats);
156 
157  bool load_binary (std::istream& is, bool swap,
159 
160  bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
161 
162  bool load_hdf5 (octave_hdf5_id loc_id, const char *name);
163 
164  octave_value map (unary_mapper_t umap) const;
165 
166  mxArray * as_mxArray (void) const;
167 
168  // Unsafe. This function exists to support the MEX interface.
169  // You should not use it anywhere else.
170  void * mex_get_data (void) const;
171 
172 private:
173 
174  void clear_cellstr_cache (void) const
175  { cellstr_cache.reset (); }
176 
177  mutable std::unique_ptr<Array<std::string>> cellstr_cache;
178 
180 };
181 
182 #endif
octave_cell(const Array< std::string > &str)
Definition: ov-cell.h:58
Definition: Cell.h:37
octave_base_value * empty_clone(void) const
Definition: ov-cell.h:68
characters Given a string matrix
Definition: hex2num.cc:155
sortmode
Definition: oct-sort.h:105
Return the CPU time used by your Octave session The first output is the total time spent executing your process and is equal to the sum of second and third which are the number of CPU seconds spent executing in user mode and the number of CPU seconds spent executing in system mode
Definition: data.cc:6348
idx subsref(val, idx) esult
Definition: ov.cc:3065
STL namespace.
Cell cell_value(void) const
Definition: ov-cell.h:128
octave_cell(const Cell &c)
Definition: ov-cell.h:55
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
Definition: file-io.cc:587
builtin_type_t
Definition: ov-base.h:71
octave_cell(const octave_cell &c)
Definition: ov-cell.h:62
bool swap
Definition: load-save.cc:738
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
Definition: ov-base.h:158
nd deftypefn *std::string name
Definition: sysdep.cc:647
octave_value convert_to_str_internal(bool pad, bool, char type) const
Definition: ov-cell.h:132
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
Definition: ov-usr-fcn.cc:997
bool isnumeric(void) const
Definition: ov-cell.h:114
std::string str
Definition: hash.cc:118
bool save_as_floats
Definition: load-save.cc:1617
double tmp
Definition: data.cc:6252
bool is_true(const std::string &s)
int64_t octave_hdf5_id
idx type
Definition: ov.cc:3114
bool is_defined(void) const
Definition: ov-cell.h:116
builtin_type_t builtin_type(void) const
Definition: ov-cell.h:122
OCTAVE_EXPORT octave_value_list iscellstr
Definition: ov-cell.cc:1220
std::unique_ptr< Array< std::string > > cellstr_cache
Definition: ov-cell.h:177
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
Definition: ov-cell.h:74
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
octave_cell(void)
Definition: ov-cell.h:52
void clear_cellstr_cache(void) const
Definition: ov-cell.h:174
octave_map map(dims)
idx subsasgn(val, idx, 0) esult
Definition: ov.cc:3114
bool is_constant(void) const
Definition: ov-cell.h:118
bool iscell(void) const
Definition: ov-cell.h:120
write the output to stdout if nargout is
Definition: load-save.cc:1612
bool is_matrix_type(void) const
Definition: ov-cell.h:112
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
octave::stream os
Definition: file-io.cc:627
octave_base_value * clone(void) const
Definition: ov-cell.h:67