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&, |
|
69 const std::list<octave_value_list>&) |
4271
|
70 { |
|
71 panic_impossible (); |
|
72 return octave_value_list (); |
|
73 } |
|
74 |
4994
|
75 octave_value_list subsref (const std::string& type, |
|
76 const std::list<octave_value_list>& idx, |
|
77 int nargout); |
|
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 |
4563
|
86 dim_vector dims (void) const { return map.dims (); } |
4200
|
87 |
4791
|
88 size_t byte_size (void) const; |
|
89 |
5900
|
90 // This is the number of elements in each field. The total number |
|
91 // of elements is numel () * nfields (). |
|
92 octave_idx_type numel (void) const |
|
93 { |
|
94 dim_vector dv = dims (); |
|
95 return dv.numel (); |
|
96 } |
|
97 |
6639
|
98 octave_idx_type nfields (void) const { return map.nfields (); } |
5900
|
99 |
4567
|
100 octave_value reshape (const dim_vector& new_dims) const |
|
101 { return map.reshape (new_dims); } |
|
102 |
5888
|
103 octave_value resize (const dim_vector& dv, bool = false) const |
5781
|
104 { Octave_map tmap = map; tmap.resize (dv); return tmap; } |
4936
|
105 |
2376
|
106 bool is_defined (void) const { return true; } |
|
107 |
|
108 bool is_map (void) const { return true; } |
|
109 |
|
110 Octave_map map_value (void) const { return map; } |
|
111 |
3933
|
112 string_vector map_keys (void) const { return map.keys (); } |
|
113 |
3523
|
114 void print (std::ostream& os, bool pr_as_read_syntax = false) const; |
2901
|
115 |
3523
|
116 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; |
2901
|
117 |
3523
|
118 bool print_name_tag (std::ostream& os, const std::string& name) const; |
2376
|
119 |
6974
|
120 bool save_ascii (std::ostream& os); |
4687
|
121 |
|
122 bool load_ascii (std::istream& is); |
|
123 |
|
124 bool save_binary (std::ostream& os, bool& save_as_floats); |
|
125 |
|
126 bool load_binary (std::istream& is, bool swap, |
|
127 oct_mach_info::float_format fmt); |
|
128 |
|
129 #if defined (HAVE_HDF5) |
|
130 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); |
|
131 |
|
132 bool load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug); |
|
133 #endif |
|
134 |
5900
|
135 mxArray *as_mxArray (void) const; |
|
136 |
2376
|
137 private: |
|
138 |
2477
|
139 // The associative array used to manage the structure data. |
2376
|
140 Octave_map map; |
|
141 |
3219
|
142 DECLARE_OCTAVE_ALLOCATOR |
2477
|
143 |
3219
|
144 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2376
|
145 }; |
|
146 |
|
147 #endif |
|
148 |
|
149 /* |
|
150 ;;; Local Variables: *** |
|
151 ;;; mode: C++ *** |
|
152 ;;; End: *** |
|
153 */ |