Mercurial > hg > octave-lyh
annotate src/ov-struct.h @ 7635:ba7a3e20ee3d
add -struct modifier to save
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Tue, 25 Mar 2008 15:29:26 -0400 |
parents | c195bd0a5c64 |
children | 443a8f5a50fd |
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 |
4994 | 68 octave_value subsref (const std::string&, |
7622
c195bd0a5c64
treat structs and cells as "constants"
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
69 const std::list<octave_value_list>&); |
c195bd0a5c64
treat structs and cells as "constants"
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
70 |
c195bd0a5c64
treat structs and cells as "constants"
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
71 octave_value_list subsref (const std::string&, |
c195bd0a5c64
treat structs and cells as "constants"
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
72 const std::list<octave_value_list>&, int) |
4271 | 73 { |
74 panic_impossible (); | |
75 return octave_value_list (); | |
76 } | |
77 | |
4994 | 78 |
4513 | 79 static octave_value numeric_conv (const Cell& val, |
3933 | 80 const std::string& type); |
2376 | 81 |
4247 | 82 octave_value subsasgn (const std::string& type, |
4219 | 83 const std::list<octave_value_list>& idx, |
3933 | 84 const octave_value& rhs); |
2376 | 85 |
7046 | 86 octave_value squeeze (void) const { return map.squeeze (); } |
87 | |
88 octave_value permute (const Array<int>& vec, bool inv = false) const | |
89 { return map.permute (vec, inv); } | |
90 | |
91 octave_value do_index_op (const octave_value_list& idx, | |
92 bool resize_ok = false); | |
93 | |
4563 | 94 dim_vector dims (void) const { return map.dims (); } |
4200 | 95 |
4791 | 96 size_t byte_size (void) const; |
97 | |
5900 | 98 // This is the number of elements in each field. The total number |
99 // of elements is numel () * nfields (). | |
100 octave_idx_type numel (void) const | |
101 { | |
102 dim_vector dv = dims (); | |
103 return dv.numel (); | |
104 } | |
105 | |
6639 | 106 octave_idx_type nfields (void) const { return map.nfields (); } |
5900 | 107 |
4567 | 108 octave_value reshape (const dim_vector& new_dims) const |
109 { return map.reshape (new_dims); } | |
110 | |
5888 | 111 octave_value resize (const dim_vector& dv, bool = false) const |
5781 | 112 { Octave_map tmap = map; tmap.resize (dv); return tmap; } |
4936 | 113 |
2376 | 114 bool is_defined (void) const { return true; } |
115 | |
7622
c195bd0a5c64
treat structs and cells as "constants"
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
116 bool is_constant (void) const { return true; } |
c195bd0a5c64
treat structs and cells as "constants"
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
117 |
2376 | 118 bool is_map (void) const { return true; } |
119 | |
120 Octave_map map_value (void) const { return map; } | |
121 | |
3933 | 122 string_vector map_keys (void) const { return map.keys (); } |
123 | |
3523 | 124 void print (std::ostream& os, bool pr_as_read_syntax = false) const; |
2901 | 125 |
3523 | 126 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; |
2901 | 127 |
3523 | 128 bool print_name_tag (std::ostream& os, const std::string& name) const; |
2376 | 129 |
6974 | 130 bool save_ascii (std::ostream& os); |
4687 | 131 |
132 bool load_ascii (std::istream& is); | |
133 | |
134 bool save_binary (std::ostream& os, bool& save_as_floats); | |
135 | |
136 bool load_binary (std::istream& is, bool swap, | |
137 oct_mach_info::float_format fmt); | |
138 | |
139 #if defined (HAVE_HDF5) | |
140 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); | |
141 | |
142 bool load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug); | |
143 #endif | |
144 | |
5900 | 145 mxArray *as_mxArray (void) const; |
146 | |
7336 | 147 protected: |
2376 | 148 |
2477 | 149 // The associative array used to manage the structure data. |
2376 | 150 Octave_map map; |
151 | |
7336 | 152 private: |
153 | |
3219 | 154 DECLARE_OCTAVE_ALLOCATOR |
2477 | 155 |
3219 | 156 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2376 | 157 }; |
158 | |
159 #endif | |
160 | |
161 /* | |
162 ;;; Local Variables: *** | |
163 ;;; mode: C++ *** | |
164 ;;; End: *** | |
165 */ |