Mercurial > hg > octave-lyh
annotate src/ov-struct.h @ 8546:3d8a914c580e
improve parser indexed assigment code
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Tue, 20 Jan 2009 21:15:17 +0100 |
parents | 443a8f5a50fd |
children | 906f976d35a8 |
rev | line source |
---|---|
2376 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 2000, 2002, 2003, 2004, 2005, 2006, |
4 2007 John W. Eaton | |
2376 | 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 | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2376 | 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 | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2376 | 21 |
22 */ | |
23 | |
24 #if !defined (octave_struct_h) | |
25 #define octave_struct_h 1 | |
26 | |
27 #include <cstdlib> | |
28 | |
3503 | 29 #include <iostream> |
2376 | 30 #include <string> |
31 | |
32 #include "mx-base.h" | |
33 #include "str-vec.h" | |
34 | |
35 #include "error.h" | |
2477 | 36 #include "oct-alloc.h" |
2376 | 37 #include "oct-map.h" |
38 #include "ov-base.h" | |
39 #include "ov-typeinfo.h" | |
40 | |
41 class octave_value_list; | |
42 | |
43 class tree_walker; | |
44 | |
2477 | 45 // Data structures. |
2376 | 46 |
47 class | |
48 octave_struct : public octave_base_value | |
49 { | |
50 public: | |
51 | |
52 octave_struct (void) | |
53 : octave_base_value () { } | |
54 | |
55 octave_struct (const Octave_map& m) | |
56 : octave_base_value (), map (m) { } | |
57 | |
58 octave_struct (const octave_struct& s) | |
59 : octave_base_value (), map (s.map) { } | |
60 | |
61 ~octave_struct (void) { } | |
62 | |
5759 | 63 octave_base_value *clone (void) const { return new octave_struct (*this); } |
64 octave_base_value *empty_clone (void) const { return new octave_struct (); } | |
3933 | 65 |
4513 | 66 Cell dotref (const octave_value_list& idx); |
2376 | 67 |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7622
diff
changeset
|
68 octave_value subsref (const std::string& type, |
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7622
diff
changeset
|
69 const std::list<octave_value_list>& idx) |
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7622
diff
changeset
|
70 { |
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7622
diff
changeset
|
71 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
|
72 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
|
73 } |
7622
c195bd0a5c64
treat structs and cells as "constants"
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
74 |
c195bd0a5c64
treat structs and cells as "constants"
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
75 octave_value_list subsref (const std::string&, |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7622
diff
changeset
|
76 const std::list<octave_value_list>&, int); |
4994 | 77 |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
7651
diff
changeset
|
78 static octave_value numeric_conv (const octave_value& val, |
3933 | 79 const std::string& type); |
2376 | 80 |
4247 | 81 octave_value subsasgn (const std::string& type, |
4219 | 82 const std::list<octave_value_list>& idx, |
3933 | 83 const octave_value& rhs); |
2376 | 84 |
7046 | 85 octave_value squeeze (void) const { return map.squeeze (); } |
86 | |
87 octave_value permute (const Array<int>& vec, bool inv = false) const | |
88 { return map.permute (vec, inv); } | |
89 | |
90 octave_value do_index_op (const octave_value_list& idx, | |
91 bool resize_ok = false); | |
92 | |
4563 | 93 dim_vector dims (void) const { return map.dims (); } |
4200 | 94 |
4791 | 95 size_t byte_size (void) const; |
96 | |
5900 | 97 // This is the number of elements in each field. The total number |
98 // of elements is numel () * nfields (). | |
99 octave_idx_type numel (void) const | |
100 { | |
101 dim_vector dv = dims (); | |
102 return dv.numel (); | |
103 } | |
104 | |
6639 | 105 octave_idx_type nfields (void) const { return map.nfields (); } |
5900 | 106 |
4567 | 107 octave_value reshape (const dim_vector& new_dims) const |
108 { return map.reshape (new_dims); } | |
109 | |
5888 | 110 octave_value resize (const dim_vector& dv, bool = false) const |
5781 | 111 { Octave_map tmap = map; tmap.resize (dv); return tmap; } |
4936 | 112 |
2376 | 113 bool is_defined (void) const { return true; } |
114 | |
7622
c195bd0a5c64
treat structs and cells as "constants"
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
115 bool is_constant (void) const { return true; } |
c195bd0a5c64
treat structs and cells as "constants"
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
116 |
2376 | 117 bool is_map (void) const { return true; } |
118 | |
119 Octave_map map_value (void) const { return map; } | |
120 | |
3933 | 121 string_vector map_keys (void) const { return map.keys (); } |
122 | |
3523 | 123 void print (std::ostream& os, bool pr_as_read_syntax = false) const; |
2901 | 124 |
3523 | 125 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; |
2901 | 126 |
3523 | 127 bool print_name_tag (std::ostream& os, const std::string& name) const; |
2376 | 128 |
6974 | 129 bool save_ascii (std::ostream& os); |
4687 | 130 |
131 bool load_ascii (std::istream& is); | |
132 | |
133 bool save_binary (std::ostream& os, bool& save_as_floats); | |
134 | |
135 bool load_binary (std::istream& is, bool swap, | |
136 oct_mach_info::float_format fmt); | |
137 | |
138 #if defined (HAVE_HDF5) | |
139 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); | |
140 | |
141 bool load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug); | |
142 #endif | |
143 | |
5900 | 144 mxArray *as_mxArray (void) const; |
145 | |
7336 | 146 protected: |
2376 | 147 |
2477 | 148 // The associative array used to manage the structure data. |
2376 | 149 Octave_map map; |
150 | |
7336 | 151 private: |
152 | |
3219 | 153 DECLARE_OCTAVE_ALLOCATOR |
2477 | 154 |
3219 | 155 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2376 | 156 }; |
157 | |
158 #endif | |
159 | |
160 /* | |
161 ;;; Local Variables: *** | |
162 ;;; mode: C++ *** | |
163 ;;; End: *** | |
164 */ |