GNU Octave  4.2.1
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-2017 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 "octave-config.h"
27 
28 #include <cstdlib>
29 
30 #include <iosfwd>
31 #include <string>
32 
33 #include "mx-base.h"
34 #include "str-vec.h"
35 
36 #include "error.h"
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 
45 // Data structures.
46 
47 class
49 {
50 public:
51 
53  : octave_base_value (), map () { }
54 
56  : octave_base_value (), map (m) { }
57 
59  : octave_base_value (), map (s.map) { }
60 
61  ~octave_struct (void) { }
62 
63  octave_base_value *clone (void) const { return new octave_struct (*this); }
64  octave_base_value *empty_clone (void) const { return new octave_struct (); }
65 
66  octave_base_value *try_narrowing_conversion (void);
67 
68  Cell dotref (const octave_value_list& idx, bool auto_add = false);
69 
71  const std::list<octave_value_list>& idx)
72  {
73  octave_value_list tmp = subsref (type, idx, 1);
74  return tmp.length () > 0 ? tmp(0) : octave_value ();
75  }
76 
78  const std::list<octave_value_list>&, int);
79 
81  const std::list<octave_value_list>& idx,
82  bool auto_add);
83 
84  static octave_value numeric_conv (const octave_value& val,
85  const std::string& type);
86 
88  const std::list<octave_value_list>& idx,
89  const octave_value& rhs);
90 
91  octave_value squeeze (void) const { return map.squeeze (); }
92 
93  octave_value permute (const Array<int>& vec, bool inv = false) const
94  { return map.permute (vec, inv); }
95 
96  octave_value do_index_op (const octave_value_list& idx,
97  bool resize_ok = false);
98 
99  dim_vector dims (void) const { return map.dims (); }
100 
101  size_t byte_size (void) const;
102 
103  // This is the number of elements in each field. The total number
104  // of elements is numel () * nfields ().
105  octave_idx_type numel (void) const
106  {
107  return map.numel ();
108  }
109 
110  octave_idx_type nfields (void) const { return map.nfields (); }
111 
112  octave_value reshape (const dim_vector& new_dims) const
113  { return map.reshape (new_dims); }
114 
115  octave_value resize (const dim_vector& dv, bool fill = false) const
116  { octave_map tmap = map; tmap.resize (dv, fill); return tmap; }
117 
118  bool is_defined (void) const { return true; }
119 
120  bool is_constant (void) const { return true; }
121 
122  bool is_map (void) const { return true; }
123 
124  builtin_type_t builtin_type (void) const { return btyp_struct; }
125 
126  octave_map map_value (void) const { return map; }
127 
128  string_vector map_keys (void) const { return map.fieldnames (); }
129 
130  void print (std::ostream& os, bool pr_as_read_syntax = false);
131 
132  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
133 
134  bool print_name_tag (std::ostream& os, const std::string& name) const;
135 
136  bool save_ascii (std::ostream& os);
137 
138  bool load_ascii (std::istream& is);
139 
140  bool save_binary (std::ostream& os, bool& save_as_floats);
141 
142  bool load_binary (std::istream& is, bool swap,
144 
145  bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
146 
147  bool load_hdf5 (octave_hdf5_id loc_id, const char *name);
148 
149  mxArray *as_mxArray (void) const;
150 
152  fast_elem_extract (octave_idx_type n) const;
153 
154  bool
155  fast_elem_insert (octave_idx_type n, const octave_value& x);
156 
157 protected:
158 
159  // The associative array used to manage the structure data.
161 
162 private:
163 
165 };
166 
167 class
169 {
170 public:
171 
173  : octave_base_value (), map () { }
174 
176  : octave_base_value (), map (m) { }
177 
179  : octave_base_value (), map (s.map) { }
180 
182 
183  octave_base_value *clone (void) const
184  { return new octave_scalar_struct (*this); }
186  { return new octave_scalar_struct (); }
187 
188  octave_value dotref (const octave_value_list& idx, bool auto_add = false);
189 
191  const std::list<octave_value_list>& idx);
192 
194  const std::list<octave_value_list>& idx, int);
195 
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 
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 
281 };
282 
283 #endif
octave_value squeeze(void) const
Definition: ov-struct.h:207
Definition: Cell.h:37
octave_scalar_struct(const octave_scalar_map &m)
Definition: ov-struct.h:175
dim_vector dims(void) const
Definition: ov-struct.h:99
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:124
~octave_scalar_struct(void)
Definition: ov-struct.h:181
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:5068
octave_idx_type length(void) const
Definition: ovl.h:96
octave_scalar_map scalar_map_value(void) const
Definition: ov-struct.h:244
idx subsref(val, idx) esult
Definition: ov.cc:3080
octave_idx_type nfields(void) const
Definition: ov-struct.h:110
string_vector map_keys(void) const
Definition: ov-struct.h:128
~octave_struct(void)
Definition: ov-struct.h:61
octave_scalar_struct(void)
Definition: ov-struct.h:172
octave_base_value * clone(void) const
Definition: ov-struct.h:183
bool is_map(void) const
Definition: ov-struct.h:122
octave_map squeeze(void) const
Definition: oct-map.cc:430
octave_idx_type numel(void) const
Definition: oct-map.h:371
octave_map map
Definition: ov-struct.h:160
s
Definition: file-io.cc:2682
octave_idx_type numel(void) const
Definition: ov-struct.h:105
builtin_type_t
Definition: ov-base.h:61
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:178
octave_value resize(const dim_vector &dv, bool fill=false) const
Definition: ov-struct.h:115
bool swap
Definition: load-save.cc:725
octave_value reshape(const dim_vector &new_dims) const
Definition: ov-struct.h:112
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
Definition: ov-base.h:148
octave_map map_value(void) const
Definition: ov-struct.h:126
OCTAVE_EXPORT octave_value_list any number nd example oindent prints the prompt xample Pick a any number!nd example oindent and waits for the user to enter a value The string entered by the user is evaluated as an so it may be a literal a variable name
Definition: input.cc:871
octave_idx_type nfields(void) const
Definition: oct-map.h:326
nd deftypefn *octave_map m
Definition: ov-struct.cc:2058
bool save_as_floats
Definition: load-save.cc:1581
octave_map permute(const Array< int > &vec, bool inv=false) const
Definition: oct-map.cc:453
dim_vector dims(void) const
Definition: oct-map.h:399
double tmp
Definition: data.cc:6300
bool is_defined(void) const
Definition: ov-struct.h:118
bool is_constant(void) const
Definition: ov-struct.h:120
int64_t octave_hdf5_id
octave_struct(void)
Definition: ov-struct.h:52
bool is_defined(void) const
Definition: ov-struct.h:234
idx type
Definition: ov.cc:3129
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
Definition: ov-struct.h:70
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:64
octave_map map(dims)
octave_value squeeze(void) const
Definition: ov-struct.h:91
octave_value permute(const Array< int > &vec, bool inv=false) const
Definition: ov-struct.h:93
idx subsasgn(val, idx, 0) esult
Definition: ov.cc:3129
octave_value reshape(const dim_vector &new_dims) const
Definition: ov-struct.h:228
octave_struct(const octave_map &m)
Definition: ov-struct.h:55
octave_map reshape(const dim_vector &dv) const
Definition: oct-map.cc:514
octave_base_value * clone(void) const
Definition: ov-struct.h:63
void resize(const dim_vector &dv, bool fill=false)
Definition: oct-map.cc:547
octave_scalar_map map
Definition: ov-struct.h:274
octave_struct(const octave_struct &s)
Definition: ov-struct.h:58
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
write the output to stdout if nargout is
Definition: load-save.cc:1576
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854
string_vector fieldnames(void) const
Definition: oct-map.h:335
dim_vector dv
Definition: sub2ind.cc:263
octave_base_value * empty_clone(void) const
Definition: ov-struct.h:185
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE * x
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))
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