GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ov-struct.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2015 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_ov_struct_h)
24 #define octave_ov_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-map.h"
36 #include "ov-base.h"
37 #include "ov-typeinfo.h"
38 
39 class octave_value_list;
40 
41 class tree_walker;
42 
43 // Data structures.
44 
45 class
47 {
48 public:
49 
51  : octave_base_value (), map () { }
52 
54  : octave_base_value (), map (m) { }
55 
57  : octave_base_value (), map (s.map) { }
58 
59  ~octave_struct (void) { }
60 
61  octave_base_value *clone (void) const { return new octave_struct (*this); }
62  octave_base_value *empty_clone (void) const { return new octave_struct (); }
63 
64  octave_base_value *try_narrowing_conversion (void);
65 
66  Cell dotref (const octave_value_list& idx, bool auto_add = false);
67 
68  octave_value subsref (const std::string& type,
69  const std::list<octave_value_list>& idx)
70  {
71  octave_value_list tmp = subsref (type, idx, 1);
72  return tmp.length () > 0 ? tmp(0) : octave_value ();
73  }
74 
75  octave_value_list subsref (const std::string&,
76  const std::list<octave_value_list>&, int);
77 
78  octave_value subsref (const std::string& type,
79  const std::list<octave_value_list>& idx,
80  bool auto_add);
81 
82  static octave_value numeric_conv (const octave_value& val,
83  const std::string& type);
84 
85  octave_value subsasgn (const std::string& type,
86  const std::list<octave_value_list>& idx,
87  const octave_value& rhs);
88 
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 
97  dim_vector dims (void) const { return map.dims (); }
98 
99  size_t byte_size (void) const;
100 
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  return map.numel ();
106  }
107 
108  octave_idx_type nfields (void) const { return map.nfields (); }
109 
110  octave_value reshape (const dim_vector& new_dims) const
111  { return map.reshape (new_dims); }
112 
113  octave_value resize (const dim_vector& dv, bool fill = false) const
114  { octave_map tmap = map; tmap.resize (dv, fill); return tmap; }
115 
116  bool is_defined (void) const { return true; }
117 
118  bool is_constant (void) const { return true; }
119 
120  bool is_map (void) const { return true; }
121 
122  builtin_type_t builtin_type (void) const { return btyp_struct; }
123 
124  octave_map map_value (void) const { return map; }
125 
126  string_vector map_keys (void) const { return map.fieldnames (); }
127 
128  void print (std::ostream& os, bool pr_as_read_syntax = false);
129 
130  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
131 
132  bool print_name_tag (std::ostream& os, const std::string& name) const;
133 
134  bool save_ascii (std::ostream& os);
135 
136  bool load_ascii (std::istream& is);
137 
138  bool save_binary (std::ostream& os, bool& save_as_floats);
139 
140  bool load_binary (std::istream& is, bool swap,
142 
143  bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
144 
145  bool load_hdf5 (octave_hdf5_id loc_id, const char *name);
146 
147  mxArray *as_mxArray (void) const;
148 
150  fast_elem_extract (octave_idx_type n) const;
151 
152  bool
153  fast_elem_insert (octave_idx_type n, const octave_value& x);
154 
155 protected:
156 
157  // The associative array used to manage the structure data.
159 
160 private:
161 
162 
164 };
165 
166 class
168 {
169 public:
170 
172  : octave_base_value (), map () { }
173 
175  : octave_base_value (), map (m) { }
176 
178  : octave_base_value (), map (s.map) { }
179 
181 
182  octave_base_value *clone (void) const
183  { return new octave_scalar_struct (*this); }
185  { return new octave_scalar_struct (); }
186 
187  octave_value dotref (const octave_value_list& idx, bool auto_add = false);
188 
189  octave_value subsref (const std::string& type,
190  const std::list<octave_value_list>& idx);
191 
192  octave_value_list subsref (const std::string& type,
193  const std::list<octave_value_list>& idx, int);
194 
195 
196  octave_value subsref (const std::string& type,
197  const std::list<octave_value_list>& idx,
198  bool auto_add);
199 
200  static octave_value numeric_conv (const octave_value& val,
201  const std::string& type);
202 
203  octave_value subsasgn (const std::string& type,
204  const std::list<octave_value_list>& idx,
205  const octave_value& rhs);
206 
207  octave_value squeeze (void) const { return map; }
208 
209  octave_value permute (const Array<int>& vec, bool inv = false) const
210  { return octave_map (map).permute (vec, inv); }
211 
212  octave_value do_index_op (const octave_value_list& idx,
213  bool resize_ok = false);
214 
215  dim_vector dims (void) const { static dim_vector dv (1, 1); return dv; }
216 
217  size_t byte_size (void) const;
218 
219  // This is the number of elements in each field. The total number
220  // of elements is numel () * nfields ().
221  octave_idx_type numel (void) const
222  {
223  return 1;
224  }
225 
226  octave_idx_type nfields (void) const { return map.nfields (); }
227 
228  octave_value reshape (const dim_vector& new_dims) const
229  { return octave_map (map).reshape (new_dims); }
230 
231  octave_value resize (const dim_vector& dv, bool fill = false) const
232  { octave_map tmap = map; tmap.resize (dv, fill); return tmap; }
233 
234  bool is_defined (void) const { return true; }
235 
236  bool is_constant (void) const { return true; }
237 
238  bool is_map (void) const { return true; }
239 
240  builtin_type_t builtin_type (void) const { return btyp_struct; }
241 
242  octave_map map_value (void) const { return map; }
243 
244  octave_scalar_map scalar_map_value (void) const { return map; }
245 
246  string_vector map_keys (void) const { return map.fieldnames (); }
247 
248  void print (std::ostream& os, bool pr_as_read_syntax = false);
249 
250  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
251 
252  bool print_name_tag (std::ostream& os, const std::string& name) const;
253 
254  bool save_ascii (std::ostream& os);
255 
256  bool load_ascii (std::istream& is);
257 
258  bool save_binary (std::ostream& os, bool& save_as_floats);
259 
260  bool load_binary (std::istream& is, bool swap,
262 
263  bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
264 
265  bool load_hdf5 (octave_hdf5_id loc_id, const char *name);
266 
267  mxArray *as_mxArray (void) const;
268 
269  bool fast_elem_insert_self (void *where, builtin_type_t btyp) const;
270 
271 protected:
272 
273  // The associative array used to manage the structure data.
275 
276 private:
277 
278  octave_value to_array (void);
279 
280 
282 };
283 
284 #endif
octave_value squeeze(void) const
Definition: ov-struct.h:207
Definition: Cell.h:35
octave_scalar_struct(const octave_scalar_map &m)
Definition: ov-struct.h:174
dim_vector dims(void) const
Definition: ov-struct.h:97
octave_value reshape(const dim_vector &dv) const
Definition: ov.h:498
octave_value permute(const Array< int > &vec, bool inv=false) const
Definition: ov.h:501
bool is_constant(void) const
Definition: ov-struct.h:236
dim_vector dims(void) const
Definition: ov-struct.h:215
builtin_type_t builtin_type(void) const
Definition: ov-struct.h:122
~octave_scalar_struct(void)
Definition: ov-struct.h:180
octave_idx_type length(void) const
Definition: oct-obj.h:89
octave_scalar_map scalar_map_value(void) const
Definition: ov-struct.h:244
octave_idx_type nfields(void) const
Definition: ov-struct.h:108
string_vector map_keys(void) const
Definition: ov-struct.h:126
~octave_struct(void)
Definition: ov-struct.h:59
octave_scalar_struct(void)
Definition: ov-struct.h:171
octave_base_value * clone(void) const
Definition: ov-struct.h:182
bool is_map(void) const
Definition: ov-struct.h:120
octave_map map
Definition: ov-struct.h:158
octave_idx_type numel(void) const
Definition: ov-struct.h:103
builtin_type_t
Definition: ov-base.h:59
octave_value resize(const dim_vector &dv, bool fill=false) const
Definition: ov-struct.h:231
octave_scalar_struct(const octave_scalar_struct &s)
Definition: ov-struct.h:177
octave_value resize(const dim_vector &dv, bool fill=false) const
Definition: ov-struct.h:113
octave_value reshape(const dim_vector &new_dims) const
Definition: ov-struct.h:110
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
Definition: ov-base.h:142
octave_map map_value(void) const
Definition: ov-struct.h:124
octave_value squeeze(void) const
Definition: ov.h:381
octave_map permute(const Array< int > &vec, bool inv=false) const
Definition: oct-map.cc:452
bool is_defined(void) const
Definition: ov-struct.h:116
bool is_constant(void) const
Definition: ov-struct.h:118
octave_struct(void)
Definition: ov-struct.h:50
bool is_defined(void) const
Definition: ov-struct.h:234
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
Definition: ov-struct.h:68
builtin_type_t builtin_type(void) const
Definition: ov-struct.h:240
octave_idx_type nfields(void) const
Definition: ov-struct.h:226
octave_base_value * empty_clone(void) const
Definition: ov-struct.h:62
octave_value squeeze(void) const
Definition: ov-struct.h:89
octave_value permute(const Array< int > &vec, bool inv=false) const
Definition: ov-struct.h:91
octave_value reshape(const dim_vector &new_dims) const
Definition: ov-struct.h:228
octave_struct(const octave_map &m)
Definition: ov-struct.h:53
octave_map reshape(const dim_vector &dv) const
Definition: oct-map.cc:513
octave_base_value * clone(void) const
Definition: ov-struct.h:61
void resize(const dim_vector &dv, bool fill=false)
Definition: oct-map.cc:546
octave_scalar_map map
Definition: ov-struct.h:274
octave_struct(const octave_struct &s)
Definition: ov-struct.h:56
string_vector map_keys(void) const
Definition: ov-struct.h:246
bool is_map(void) const
Definition: ov-struct.h:238
octave_map map_value(void) const
Definition: ov-struct.h:242
octave_base_value * empty_clone(void) const
Definition: ov-struct.h:184
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))
F77_RET_T const double * x
octave_value permute(const Array< int > &vec, bool inv=false) const
Definition: ov-struct.h:209
octave_idx_type numel(void) const
Definition: ov-struct.h:221