Mercurial > hg > octave-lyh
annotate src/ov-struct.h @ 8950:d865363208d6
include <iosfwd> instead of <iostream> in header files
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 10 Mar 2009 13:55:52 -0400 |
parents | eb63fbe60fab |
children | e79470be3ecb |
rev | line source |
---|---|
2376 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 2000, 2002, 2003, 2004, 2005, 2006, |
8920 | 4 2007, 2008, 2009 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 | |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
29 #include <iosfwd> |
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 |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
66 Cell dotref (const octave_value_list& idx, bool auto_add = false); |
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 |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
78 octave_value subsref (const std::string& type, |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
79 const std::list<octave_value_list>& idx, |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
80 bool auto_add); |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
81 |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
7651
diff
changeset
|
82 static octave_value numeric_conv (const octave_value& val, |
3933 | 83 const std::string& type); |
2376 | 84 |
4247 | 85 octave_value subsasgn (const std::string& type, |
4219 | 86 const std::list<octave_value_list>& idx, |
3933 | 87 const octave_value& rhs); |
2376 | 88 |
7046 | 89 octave_value squeeze (void) const { return map.squeeze (); } |
90 | |
91 octave_value permute (const Array<int>& vec, bool inv = false) const | |
92 { return map.permute (vec, inv); } | |
93 | |
94 octave_value do_index_op (const octave_value_list& idx, | |
95 bool resize_ok = false); | |
96 | |
4563 | 97 dim_vector dims (void) const { return map.dims (); } |
4200 | 98 |
4791 | 99 size_t byte_size (void) const; |
100 | |
5900 | 101 // This is the number of elements in each field. The total number |
102 // of elements is numel () * nfields (). | |
103 octave_idx_type numel (void) const | |
104 { | |
105 dim_vector dv = dims (); | |
106 return dv.numel (); | |
107 } | |
108 | |
6639 | 109 octave_idx_type nfields (void) const { return map.nfields (); } |
5900 | 110 |
4567 | 111 octave_value reshape (const dim_vector& new_dims) const |
112 { return map.reshape (new_dims); } | |
113 | |
5888 | 114 octave_value resize (const dim_vector& dv, bool = false) const |
5781 | 115 { Octave_map tmap = map; tmap.resize (dv); return tmap; } |
4936 | 116 |
2376 | 117 bool is_defined (void) const { return true; } |
118 | |
7622
c195bd0a5c64
treat structs and cells as "constants"
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
119 bool is_constant (void) const { return true; } |
c195bd0a5c64
treat structs and cells as "constants"
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
120 |
2376 | 121 bool is_map (void) const { return true; } |
122 | |
123 Octave_map map_value (void) const { return map; } | |
124 | |
3933 | 125 string_vector map_keys (void) const { return map.keys (); } |
126 | |
3523 | 127 void print (std::ostream& os, bool pr_as_read_syntax = false) const; |
2901 | 128 |
3523 | 129 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; |
2901 | 130 |
3523 | 131 bool print_name_tag (std::ostream& os, const std::string& name) const; |
2376 | 132 |
6974 | 133 bool save_ascii (std::ostream& os); |
4687 | 134 |
135 bool load_ascii (std::istream& is); | |
136 | |
137 bool save_binary (std::ostream& os, bool& save_as_floats); | |
138 | |
139 bool load_binary (std::istream& is, bool swap, | |
140 oct_mach_info::float_format fmt); | |
141 | |
142 #if defined (HAVE_HDF5) | |
143 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); | |
144 | |
145 bool load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug); | |
146 #endif | |
147 | |
5900 | 148 mxArray *as_mxArray (void) const; |
149 | |
7336 | 150 protected: |
2376 | 151 |
2477 | 152 // The associative array used to manage the structure data. |
2376 | 153 Octave_map map; |
154 | |
7336 | 155 private: |
156 | |
3219 | 157 DECLARE_OCTAVE_ALLOCATOR |
2477 | 158 |
3219 | 159 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2376 | 160 }; |
161 | |
162 #endif | |
163 | |
164 /* | |
165 ;;; Local Variables: *** | |
166 ;;; mode: C++ *** | |
167 ;;; End: *** | |
168 */ |