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-class.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2007-2017 John W. Eaton
4 Copyright (C) 2009 VZLU Prague
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
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
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
19 along with Octave; see the file COPYING. If not, see
20 <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #if ! defined (octave_ov_class_h)
25 #define octave_ov_class_h 1
26 
27 #include "octave-config.h"
28 
29 #include <cstdlib>
30 
31 #include <iosfwd>
32 #include <string>
33 
34 #include "mx-base.h"
35 #include "str-vec.h"
36 
37 #include "error.h"
38 #include "oct-map.h"
39 #include "ov-base.h"
40 #include "ov-typeinfo.h"
41 
42 class octave_value_list;
43 
44 class tree_walker;
45 
46 // Data structures.
47 
48 class
50 {
51 public:
52 
53  octave_class (void)
54  : octave_base_value (), map (), c_name (),
55  parent_list (), obsolete_copies (0)
56  { }
57 
58  octave_class (const octave_map& m, const std::string& id,
59  const std::list<std::string>& plist)
60  : octave_base_value (), map (m), c_name (id),
61  parent_list (plist), obsolete_copies (0)
62  { }
63 
64  octave_class (const octave_map& m, const std::string& id,
65  const octave_value_list& parents);
66 
68  : octave_base_value (s), map (s.map), c_name (s.c_name),
69  parent_list (s.parent_list), obsolete_copies (0) { }
70 
71  ~octave_class (void) { }
72 
73  octave_base_value *clone (void) const { return new octave_class (*this); }
74 
75  octave_base_value *unique_clone (void);
76 
78  {
79  return new octave_class (octave_map (map.keys ()), c_name, parent_list);
80  }
81 
82  Cell dotref (const octave_value_list& idx);
83 
84  Matrix size (void);
85 
87 
89  const std::list<octave_value_list>& idx)
90  {
91  octave_value_list tmp = subsref (type, idx, 1);
92  return tmp.length () > 0 ? tmp(0) : octave_value ();
93  }
94 
96  const std::list<octave_value_list>& idx,
97  int nargout);
98 
101  {
102  return subsref ("(", std::list<octave_value_list> (1, idx), nargout);
103  }
104 
105  static octave_value numeric_conv (const Cell& val,
106  const std::string& type);
107 
108  void assign(const std::string& k, const octave_value& rhs)
109  { map.assign (k, rhs); };
110 
112  const std::list<octave_value_list>& idx,
113  const octave_value& rhs);
114 
115  octave_value undef_subsasgn (const std::string& type,
116  const std::list<octave_value_list>& idx,
117  const octave_value& rhs);
118 
119  idx_vector index_vector (bool require_integers = false) const;
120 
121  dim_vector dims (void) const { return map.dims (); }
122 
123  size_t byte_size (void) const;
124 
125  // This is the number of elements in each field. The total number
126  // of elements is numel () * nfields ().
127  octave_idx_type numel (void) const
128  {
129  dim_vector dv = dims ();
130  return dv.numel ();
131  }
132 
133  octave_idx_type nfields (void) const { return map.nfields (); }
134 
135  size_t nparents (void) const { return parent_list.size (); }
136 
137  octave_value reshape (const dim_vector& new_dims) const
138  {
139  octave_class retval = octave_class (*this);
140  retval.map = retval.map_value ().reshape (new_dims);
141  return octave_value (new octave_class (retval));
142  }
143 
144  octave_value resize (const dim_vector& dv, bool = false) const
145  {
146  octave_class retval = octave_class (*this);
147  retval.map.resize (dv);
148  return octave_value (new octave_class (retval));
149  }
150 
151  bool is_defined (void) const { return true; }
152 
153  bool is_map (void) const { return false; }
154 
155  bool is_object (void) const { return true; }
156 
157  bool is_true (void) const;
158 
159  octave_map map_value (void) const { return map; }
160 
161  string_vector map_keys (void) const;
162 
163  std::list<std::string> parent_class_name_list (void) const
164  { return parent_list; }
165 
167  { return string_vector (parent_list); }
168 
169  octave_base_value *find_parent_class (const std::string&);
170 
171  octave_base_value *unique_parent_class (const std::string&);
172 
173  bool is_instance_of (const std::string&) const;
174 
175  string_vector string_vector_value (bool pad) const;
176 
177  void print (std::ostream& os, bool pr_as_read_syntax = false);
178 
179  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
180 
181  bool print_name_tag (std::ostream& os, const std::string& name) const;
182 
183  void print_with_name (std::ostream& os, const std::string& name,
184  bool print_padding = true);
185 
186  bool reconstruct_exemplar (void);
187 
188  static void clear_exemplar_map (void);
189 
190  bool reconstruct_parents (void);
191 
192  bool save_ascii (std::ostream& os);
193 
194  bool load_ascii (std::istream& is);
195 
196  bool save_binary (std::ostream& os, bool& save_as_floats);
197 
198  bool load_binary (std::istream& is, bool swap,
200 
201  bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
202 
203  bool load_hdf5 (octave_hdf5_id loc_id, const char *name);
204 
205  mxArray *as_mxArray (void) const;
206 
207 private:
209 
210 public:
211  int type_id (void) const { return t_id; }
212  std::string type_name (void) const { return t_name; }
213  std::string class_name (void) const { return c_name; }
214 
215  static int static_type_id (void) { return t_id; }
216  static std::string static_type_name (void) { return t_name; }
217  static std::string static_class_name (void) { return "<unknown>"; }
218  static void register_type (void);
219 
220 private:
221  static int t_id;
222 
223  static const std::string t_name;
225  std::list<std::string> parent_list;
226 
227  bool in_class_method (void);
228  std::string get_current_method_class (void);
229 
230  octave_value subsasgn_common (const octave_value& obj,
231  const std::string& type,
232  const std::list<octave_value_list>& idx,
233  const octave_value& rhs);
234 
236 
237 public:
238  // The list of field names and parent classes defines a class. We
239  // keep track of each class that has been created so that we know
241  {
242  public:
243 
244  exemplar_info (void) : field_names (), parent_class_names () { }
245 
246  exemplar_info (const octave_value& obj);
247 
249  : field_names (x.field_names),
250  parent_class_names (x.parent_class_names) { }
251 
252  exemplar_info& operator = (const exemplar_info& x)
253  {
254  if (&x != this)
255  {
256  field_names = x.field_names;
257  parent_class_names = x.parent_class_names;
258  }
259  return *this;
260  }
261 
262  octave_idx_type nfields (void) const { return field_names.numel (); }
263 
264  size_t nparents (void) const { return parent_class_names.size (); }
265 
266  string_vector fields (void) const { return field_names; }
267 
268  std::list<std::string> parents (void) const { return parent_class_names; }
269 
270  bool compare (const octave_value& obj) const;
271 
272  private:
273 
275  std::list<std::string> parent_class_names;
276  };
277 
278  // A map from class names to lists of fields.
279  static std::map<std::string, exemplar_info> exemplar_map;
280 
281  typedef std::map<std::string, exemplar_info>::iterator
283  typedef std::map<std::string, exemplar_info>::const_iterator
285 };
286 
287 #endif
int type_id(void) const
Definition: ov-class.h:211
std::list< std::string > parent_class_name_list(void) const
Definition: ov-class.h:163
string_vector keys(void) const
Definition: oct-map.h:338
static std::string static_class_name(void)
Definition: ov-class.h:217
bool is_true(const std::string &s)
Definition: mkoctfile.cc:398
bool is_map(void) const
Definition: ov-class.h:153
Definition: Cell.h:37
std::list< std::string > parents(void) const
Definition: ov-class.h:268
static int t_id
Definition: ov-class.h:221
octave_value reshape(const dim_vector &new_dims) const
Definition: ov-class.h:137
void assign(const std::string &k, const Cell &val)
Definition: oct-map.h:347
octave_base_value * clone(void) const
Definition: ov-class.h:73
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
dim_vector dims(void) const
Definition: ov-class.h:121
octave_idx_type nfields(void) const
Definition: ov-class.h:262
idx subsref(val, idx) esult
Definition: ov.cc:3080
std::string type_name(void) const
Definition: ov-class.h:212
for large enough k
Definition: lu.cc:606
static bool in_class_method(const cdef_class &cls)
Definition: ov-classdef.cc:298
static const std::string t_name
Definition: ov-class.h:223
void assign(const std::string &k, const octave_value &rhs)
Definition: ov-class.h:108
octave_class(const octave_map &m, const std::string &id, const std::list< std::string > &plist)
Definition: ov-class.h:58
s
Definition: file-io.cc:2682
octave_base_value * empty_clone(void) const
Definition: ov-class.h:77
string_vector parent_class_names(void) const
Definition: ov-class.h:166
octave_idx_type numel(int n=0) const
Number of elements that a matrix with this dimensions would have.
Definition: dim-vector.h:389
~octave_class(void)
Definition: ov-class.h:71
octave_class(void)
Definition: ov-class.h:53
string_vector field_names
Definition: ov-class.h:274
bool swap
Definition: load-save.cc:725
octave_map map_value(void) const
Definition: ov-class.h:159
std::map< std::string, exemplar_info >::const_iterator exemplar_const_iterator
Definition: ov-class.h:284
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
static std::map< std::string, exemplar_info > exemplar_map
Definition: ov-class.h:279
size_t nparents(void) const
Definition: ov-class.h:264
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
Definition: ov-usr-fcn.cc:935
octave_idx_type nfields(void) const
Definition: oct-map.h:326
nd deftypefn *octave_map m
Definition: ov-struct.cc:2058
int obsolete_copies
Definition: ov-class.h:235
bool save_as_floats
Definition: load-save.cc:1581
dim_vector dims(void) const
Definition: oct-map.h:399
double tmp
Definition: data.cc:6300
octave_value retval
Definition: data.cc:6294
int64_t octave_hdf5_id
idx type
Definition: ov.cc:3129
Definition: dMatrix.h:37
std::list< std::string > parent_class_names
Definition: ov-class.h:275
bool is_defined(void) const
Definition: ov-class.h:151
the exceeded dimensions are set to if fewer subscripts than dimensions are the exceeding dimensions are merged into the final requested dimension For consider the following dims
Definition: sub2ind.cc:255
static std::string static_type_name(void)
Definition: ov-class.h:216
T::size_type numel(const T &str)
Definition: oct-string.cc:61
size_t nparents(void) const
Definition: ov-class.h:135
octave_idx_type nfields(void) const
Definition: ov-class.h:133
octave_map map
Definition: ov-class.h:208
octave_class(const octave_class &s)
Definition: ov-class.h:67
std::list< std::string > parent_list
Definition: ov-class.h:225
octave_map map(dims)
idx subsasgn(val, idx, 0) esult
Definition: ov.cc:3129
octave_idx_type numel(void) const
Definition: ov-class.h:127
bool is_object(void) const
Definition: ov-class.h:155
octave_map reshape(const dim_vector &dv) const
Definition: oct-map.cc:514
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
Definition: ov-class.h:88
octave_value_list do_multi_index_op(int nargout, const octave_value_list &idx)
Definition: ov-class.h:100
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 or any other valid Octave code The number of return their size
Definition: input.cc:871
void resize(const dim_vector &dv, bool fill=false)
Definition: oct-map.cc:547
exemplar_info(const exemplar_info &x)
Definition: ov-class.h:248
write the output to stdout if nargout is
Definition: load-save.cc:1576
octave_value resize(const dim_vector &dv, bool=false) const
Definition: ov-class.h:144
std::string c_name
Definition: ov-class.h:224
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
std::map< std::string, exemplar_info >::iterator exemplar_iterator
Definition: ov-class.h:282
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 fields(void) const
Definition: ov-class.h:266
static int static_type_id(void)
Definition: ov-class.h:215
dim_vector dv
Definition: sub2ind.cc:263
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())? '\'': '"'))
std::string class_name(void) const
Definition: ov-class.h:213