comparison libinterp/octave-value/ov-struct.h @ 15195:2fc554ffbc28

split libinterp from src * libinterp: New directory. Move all files from src directory here except Makefile.am, main.cc, main-cli.cc, mkoctfile.in.cc, mkoctfilr.in.sh, octave-config.in.cc, octave-config.in.sh. * libinterp/Makefile.am: New file, extracted from src/Makefile.am. * src/Makefile.am: Delete everything except targets and definitions needed to build and link main and utility programs. * Makefile.am (SUBDIRS): Include libinterp in the list. * autogen.sh: Run config-module.sh in libinterp/dldfcn directory, not src/dldfcn directory. * configure.ac (AC_CONFIG_SRCDIR): Use libinterp/octave.cc, not src/octave.cc. (DL_LDFLAGS, LIBOCTINTERP): Use libinterp, not src. (AC_CONFIG_FILES): Include libinterp/Makefile in the list. * find-docstring-files.sh: Look in libinterp, not src. * gui/src/Makefile.am (liboctgui_la_CPPFLAGS): Find header files in libinterp, not src.
author John W. Eaton <jwe@octave.org>
date Sat, 18 Aug 2012 16:23:39 -0400
parents src/octave-value/ov-struct.h@46b19589b593
children
comparison
equal deleted inserted replaced
15194:0f0b795044c3 15195:2fc554ffbc28
1 /*
2
3 Copyright (C) 1996-2012 John W. Eaton
4
5 This file is part of Octave.
6
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20
21 */
22
23 #if !defined (octave_struct_h)
24 #define octave_struct_h 1
25
26 #include <cstdlib>
27
28 #include <iosfwd>
29 #include <string>
30
31 #include "mx-base.h"
32 #include "str-vec.h"
33
34 #include "error.h"
35 #include "oct-alloc.h"
36 #include "oct-map.h"
37 #include "ov-base.h"
38 #include "ov-typeinfo.h"
39
40 class octave_value_list;
41
42 class tree_walker;
43
44 // Data structures.
45
46 class
47 octave_struct : public octave_base_value
48 {
49 public:
50
51 octave_struct (void)
52 : octave_base_value (), map () { }
53
54 octave_struct (const octave_map& m)
55 : octave_base_value (), map (m) { }
56
57 octave_struct (const octave_struct& s)
58 : octave_base_value (), map (s.map) { }
59
60 ~octave_struct (void) { }
61
62 octave_base_value *clone (void) const { return new octave_struct (*this); }
63 octave_base_value *empty_clone (void) const { return new octave_struct (); }
64
65 octave_base_value *try_narrowing_conversion (void);
66
67 Cell dotref (const octave_value_list& idx, bool auto_add = false);
68
69 octave_value subsref (const std::string& type,
70 const std::list<octave_value_list>& idx)
71 {
72 octave_value_list tmp = subsref (type, idx, 1);
73 return tmp.length () > 0 ? tmp(0) : octave_value ();
74 }
75
76 octave_value_list subsref (const std::string&,
77 const std::list<octave_value_list>&, int);
78
79 octave_value subsref (const std::string& type,
80 const std::list<octave_value_list>& idx,
81 bool auto_add);
82
83 static octave_value numeric_conv (const octave_value& val,
84 const std::string& type);
85
86 octave_value subsasgn (const std::string& type,
87 const std::list<octave_value_list>& idx,
88 const octave_value& rhs);
89
90 octave_value squeeze (void) const { return map.squeeze (); }
91
92 octave_value permute (const Array<int>& vec, bool inv = false) const
93 { return map.permute (vec, inv); }
94
95 octave_value do_index_op (const octave_value_list& idx,
96 bool resize_ok = false);
97
98 dim_vector dims (void) const { return map.dims (); }
99
100 size_t byte_size (void) const;
101
102 // This is the number of elements in each field. The total number
103 // of elements is numel () * nfields ().
104 octave_idx_type numel (void) const
105 {
106 return map.numel ();
107 }
108
109 octave_idx_type nfields (void) const { return map.nfields (); }
110
111 octave_value reshape (const dim_vector& new_dims) const
112 { return map.reshape (new_dims); }
113
114 octave_value resize (const dim_vector& dv, bool fill = false) const
115 { octave_map tmap = map; tmap.resize (dv, fill); return tmap; }
116
117 bool is_defined (void) const { return true; }
118
119 bool is_constant (void) const { return true; }
120
121 bool is_map (void) const { return true; }
122
123 builtin_type_t builtin_type (void) const { return btyp_struct; }
124
125 octave_map map_value (void) const { return map; }
126
127 string_vector map_keys (void) const { return map.fieldnames (); }
128
129 void print (std::ostream& os, bool pr_as_read_syntax = false) const;
130
131 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
132
133 bool print_name_tag (std::ostream& os, const std::string& name) const;
134
135 bool save_ascii (std::ostream& os);
136
137 bool load_ascii (std::istream& is);
138
139 bool save_binary (std::ostream& os, bool& save_as_floats);
140
141 bool load_binary (std::istream& is, bool swap,
142 oct_mach_info::float_format fmt);
143
144 #if defined (HAVE_HDF5)
145 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats);
146
147 bool load_hdf5 (hid_t loc_id, const char *name);
148 #endif
149
150 mxArray *as_mxArray (void) const;
151
152 octave_value
153 fast_elem_extract (octave_idx_type n) const;
154
155 bool
156 fast_elem_insert (octave_idx_type n, const octave_value& x);
157
158 protected:
159
160 // The associative array used to manage the structure data.
161 octave_map map;
162
163 private:
164
165 DECLARE_OCTAVE_ALLOCATOR
166
167 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
168 };
169
170 class
171 octave_scalar_struct : public octave_base_value
172 {
173 public:
174
175 octave_scalar_struct (void)
176 : octave_base_value (), map () { }
177
178 octave_scalar_struct (const octave_scalar_map& m)
179 : octave_base_value (), map (m) { }
180
181 octave_scalar_struct (const octave_scalar_struct& s)
182 : octave_base_value (), map (s.map) { }
183
184 ~octave_scalar_struct (void) { }
185
186 octave_base_value *clone (void) const { return new octave_scalar_struct (*this); }
187 octave_base_value *empty_clone (void) const { return new octave_scalar_struct (); }
188
189 octave_value dotref (const octave_value_list& idx, bool auto_add = false);
190
191 octave_value subsref (const std::string& type,
192 const std::list<octave_value_list>& idx);
193
194 octave_value_list subsref (const std::string& type,
195 const std::list<octave_value_list>& idx, int);
196
197
198 octave_value subsref (const std::string& type,
199 const std::list<octave_value_list>& idx,
200 bool auto_add);
201
202 static octave_value numeric_conv (const octave_value& val,
203 const std::string& type);
204
205 octave_value subsasgn (const std::string& type,
206 const std::list<octave_value_list>& idx,
207 const octave_value& rhs);
208
209 octave_value squeeze (void) const { return map; }
210
211 octave_value permute (const Array<int>& vec, bool inv = false) const
212 { return octave_map (map).permute (vec, inv); }
213
214 octave_value do_index_op (const octave_value_list& idx,
215 bool resize_ok = false);
216
217 dim_vector dims (void) const { static dim_vector dv (1, 1); return dv; }
218
219 size_t byte_size (void) const;
220
221 // This is the number of elements in each field. The total number
222 // of elements is numel () * nfields ().
223 octave_idx_type numel (void) const
224 {
225 return 1;
226 }
227
228 octave_idx_type nfields (void) const { return map.nfields (); }
229
230 octave_value reshape (const dim_vector& new_dims) const
231 { return octave_map (map).reshape (new_dims); }
232
233 octave_value resize (const dim_vector& dv, bool fill = false) const
234 { octave_map tmap = map; tmap.resize (dv, fill); return tmap; }
235
236 bool is_defined (void) const { return true; }
237
238 bool is_constant (void) const { return true; }
239
240 bool is_map (void) const { return true; }
241
242 builtin_type_t builtin_type (void) const { return btyp_struct; }
243
244 octave_map map_value (void) const { return map; }
245
246 octave_scalar_map scalar_map_value (void) const { return map; }
247
248 string_vector map_keys (void) const { return map.fieldnames (); }
249
250 void print (std::ostream& os, bool pr_as_read_syntax = false) const;
251
252 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
253
254 bool print_name_tag (std::ostream& os, const std::string& name) const;
255
256 bool save_ascii (std::ostream& os);
257
258 bool load_ascii (std::istream& is);
259
260 bool save_binary (std::ostream& os, bool& save_as_floats);
261
262 bool load_binary (std::istream& is, bool swap,
263 oct_mach_info::float_format fmt);
264
265 #if defined (HAVE_HDF5)
266 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats);
267
268 bool load_hdf5 (hid_t loc_id, const char *name);
269 #endif
270
271 mxArray *as_mxArray (void) const;
272
273 bool fast_elem_insert_self (void *where, builtin_type_t btyp) const;
274
275 protected:
276
277 // The associative array used to manage the structure data.
278 octave_scalar_map map;
279
280 private:
281
282 octave_value to_array (void);
283
284 DECLARE_OCTAVE_ALLOCATOR
285
286 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
287 };
288
289 #endif