GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ov-cell.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1999-2015 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 the
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 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 <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #if !defined (octave_ov_cell_h)
25 #define octave_ov_cell_h 1
26 
27 #include <cstdlib>
28 
29 #include <iosfwd>
30 #include <string>
31 #include <memory>
32 
33 #include "mx-base.h"
34 #include "str-vec.h"
35 
36 #include "Cell.h"
37 #include "error.h"
38 #include "ov-base-mat.h"
39 #include "ov-typeinfo.h"
40 
41 class octave_value_list;
42 
43 class tree_walker;
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 
59  : octave_base_matrix<Cell> (Cell (str)),
60  cellstr_cache (new Array<std::string> (str)) { }
61 
63  : octave_base_matrix<Cell> (c), cellstr_cache () { }
64 
65  ~octave_cell (void) { }
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 
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  return subsref (type, idx, nargout, 0);
86  }
87 
88  octave_value_list subsref (const std::string& type,
89  const std::list<octave_value_list>& idx,
90  int nargout,
91  const std::list<octave_lvalue> *lvalue_list);
92 
93  octave_value subsref (const std::string& type,
94  const std::list<octave_value_list>& idx,
95  bool auto_add);
96 
97  octave_value subsasgn (const std::string& type,
98  const std::list<octave_value_list>& idx,
99  const octave_value& rhs);
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  size_t byte_size (void) const;
108 
109  octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const;
110 
112  sortmode mode = ASCENDING) const;
113 
114  sortmode is_sorted (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 (void) const { return false; }
121 
122  bool is_numeric_type (void) const { return false; }
123 
124  bool is_defined (void) const { return true; }
125 
126  bool is_constant (void) const { return true; }
127 
128  bool is_cell (void) const { return true; }
129 
130  builtin_type_t builtin_type (void) const { return btyp_cell; }
131 
132  bool is_cellstr (void) const;
133 
134  bool is_true (void) const;
135 
136  Cell cell_value (void) const { return matrix; }
137 
138  octave_value_list list_value (void) const;
139 
140  octave_value convert_to_str_internal (bool pad, bool, char type) const
141  { return octave_value (all_strings (pad), type); }
142 
143  string_vector all_strings (bool pad = false) const;
144 
145  Array<std::string> cellstr_value (void) const;
146 
147  bool print_as_scalar (void) const;
148 
149  void print (std::ostream& os, bool pr_as_read_syntax = false);
150 
151  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
152 
153  void short_disp (std::ostream& os) const;
154 
155  bool save_ascii (std::ostream& os);
156 
157  bool load_ascii (std::istream& is);
158 
159  bool save_binary (std::ostream& os, bool& save_as_floats);
160 
161  bool load_binary (std::istream& is, bool swap,
163 
164  bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
165 
166  bool load_hdf5 (octave_hdf5_id loc_id, const char *name);
167 
168  octave_value map (unary_mapper_t umap) const;
169 
170  mxArray *as_mxArray (void) const;
171 
172  // Unsafe. This function exists to support the MEX interface.
173  // You should not use it anywhere else.
174  void *mex_get_data (void) const;
175 
176 private:
177 
178  void clear_cellstr_cache (void) const
179  { cellstr_cache.reset (); }
180 
181  mutable std::auto_ptr<Array<std::string> > cellstr_cache;
182 
183 
185 };
186 
187 #endif
octave_value_list subsref(const std::string &type, const std::list< octave_value_list > &idx, int nargout)
Definition: ov-cell.h:81
octave_cell(const Array< std::string > &str)
Definition: ov-cell.h:58
bool is_true(const std::string &s)
Definition: mkoctfile.cc:373
~octave_cell(void)
Definition: ov-cell.h:65
Definition: Cell.h:35
bool is_numeric_type(void) const
Definition: ov-cell.h:122
sortmode
Definition: oct-sort.h:103
octave_idx_type length(void) const
Definition: oct-obj.h:89
Cell cell_value(void) const
Definition: ov-cell.h:136
STL namespace.
std::auto_ptr< Array< std::string > > cellstr_cache
Definition: ov-cell.h:181
octave_cell(const Cell &c)
Definition: ov-cell.h:55
builtin_type_t
Definition: ov-base.h:59
octave_cell(const octave_cell &c)
Definition: ov-cell.h:62
bool is_constant(void) const
Definition: ov-cell.h:126
octave_value convert_to_str_internal(bool pad, bool, char type) const
Definition: ov-cell.h:140
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
Definition: ov-base.h:142
bool is_cell(void) const
Definition: ov-cell.h:128
bool is_defined(void) const
Definition: ov-cell.h:124
void clear_cellstr_cache(void) const
Definition: ov-cell.h:178
builtin_type_t builtin_type(void) const
Definition: ov-cell.h:130
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
Definition: ov-cell.h:74
octave_cell(void)
Definition: ov-cell.h:52
octave_base_value * empty_clone(void) const
Definition: ov-cell.h:68
octave_base_value * clone(void) const
Definition: ov-cell.h:67
bool is_matrix_type(void) const
Definition: ov-cell.h:120
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))