Mercurial > hg > octave-nkf
annotate src/ov-cell.h @ 11217:521373e25613
correctly parse {1 2 {3 4}}
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 09 Nov 2010 18:12:17 -0500 |
parents | 604e13a89c7f |
children | fd0a3ac60b0e |
rev | line source |
---|---|
3353 | 1 /* |
2 | |
8920 | 3 Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 |
7017 | 4 John W. Eaton |
10521
4d1fc073fbb7
add some missing copyright stmts
Jaroslav Hajek <highegg@gmail.com>
parents:
10313
diff
changeset
|
5 Copyright (C) 2009, 2010 VZLU Prague |
3353 | 6 |
7 This file is part of Octave. | |
8 | |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
7016 | 11 Free Software Foundation; either version 3 of the License, or (at your |
12 option) any later version. | |
3353 | 13 |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
3353 | 22 |
23 */ | |
24 | |
25 #if !defined (octave_cell_h) | |
26 #define octave_cell_h 1 | |
27 | |
28 #include <cstdlib> | |
29 | |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
30 #include <iosfwd> |
3353 | 31 #include <string> |
10065
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9881
diff
changeset
|
32 #include <memory> |
3353 | 33 |
34 #include "mx-base.h" | |
35 #include "oct-alloc.h" | |
36 #include "str-vec.h" | |
37 | |
38 #include "Cell.h" | |
39 #include "error.h" | |
3928 | 40 #include "ov-base-mat.h" |
3353 | 41 #include "ov-typeinfo.h" |
42 | |
43 class octave_value_list; | |
44 | |
45 class tree_walker; | |
46 | |
47 // Cells. | |
48 | |
49 class | |
3928 | 50 octave_cell : public octave_base_matrix<Cell> |
3353 | 51 { |
52 public: | |
53 | |
54 octave_cell (void) | |
3928 | 55 : octave_base_matrix<Cell> () { } |
3353 | 56 |
57 octave_cell (const Cell& c) | |
3928 | 58 : octave_base_matrix<Cell> (c) { } |
3353 | 59 |
8825
c3445f1c8cb4
reuse cellstr cache in strcmp
Jaroslav Hajek <highegg@gmail.com>
parents:
8823
diff
changeset
|
60 octave_cell (const Array<std::string>& str) |
10065
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9881
diff
changeset
|
61 : octave_base_matrix<Cell> (Cell (str)), cellstr_cache (new Array<std::string> (str)) { } |
8825
c3445f1c8cb4
reuse cellstr cache in strcmp
Jaroslav Hajek <highegg@gmail.com>
parents:
8823
diff
changeset
|
62 |
3353 | 63 octave_cell (const octave_cell& c) |
3928 | 64 : octave_base_matrix<Cell> (c) { } |
3353 | 65 |
66 ~octave_cell (void) { } | |
67 | |
5759 | 68 octave_base_value *clone (void) const { return new octave_cell (*this); } |
69 octave_base_value *empty_clone (void) const { return new octave_cell (); } | |
3353 | 70 |
3928 | 71 #if 0 |
5759 | 72 octave_base_value *try_narrowing_conversion (void); |
3928 | 73 #endif |
74 | |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7622
diff
changeset
|
75 octave_value subsref (const std::string& type, |
10313 | 76 const std::list<octave_value_list>& idx) |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7622
diff
changeset
|
77 { |
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7622
diff
changeset
|
78 octave_value_list tmp = subsref (type, idx, 1); |
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7622
diff
changeset
|
79 return tmp.length () > 0 ? tmp(0) : octave_value (); |
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7622
diff
changeset
|
80 } |
7622
c195bd0a5c64
treat structs and cells as "constants"
John W. Eaton <jwe@octave.org>
parents:
7530
diff
changeset
|
81 |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7622
diff
changeset
|
82 octave_value_list subsref (const std::string& type, |
10313 | 83 const std::list<octave_value_list>& idx, int); |
4271 | 84 |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
7651
diff
changeset
|
85 octave_value subsref (const std::string& type, |
10313 | 86 const std::list<octave_value_list>& idx, |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
7651
diff
changeset
|
87 bool auto_add); |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
7651
diff
changeset
|
88 |
4247 | 89 octave_value subsasgn (const std::string& type, |
10313 | 90 const std::list<octave_value_list>& idx, |
91 const octave_value& rhs); | |
3933 | 92 |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
93 void assign (const octave_value_list& idx, const Cell& rhs); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
94 |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
95 void assign (const octave_value_list& idx, const octave_value& rhs); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
96 |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
97 void delete_elements (const octave_value_list& idx); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
98 |
4791 | 99 size_t byte_size (void) const; |
100 | |
8732 | 101 octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const; |
102 | |
103 octave_value sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0, | |
10313 | 104 sortmode mode = ASCENDING) const; |
8732 | 105 |
8823
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
106 sortmode is_sorted (sortmode mode = UNSORTED) const; |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
107 |
8733
3ef774603887
rename all uses of sortrows_idx to sort_rows_idx
John W. Eaton <jwe@octave.org>
parents:
8732
diff
changeset
|
108 Array<octave_idx_type> sort_rows_idx (sortmode mode = ASCENDING) const; |
8732 | 109 |
8823
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
110 sortmode is_sorted_rows (sortmode mode = UNSORTED) const; |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
111 |
4645 | 112 bool is_matrix_type (void) const { return false; } |
113 | |
4370 | 114 bool is_numeric_type (void) const { return false; } |
115 | |
3928 | 116 bool is_defined (void) const { return true; } |
3353 | 117 |
7622
c195bd0a5c64
treat structs and cells as "constants"
John W. Eaton <jwe@octave.org>
parents:
7530
diff
changeset
|
118 bool is_constant (void) const { return true; } |
4994 | 119 |
3724 | 120 bool is_cell (void) const { return true; } |
121 | |
10087
090173f2db40
improve overload dispatching of built-in classes
Jaroslav Hajek <highegg@gmail.com>
parents:
10065
diff
changeset
|
122 builtin_type_t builtin_type (void) const { return btyp_cell; } |
090173f2db40
improve overload dispatching of built-in classes
Jaroslav Hajek <highegg@gmail.com>
parents:
10065
diff
changeset
|
123 |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
124 bool is_cellstr (void) const; |
6116 | 125 |
8626
1dce30ab0e72
don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents:
8551
diff
changeset
|
126 bool is_true (void) const; |
1dce30ab0e72
don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents:
8551
diff
changeset
|
127 |
3928 | 128 Cell cell_value (void) const { return matrix; } |
3353 | 129 |
3933 | 130 octave_value_list list_value (void) const; |
131 | |
5715 | 132 octave_value convert_to_str_internal (bool pad, bool, char type) const |
133 { return octave_value (all_strings (pad), type); } | |
4358 | 134 |
5715 | 135 string_vector all_strings (bool pad = false) const; |
4243 | 136 |
8732 | 137 Array<std::string> cellstr_value (void) const; |
138 | |
4604 | 139 bool print_as_scalar (void) const; |
140 | |
3933 | 141 void print (std::ostream& os, bool pr_as_read_syntax = false) const; |
142 | |
143 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; | |
144 | |
4687 | 145 |
6974 | 146 bool save_ascii (std::ostream& os); |
4687 | 147 |
148 bool load_ascii (std::istream& is); | |
149 | |
150 bool save_binary (std::ostream& os, bool& save_as_floats); | |
151 | |
152 bool load_binary (std::istream& is, bool swap, | |
10313 | 153 oct_mach_info::float_format fmt); |
4687 | 154 |
155 #if defined (HAVE_HDF5) | |
156 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); | |
157 | |
9881
b3089dba88bf
Remove HDF5 cruft for older versions of HDF5
Kacper Kowalik
parents:
9813
diff
changeset
|
158 bool load_hdf5 (hid_t loc_id, const char *name); |
4687 | 159 #endif |
160 | |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
161 octave_value map (unary_mapper_t umap) const; |
7530
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
162 |
5900 | 163 mxArray *as_mxArray (void) const; |
164 | |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
165 // Unsafe. This function exists to support the MEX interface. |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
166 // You should not use it anywhere else. |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
167 void *mex_get_data (void) const; |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
168 |
3353 | 169 private: |
4612 | 170 |
10065
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9881
diff
changeset
|
171 void clear_cellstr_cache (void) const |
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9881
diff
changeset
|
172 { cellstr_cache.reset (); } |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
173 |
10065
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
9881
diff
changeset
|
174 mutable std::auto_ptr<Array<std::string> > cellstr_cache; |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
175 |
3353 | 176 DECLARE_OCTAVE_ALLOCATOR |
177 | |
178 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA | |
179 }; | |
180 | |
181 #endif |