GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ov-classdef.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2012-2018 Michael Goffioul
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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License 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 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_classdef_h)
24 #define octave_classdef_h 1
25 
26 #include "octave-config.h"
27 
28 #include <map>
29 #include <set>
30 #include <string>
31 
32 #include "oct-refcount.h"
33 
34 #include "oct-map.h"
35 #include "ov-base.h"
36 #include "ov-builtin.h"
37 
38 class cdef_object;
39 class cdef_class;
40 class cdef_property;
41 class cdef_method;
42 class cdef_package;
43 
44 namespace octave
45 {
46  class interpreter;
47  class tree_classdef;
48  class type_info;
49 }
50 
51 // This is mainly a boostrap class to declare the expected interface.
52 // The actual base class is cdef_class_base, which is declared after
53 // cdef_object, such that it can contain cdef_object objects.
54 class
56 {
57 public:
58  friend class cdef_object;
59 
60 public:
61 
63  { }
64 
66 
67  virtual ~cdef_object_rep (void) = default;
68 
69  virtual cdef_class get_class (void) const;
70 
71  virtual void set_class (const cdef_class&)
72  { err_invalid_object ("set_class"); }
73 
74  virtual cdef_object_rep * clone (void) const
75  {
76  err_invalid_object ("clone");
77  }
78 
79  virtual cdef_object_rep * empty_clone (void) const
80  {
81  err_invalid_object ("empty_clone");
82  }
83 
84  virtual cdef_object_rep * copy (void) const
85  {
86  err_invalid_object ("copy");
87  }
88 
89  virtual cdef_object_rep * make_array (void) const
90  {
91  err_invalid_object ("make_array");
92  }
93 
94  virtual bool is_array (void) const { return false; }
95 
96  virtual bool is_value_object (void) const { return false; }
97 
98  virtual bool is_handle_object (void) const { return false; }
99 
100  virtual bool is_meta_object (void) const { return false; }
101 
102  virtual Array<cdef_object> array_value (void) const
103  {
104  err_invalid_object ("array_value");
105  }
106 
107  virtual void put (const std::string&, const octave_value&)
108  { err_invalid_object ("put"); }
109 
110  virtual octave_value get (const std::string&) const
111  {
112  err_invalid_object ("get");
113  }
114 
115  virtual void set_property (octave_idx_type, const std::string&,
116  const octave_value&)
117  {
118  err_invalid_object ("set_property");
119  }
120 
122  {
123  err_invalid_object ("get_property");
124  }
125 
126  virtual octave_value_list
127  subsref (const std::string&, const std::list<octave_value_list>&,
128  int, size_t&, const cdef_class&, bool)
129  {
130  err_invalid_object ("subsref");
131  }
132 
133  virtual octave_value
134  subsasgn (const std::string&, const std::list<octave_value_list>&,
135  const octave_value&)
136  {
137  err_invalid_object ("subsasgn");
138  }
139 
140  virtual string_vector map_keys (void) const;
141 
142  virtual bool is_valid (void) const { return false; }
143 
144  std::string class_name (void) const;
145 
146  virtual void mark_for_construction (const cdef_class&)
147  {
148  err_invalid_object ("mark_for_construction");
149  }
150 
151  virtual bool is_constructed_for (const cdef_class&) const
152  {
153  err_invalid_object ("is_constructed_for");
154  }
155 
156  virtual bool is_partially_constructed_for (const cdef_class&) const
157  {
158  err_invalid_object ("is_partially_constructed_for");
159  }
160 
161  virtual void mark_as_constructed (void)
162  {
163  err_invalid_object ("mark_as_constructed");
164  }
165 
166  virtual void mark_as_constructed (const cdef_class&)
167  {
168  err_invalid_object ("mark_as_constructed");
169  }
170 
171  virtual bool is_constructed (void) const
172  {
173  err_invalid_object ("is_constructed");
174  }
175 
176  virtual octave_idx_type static_count (void) const { return 0; }
177 
178  virtual void destroy (void) { delete this; }
179 
180  void release (const cdef_object& obj);
181 
182  virtual dim_vector dims (void) const { return dim_vector (); }
183 
184 protected:
185 
186  // Reference count
188 
189 protected:
190 
191  // Restricted copying.
192 
194  : refcount (1)
195  { }
196 
197 private:
198 
199  OCTAVE_NORETURN void err_invalid_object (const char *who) const
200  { error ("%s: invalid object", who); }
201 };
202 
203 class
205 {
206 public:
207  // FIXME: use a null object
208  cdef_object (void)
209  : rep (new cdef_object_rep ()) { }
210 
212  : rep (obj.rep) { rep->refcount++; }
213 
215  : rep (r) { }
216 
217  virtual ~cdef_object (void)
218  {
219  rep->release (*this);
220  }
221 
223  {
224  if (rep != obj.rep)
225  {
226  rep->release (*this);
227 
228  rep = obj.rep;
229  rep->refcount++;
230  }
231 
232  return *this;
233  }
234 
235  cdef_class get_class (void) const;
236 
237  void set_class (const cdef_class& cls) { rep->set_class (cls); }
238 
239  std::string class_name (void) const
240  { return rep->class_name (); }
241 
242  cdef_object clone (void) const
243  { return cdef_object (rep->clone ()); }
244 
246  { return cdef_object (rep->empty_clone ()); }
247 
248  dim_vector dims (void) const { return rep->dims (); }
249 
250  cdef_object make_array (void) const
251  { return cdef_object (rep->make_array ()); }
252 
253  cdef_object copy (void) const
254  { return cdef_object (rep->copy ()); }
255 
256  bool is_array (void) const { return rep->is_array (); }
257 
258  bool is_value_object (void) const { return rep->is_value_object (); }
259 
260  bool is_handle_object (void) const { return rep->is_handle_object (); }
261 
262  bool is_meta_object (void) const { return rep->is_meta_object (); }
263 
264  Array<cdef_object> array_value (void) const { return rep->array_value (); }
265 
266  void put (const std::string& pname, const octave_value& val)
267  { rep->put (pname, val); }
268 
269  octave_value get (const std::string& pname) const
270  { return rep->get (pname); }
271 
273  const octave_value& pval)
274  { return rep->set_property (idx, pname, pval); }
275 
278  { return rep->get_property (idx, pname); }
279 
281  subsref (const std::string& type, const std::list<octave_value_list>& idx,
282  int nargout, size_t& skip, const cdef_class& context,
283  bool auto_add = false)
284  { return rep->subsref (type, idx, nargout, skip, context, auto_add); }
285 
287  subsasgn (const std::string& type, const std::list<octave_value_list>& idx,
288  const octave_value& rhs, int ignore_copies = 0)
289  {
290  make_unique (ignore_copies);
291  return rep->subsasgn (type, idx, rhs);
292  }
293 
294  string_vector map_keys (void) const { return rep->map_keys (); }
295 
296  octave_map map_value (void) const;
297 
298  const cdef_object_rep * get_rep (void) const { return rep; }
299 
300  bool ok (void) const { return rep->is_valid (); }
301 
303  { rep->mark_for_construction (cls); }
304 
305  bool is_constructed (void) const { return rep->is_constructed (); }
306 
307  bool is_constructed_for (const cdef_class& cls) const
308  { return rep->is_constructed_for (cls); }
309 
310  bool is_partially_constructed_for (const cdef_class& cls) const
311  { return rep->is_partially_constructed_for (cls); }
312 
314 
315  void mark_as_constructed (const cdef_class& cls)
316  { rep->mark_as_constructed (cls); }
317 
318  bool is (const cdef_object& obj) const { return rep == obj.rep; }
319 
320 protected:
321  cdef_object_rep * get_rep (void) { return rep; }
322 
323  void make_unique (int ignore_copies)
324  {
325  if (rep->refcount > ignore_copies + 1)
326  *this = clone ();
327  }
328 
329 private:
331 };
332 
333 class
335 {
336 public:
338  : cdef_object_rep (), klass ()
339  {
340  register_object ();
341  }
342 
343  ~cdef_object_base (void) { unregister_object (); }
344 
345  cdef_class get_class (void) const;
346 
347  void set_class (const cdef_class& cls);
348 
350  { return new cdef_object_base (*this); }
351 
352  cdef_object_rep * make_array (void) const;
353 
354 protected:
355  // Restricted copying!
357  : cdef_object_rep (obj), klass (obj.klass)
358  {
359  register_object ();
360  }
361 
362 private:
363  void register_object (void);
364 
365  void unregister_object (void);
366 
367  // The class of the object
369 
370  // No assignment!
372 };
373 
374 class
376 {
377 public:
379 
381  : cdef_object_base (), array (a) { }
382 
383  cdef_object_rep * clone (void) const
384  { return new cdef_object_array (*this); }
385 
386  dim_vector dims (void) const { return array.dims (); }
387 
388  bool is_valid (void) const { return true; }
389 
390  bool is_array (void) const { return true; }
391 
392  Array<cdef_object> array_value (void) const { return array; }
393 
395  subsref (const std::string& type, const std::list<octave_value_list>& idx,
396  int nargout, size_t& skip, const cdef_class& context,
397  bool auto_add);
398 
400  subsasgn (const std::string& type, const std::list<octave_value_list>& idx,
401  const octave_value& rhs);
402 
404  const octave_value& pval)
405  {
406  cdef_object& tmp = array.elem (idx);
407 
408  return tmp.put (pname, pval);
409  }
410 
413  {
414  cdef_object tmp = array.elem (idx);
415 
416  return tmp.get (pname);
417  }
418 
419 private:
421 
423 
424  void fill_empty_values (Array<cdef_object>& arr);
425 
426  // Private copying!
428  : cdef_object_base (obj), array (obj.array) { }
429 
430  // No assignment!
432 };
433 
434 class
436 {
437 public:
439 
440  ~cdef_object_scalar (void) = default;
441 
442  dim_vector dims (void) const { return dim_vector (1, 1); }
443 
444  void put (const std::string& pname, const octave_value& val)
445  { map.assign (pname, val); }
446 
447  octave_value get (const std::string& pname) const
448  {
449  Cell val = map.contents (pname);
450 
451  if (val.numel () < 1)
452  error ("get: unknown slot: %s", pname.c_str ());
453 
454  return val(0, 0);
455  }
456 
458  const octave_value& pval)
459  {
460  if (idx != 0)
461  error ("invalid index"); // FIXME
462 
463  put (pname, pval);
464  }
465 
468  {
469  if (idx != 0)
470  error ("invalid index"); // FIXME
471 
472  return get (pname);
473  }
474 
476  subsref (const std::string& type, const std::list<octave_value_list>& idx,
477  int nargout, size_t& skip, const cdef_class& context,
478  bool auto_add);
479 
481  subsasgn (const std::string& type, const std::list<octave_value_list>& idx,
482  const octave_value& rhs);
483 
484  void mark_for_construction (const cdef_class&);
485 
486  bool is_constructed_for (const cdef_class& cls) const;
487 
488  bool is_partially_constructed_for (const cdef_class& cls) const;
489 
490  void mark_as_constructed (void) { ctor_list.clear (); }
491 
492  void mark_as_constructed (const cdef_class& cls);
493 
494  bool is_constructed (void) const { return ctor_list.empty (); }
495 
496 protected:
497  // Object property values
499 
500  // Internal/temporary structure used during object construction
501  std::map< cdef_class, std::list<cdef_class>> ctor_list;
502 
503 protected:
504  // Restricted object copying!
506  : cdef_object_base (obj), map (obj.map), ctor_list (obj.ctor_list) { }
507 
508 private:
509  // No assignment!
511 };
512 
513 class
515 {
516 public:
518  : cdef_object_scalar () { }
519 
520  ~handle_cdef_object (void);
521 
522  cdef_object_rep * clone (void) const
523  {
524  handle_cdef_object *obj = const_cast<handle_cdef_object *> (this);
525  obj->refcount++;
526  return obj;
527  }
528 
529  cdef_object_rep * copy (void) const
530  { return new handle_cdef_object (*this); }
531 
532  bool is_valid (void) const { return true; }
533 
534  bool is_handle_object (void) const { return true; }
535 
536 protected:
537  // Restricted copying!
539  : cdef_object_scalar (obj) { }
540 
541 private:
542  // No assignment
544 };
545 
546 class
548 {
549 public:
551  : cdef_object_scalar () { }
552 
553  ~value_cdef_object (void);
554 
555  cdef_object_rep * clone (void) const
556  { return new value_cdef_object (*this); }
557 
558  cdef_object_rep * copy (void) const { return clone (); }
559 
560  bool is_valid (void) const { return true; }
561 
562  bool is_value_object (void) const { return true; }
563 
564 private:
565  // Private copying!
567  : cdef_object_scalar (obj) { }
568 
569  // No assignment!
571 };
572 
573 class
575 {
576 public:
578  : handle_cdef_object () { }
579 
580  ~cdef_meta_object_rep (void) = default;
581 
582  cdef_object_rep * copy (void) const
583  { return new cdef_meta_object_rep (*this); }
584 
585  bool is_meta_object (void) const { return true; }
586 
587  virtual bool is_class (void) const { return false; }
588 
589  virtual bool is_property (void) const { return false; }
590 
591  virtual bool is_method (void) const { return false; }
592 
593  virtual bool is_package (void) const { return false; }
594 
595  virtual octave_value_list
596  meta_subsref (const std::string& /* type */,
597  const std::list<octave_value_list>& /* idx */,
598  int /* nargout */)
599  {
600  error ("subsref: invalid meta object");
601  }
602 
603  virtual void meta_release (void) { }
604 
605  virtual bool meta_accepts_postfix_index (char /* type */) const
606  { return false; }
607 
608 protected:
609  // Restricted copying!
611  : handle_cdef_object (obj) { }
612 
613 private:
614  // No assignment!
616 };
617 
618 class
620 {
621 public:
623  : cdef_object () { }
624 
625  // Object consistency is checked in sub-classes.
627  : cdef_object (obj) { }
628 
630  : cdef_object (r) { }
631 
633  : cdef_object (obj) { }
634 
635  ~cdef_meta_object (void) = default;
636 
637  bool is_class (void) const { return get_rep ()->is_class (); }
638 
639  bool is_property (void) const { return get_rep ()->is_property (); }
640 
641  bool is_method (void) const { return get_rep ()->is_method (); }
642 
643  bool is_package (void) const { return get_rep ()->is_package (); }
644 
647  const std::list<octave_value_list>& idx, int nargout)
648  { return get_rep ()->meta_subsref (type, idx, nargout); }
649 
650  void meta_release (void) { get_rep ()->meta_release (); }
651 
653  { return get_rep ()->meta_accepts_postfix_index (type); }
654 
655 private:
657  { return dynamic_cast<cdef_meta_object_rep *> (cdef_object::get_rep ()); }
658 
659  const cdef_meta_object_rep * get_rep (void) const
660  { return dynamic_cast<const cdef_meta_object_rep *> (cdef_object::get_rep ()); }
661 };
662 
663 class
665 {
666 private:
667 
668  class
670  {
671  public:
673  : cdef_meta_object_rep (), member_count (0), handle_class (false),
674  object_count (0), meta (false)
675  { }
676 
677  cdef_class_rep (const std::list<cdef_class>& superclasses);
678 
679  cdef_object_rep * copy (void) const { return new cdef_class_rep (*this); }
680 
681  bool is_class (void) const { return true; }
682 
683  std::string get_name (void) const
684  { return get ("Name").string_value (); }
685 
686  void set_name (const std::string& nm) { put ("Name", nm); }
687 
688  bool is_abstract (void) const { return get ("Abstract").bool_value (); }
689 
690  bool is_sealed (void) const { return get ("Sealed").bool_value (); }
691 
692  cdef_method find_method (const std::string& nm, bool local = false);
693 
694  void install_method (const cdef_method& meth);
695 
696  Cell get_methods (void);
697 
698  cdef_property find_property (const std::string& nm);
699 
700  void install_property (const cdef_property& prop);
701 
702  Cell get_properties (int mode);
703 
704  std::map<std::string, cdef_property> get_property_map (int mode);
705 
706  string_vector get_names (void);
707 
708  void set_directory (const std::string& dir) { directory = dir; }
709 
710  std::string get_directory (void) const { return directory; }
711 
712  void delete_object (const cdef_object& obj);
713 
715  meta_subsref (const std::string& type,
716  const std::list<octave_value_list>& idx, int nargout);
717 
718  void meta_release (void);
719 
721  { return (type == '(' || type == '.'); }
722 
723  octave_value construct (const octave_value_list& args);
724 
725  cdef_object construct_object (const octave_value_list& args);
726 
727  void initialize_object (cdef_object& obj);
728 
729  void run_constructor (cdef_object& obj, const octave_value_list& args);
730 
731  void mark_as_handle_class (void) { handle_class = true; }
732 
733  bool is_handle_class (void) const { return handle_class; }
734 
735  void register_object (void) { object_count++; }
736 
737  void unregister_object (void) { object_count--; }
738 
739  octave_idx_type static_count (void) const { return member_count; }
740 
741  void destroy (void)
742  {
743  if (member_count)
744  {
745  refcount++;
746  cdef_class lock (this);
747 
748  member_count = 0;
749  method_map.clear ();
750  property_map.clear ();
751  }
752  else
753  delete this;
754  }
755 
756  void mark_as_meta_class (void) { meta = true; }
757 
758  bool is_meta_class (void) const { return meta; }
759 
760  private:
761 
762  void load_all_methods (void);
763 
764  void find_names (std::set<std::string>& names, bool all);
765 
766  void find_properties (std::map<std::string,cdef_property>& props,
767  int mode = 0);
768 
769  void find_methods (std::map<std::string, cdef_method>& meths,
770  bool only_inherited);
771 
773  {
774  refcount++;
775  return cdef_class (this);
776  }
777 
778  // The @-directory were this class is loaded from.
779  // (not used yet)
781 
782  // The methods defined by this class.
783  std::map<std::string,cdef_method> method_map;
784 
785  // The properties defined by this class.
786  std::map<std::string,cdef_property> property_map;
787 
788  // The number of members in this class (methods, properties...)
790 
791  // TRUE if this class is a handle class. A class is a handle
792  // class when the abstract "handle" class is one of its superclasses.
794 
795  // The list of super-class constructors that are called implicitly by the
796  // the classdef engine when creating an object. These constructors are not
797  // called explicitly by the class constructor.
798  std::list<cdef_class> implicit_ctor_list;
799 
800  // The number of objects of this class.
802 
803  // TRUE if this class is a built-in meta class.
804  bool meta;
805 
806  // Utility iterator typedef's.
807  typedef std::map<std::string,cdef_method>::iterator method_iterator;
808  typedef std::map<std::string,cdef_method>::const_iterator method_const_iterator;
809  typedef std::map<std::string,cdef_property>::iterator property_iterator;
810  typedef std::map<std::string,cdef_property>::const_iterator property_const_iterator;
811 
814  method_map (c.method_map), property_map (c.property_map),
815  member_count (c.member_count), handle_class (c.handle_class),
816  implicit_ctor_list (c.implicit_ctor_list),
817  object_count (c.object_count), meta (c.meta) { }
818  };
819 
820 public:
821  // Create and invalid class object
822  cdef_class (void)
823  : cdef_meta_object () { }
824 
825  cdef_class (const std::string& nm, const std::list<cdef_class>& superclasses)
826  : cdef_meta_object (new cdef_class_rep (superclasses))
827  { get_rep ()->set_name (nm); }
828 
829  cdef_class (const cdef_class& cls)
830  : cdef_meta_object (cls) { }
831 
832  cdef_class (const cdef_object& obj)
833  : cdef_meta_object (obj)
834  {
835  // This should never happen...
836  if (! is_class ())
837  error ("internal error: invalid assignment from %s to meta.class object",
838  class_name ().c_str ());
839  }
840 
842  {
844 
845  return *this;
846  }
847 
848  cdef_method find_method (const std::string& nm, bool local = false);
849 
850  void install_method (const cdef_method& meth)
851  { get_rep ()->install_method (meth); }
852 
853  Cell get_methods (void) { return get_rep ()->get_methods (); }
854 
855  cdef_property find_property (const std::string& nm);
856 
857  void install_property (const cdef_property& prop)
858  { get_rep ()->install_property (prop); }
859 
860  Cell get_properties (int mode = property_normal)
861  { return get_rep ()->get_properties (mode); }
862 
863  std::map<std::string, cdef_property>
864  get_property_map (int mode = property_normal)
865  { return get_rep ()->get_property_map (mode); }
866 
867  string_vector get_names (void) { return get_rep ()->get_names (); }
868 
869  bool is_abstract (void) const { return get_rep ()->is_abstract (); }
870 
871  bool is_sealed (void) const { return get_rep ()->is_sealed (); }
872 
873  void set_directory (const std::string& dir)
874  { get_rep ()->set_directory (dir); }
875 
877  { return get_rep ()->get_directory (); }
878 
879  std::string get_name (void) const
880  { return get_rep ()->get_name (); }
881 
882  bool is_builtin (void) const
883  { return get_directory ().empty (); }
884 
885  void delete_object (const cdef_object& obj)
886  { get_rep ()->delete_object (obj); }
887 
888  //! Analyze the tree_classdef tree and transform it to a cdef_class
889  //!
890  //! <b>All attribute validation should occur here.</b>
891  //!
892  //! Classdef attribute values can be given in the form of
893  //! expressions. These expressions must be evaluated before
894  //! assigning them as attribute values. Evaluating them as they are
895  //! parsed causes trouble with possible recusion in the parser so we
896  //! do it here. For example
897  //!
898  //! @code
899  //! classdef recursion_class
900  //! methods (Access = ?recursion_class)
901  //! endmethods
902  //! endclassdef
903  //! @endcode
904  //!
905  //! will fail because each attempt to compute the metaclass of
906  //! recursion_class will cause recursion_class to be parsed again.
907 
908  static cdef_class
909  make_meta_class (octave::interpreter& interp, octave::tree_classdef *t,
910  bool is_at_folder = false);
911 
912  octave_function * get_method_function (const std::string& nm);
913 
915  { return get_method_function (get_name ()); }
916 
918  { return get_rep ()->construct (args); }
919 
921  { return get_rep ()->construct_object (args); }
922 
924  { get_rep ()->initialize_object (obj); }
925 
927  { get_rep ()->run_constructor (obj, args); }
928 
930  { get_rep ()->mark_as_handle_class (); }
931 
932  bool is_handle_class (void) const
933  { return get_rep ()->is_handle_class (); }
934 
935  void mark_as_meta_class (void) { get_rep ()->mark_as_meta_class (); }
936 
937  bool is_meta_class (void) const { return get_rep ()->is_meta_class (); }
938 
939  void register_object (void) { get_rep ()->register_object (); }
940 
941  void unregister_object (void) { get_rep ()->unregister_object (); }
942 
943 public:
944  enum
945  {
948  property_all
949  };
950 
951 private:
953  { return dynamic_cast<cdef_class_rep *> (cdef_object::get_rep ()); }
954 
955  const cdef_class_rep * get_rep (void) const
956  { return dynamic_cast<const cdef_class_rep *> (cdef_object::get_rep ()); }
957 
958  friend bool operator == (const cdef_class&, const cdef_class&);
959  friend bool operator != (const cdef_class&, const cdef_class&);
960  friend bool operator < (const cdef_class&, const cdef_class&);
961 
962  friend void install_classdef (octave::interpreter& interp);
963 };
964 
965 inline bool
966 operator == (const cdef_class& clsa, const cdef_class& clsb)
967 // FIXME: is this really the right way to check class equality?
968 { return (clsa.get_rep () == clsb.get_rep ()); }
969 
970 inline bool
971 operator != (const cdef_class& clsa, const cdef_class& clsb)
972 { return ! (clsa == clsb); }
973 
974 // This is only to be able to use cdef_class as map keys.
975 inline bool
976 operator < (const cdef_class& clsa, const cdef_class& clsb)
977 { return clsa.get_rep () < clsb.get_rep (); }
978 
979 class
981 {
982  friend class cdef_class;
983 
984 private:
985 
986  class
988  {
989  public:
991  : cdef_meta_object_rep () { }
992 
993  cdef_object_rep * copy (void) const { return new cdef_property_rep (*this); }
994 
995  bool is_property (void) const { return true; }
996 
997  std::string get_name (void) const { return get("Name").string_value (); }
998 
999  void set_name (const std::string& nm) { put ("Name", nm); }
1000 
1001  bool is_constant (void) const { return get("Constant").bool_value (); }
1002 
1003  octave_value get_value (bool do_check_access = true,
1004  const std::string& who = "");
1005 
1006  octave_value get_value (const cdef_object& obj,
1007  bool do_check_access = true,
1008  const std::string& who = "");
1009 
1010  void set_value (cdef_object& obj, const octave_value& val,
1011  bool do_check_access = true,
1012  const std::string& who = "");
1013 
1014  bool check_get_access (void) const;
1015 
1016  bool check_set_access (void) const;
1017 
1018  private:
1020  : cdef_meta_object_rep (p) { }
1021 
1022  bool is_recursive_set (const cdef_object& obj) const;
1023 
1025  {
1026  refcount++;
1027  return cdef_property (this);
1028  }
1029  };
1030 
1031 public:
1033 
1036  { get_rep ()->set_name (nm); }
1037 
1039  : cdef_meta_object (prop) { }
1040 
1042  : cdef_meta_object (obj)
1043  {
1044  // This should never happen...
1045  if (! is_property ())
1046  error ("internal error: invalid assignment from %s to meta.property object",
1047  class_name ().c_str ());
1048  }
1049 
1051  {
1053 
1054  return *this;
1055  }
1056 
1057  octave_value get_value (const cdef_object& obj, bool do_check_access = true,
1058  const std::string& who = "")
1059  { return get_rep ()->get_value (obj, do_check_access, who); }
1060 
1061  octave_value get_value (bool do_check_access = true,
1062  const std::string& who = "")
1063  { return get_rep ()->get_value (do_check_access, who); }
1064 
1066  bool do_check_access = true,
1067  const std::string& who = "")
1068  { get_rep ()->set_value (obj, val, do_check_access, who); }
1069 
1070  bool check_get_access (void) const
1071  { return get_rep ()->check_get_access (); }
1072 
1073  bool check_set_access (void) const
1074  { return get_rep ()->check_set_access (); }
1075 
1076  std::string get_name (void) const { return get_rep ()->get_name (); }
1077 
1078  bool is_constant (void) const { return get_rep ()->is_constant (); }
1079 
1080 private:
1082  { return dynamic_cast<cdef_property_rep *> (cdef_object::get_rep ()); }
1083 
1084  const cdef_property_rep * get_rep (void) const
1085  { return dynamic_cast<const cdef_property_rep *> (cdef_object::get_rep ()); }
1086 };
1087 
1088 class
1090 {
1091  friend class cdef_class;
1092 
1093 private:
1094 
1095  class
1097  {
1098  public:
1100  : cdef_meta_object_rep (), function (), dispatch_type ()
1101  { }
1102 
1103  cdef_object_rep * copy (void) const { return new cdef_method_rep(*this); }
1104 
1105  bool is_method (void) const { return true; }
1106 
1107  std::string get_name (void) const { return get("Name").string_value (); }
1108 
1109  void set_name (const std::string& nm) { put ("Name", nm); }
1110 
1111  bool is_static (void) const { return get("Static").bool_value (); }
1112 
1113  octave_value get_function (void) const { return function; }
1114 
1115  void set_function (const octave_value& fcn) { function = fcn; }
1116 
1117  bool check_access (void) const;
1118 
1119  bool is_external (void) const { return ! dispatch_type.empty (); }
1120 
1121  void mark_as_external (const std::string& dtype)
1122  { dispatch_type = dtype; }
1123 
1124  octave_value_list execute (const octave_value_list& args, int nargout,
1125  bool do_check_access = true,
1126  const std::string& who = "");
1127 
1128  octave_value_list execute (const cdef_object& obj,
1129  const octave_value_list& args, int nargout,
1130  bool do_check_access = true,
1131  const std::string& who = "");
1132 
1133  bool is_constructor (void) const;
1134 
1136  meta_subsref (const std::string& type,
1137  const std::list<octave_value_list>& idx, int nargout);
1138 
1140  { return (type == '(' || type == '.'); }
1141 
1142  private:
1145  dispatch_type (m.dispatch_type)
1146  { }
1147 
1148  void check_method (void);
1149 
1151  {
1152  refcount++;
1153  return cdef_method (this);
1154  }
1155 
1156  octave_value function;
1157 
1158  // When non-empty, the method is externally defined and this member
1159  // is used to cache the dispatch type to look for the method.
1161  };
1162 
1163 public:
1165 
1168  { get_rep ()->set_name (nm); }
1169 
1170  cdef_method (const cdef_method& meth)
1171  : cdef_meta_object (meth) { }
1172 
1174  : cdef_meta_object (obj)
1175  {
1176  // This should never happen...
1177  if (! is_method ())
1178  error ("internal error: invalid assignment from %s to meta.method object",
1179  class_name ().c_str ());
1180  }
1181 
1183  {
1185 
1186  return *this;
1187  }
1188 
1189  // normal invocation
1191  bool do_check_access = true,
1192  const std::string& who = "")
1193  { return get_rep ()->execute (args, nargout, do_check_access, who); }
1194 
1195  // dot-invocation: object is pushed as 1st argument
1197  const octave_value_list& args, int nargout,
1198  bool do_check_access = true,
1199  const std::string& who = "")
1200  { return get_rep ()->execute (obj, args, nargout, do_check_access, who); }
1201 
1202  bool check_access (void) const { return get_rep ()->check_access (); }
1203 
1204  std::string get_name (void) const { return get_rep ()->get_name (); }
1205 
1206  bool is_static (void) const { return get_rep ()->is_static (); }
1207 
1209  { get_rep ()->set_function (fcn); }
1210 
1212  { return get_rep ()->get_function (); }
1213 
1214  bool is_constructor (void) const
1215  { return get_rep ()->is_constructor (); }
1216 
1217  bool is_external (void) const { return get_rep ()->is_external (); }
1218 
1219  void mark_as_external (const std::string& dtype)
1220  { get_rep ()->mark_as_external (dtype); }
1221 
1222 private:
1224  { return dynamic_cast<cdef_method_rep *> (cdef_object::get_rep ()); }
1225 
1226  const cdef_method_rep * get_rep (void) const
1227  { return dynamic_cast<const cdef_method_rep *> (cdef_object::get_rep ()); }
1228 };
1229 
1230 inline cdef_class
1232 {
1233  err_invalid_object ("get_class");
1234 }
1235 
1236 inline std::string
1238 { return get_class ().get_name (); }
1239 
1240 inline cdef_class
1242 { return rep->get_class (); }
1243 
1244 inline cdef_class
1246 { return cdef_class (klass); }
1247 
1248 inline void
1250 {
1251  if ((klass.ok () && cls.ok () && cls != get_class ())
1252  || (klass.ok () && ! cls.ok ())
1253  || (! klass.ok () && cls.ok ()))
1254  {
1255  unregister_object ();
1256  klass = cls;
1257  register_object ();
1258  }
1259 }
1260 
1261 inline void
1263 {
1264  if (klass.ok ())
1265  {
1266  cdef_class cls (get_class ());
1267 
1268  if (cls.ok ())
1269  cls.register_object ();
1270  }
1271 }
1272 
1273 inline void
1275 {
1276  if (klass.ok ())
1277  {
1278  cdef_class cls (get_class ());
1279 
1280  if (cls.ok ())
1281  cls.unregister_object ();
1282  }
1283 }
1284 
1285 inline cdef_object_rep*
1287 {
1288  cdef_object_rep *r = new cdef_object_array ();
1289 
1290  r->set_class (get_class ());
1291 
1292  return r;
1293 }
1294 
1295 inline cdef_method
1297 { return get_rep ()->find_method (nm, local); }
1298 
1299 inline cdef_property
1301 { return get_rep ()->find_property (nm); }
1302 
1303 class
1305 {
1306  friend class cdef_class;
1307 
1308 private:
1309 
1310  class
1312  {
1313  public:
1315  : cdef_meta_object_rep (), member_count (0) { }
1316 
1317  ~cdef_package_rep (void) = default;
1318 
1319  cdef_object_rep * copy (void) const { return new cdef_package_rep (*this); }
1320 
1321  bool is_package (void) const { return true; }
1322 
1323  std::string get_name (void) const { return get("Name").string_value (); }
1324 
1325  void set_name (const std::string& nm) { put ("Name", nm); }
1326 
1327  void install_class (const cdef_class& cls, const std::string& nm);
1328 
1329  void install_function (const octave_value& fcn, const std::string& nm);
1330 
1331  void install_package (const cdef_package& pack, const std::string& nm);
1332 
1333  Cell get_classes (void) const;
1334 
1335  Cell get_functions (void) const;
1336 
1337  Cell get_packages (void) const;
1338 
1339  octave_idx_type static_count (void) const { return member_count; }
1340 
1341  void destroy (void)
1342  {
1343  if (member_count)
1344  {
1345  refcount++;
1346  cdef_package lock (this);
1347 
1348  member_count = 0;
1349  class_map.clear ();
1350  package_map.clear ();
1351  }
1352  else
1353  delete this;
1354  }
1355 
1357  meta_subsref (const std::string& type,
1358  const std::list<octave_value_list>& idx, int nargout);
1359 
1360  void meta_release (void);
1361 
1363  { return (type == '.'); }
1364 
1365  octave_value find (const std::string& nm);
1366 
1367  private:
1369  std::map<std::string, cdef_class> class_map;
1370  std::map<std::string, octave_value> function_map;
1371  std::map<std::string, cdef_package> package_map;
1372 
1373  // The number of registered members in this package (classes, packages).
1374  // This only accounts for the members that back-reference to this package.
1376 
1377  typedef std::map<std::string, cdef_class>::iterator class_iterator;
1378  typedef std::map<std::string, cdef_class>::const_iterator class_const_iterator;
1379  typedef std::map<std::string, octave_value>::iterator function_iterator;
1380  typedef std::map<std::string, octave_value>::const_iterator function_const_iterator;
1381  typedef std::map<std::string, cdef_package>::iterator package_iterator;
1382  typedef std::map<std::string, cdef_package>::const_iterator package_const_iterator;
1383 
1385  : cdef_meta_object_rep (p), full_name (p.full_name),
1386  class_map (p.class_map), function_map (p.function_map),
1387  package_map (p.package_map), member_count (p.member_count)
1388  { }
1389 
1391  {
1392  refcount++;
1393  return cdef_package (this);
1394  }
1395  };
1396 
1397 public:
1399 
1402  { get_rep ()->set_name (nm); }
1403 
1405  : cdef_meta_object (pack) { }
1406 
1408  : cdef_meta_object (obj)
1409  {
1410  // This should never happen...
1411  if (! is_package ())
1412  error ("internal error: invalid assignment from %s to meta.package object",
1413  class_name ().c_str ());
1414  }
1415 
1417  {
1419 
1420  return *this;
1421  }
1422 
1423  void install_class (const cdef_class& cls, const std::string& nm)
1424  { get_rep ()->install_class (cls, nm); }
1425 
1427  { get_rep ()->install_function (fcn, nm); }
1428 
1429  void install_package (const cdef_package& pack, const std::string& nm)
1430  { get_rep ()->install_package (pack, nm); }
1431 
1432  Cell get_classes (void) const
1433  { return get_rep ()->get_classes (); }
1434 
1435  Cell get_functions (void) const
1436  { return get_rep ()->get_functions (); }
1437 
1438  Cell get_packages (void) const
1439  { return get_rep ()->get_packages (); }
1440 
1441  std::string get_name (void) const { return get_rep ()->get_name (); }
1442 
1443  octave_value find (const std::string& nm) { return get_rep ()->find (nm); }
1444 
1445 private:
1447  { return dynamic_cast<cdef_package_rep *> (cdef_object::get_rep ()); }
1448 
1449  const cdef_package_rep * get_rep (void) const
1450  { return dynamic_cast<const cdef_package_rep *> (cdef_object::get_rep ()); }
1451 
1452  friend void install_classdef (octave::interpreter& interp);
1453 };
1454 
1455 class
1457 {
1458 public:
1460  : octave_base_value (), object () { }
1461 
1463  : octave_base_value (), object (obj) { }
1464 
1466  : octave_base_value (obj), object (obj.object) { }
1467 
1468  octave_base_value * clone (void) const
1469  { return new octave_classdef (object.clone ()); }
1470 
1472  { return new octave_classdef (object.empty_clone ()); }
1473 
1474  octave_classdef * classdef_object_value (bool = false) { return this; }
1475 
1476  cdef_object get_object (void) const { return object; }
1477 
1478  cdef_object& get_object_ref (void) { return object; }
1479 
1480  bool is_defined (void) const { return true; }
1481 
1482  bool isstruct (void) const { return false; }
1483 
1484  bool isobject (void) const { return true; }
1485 
1486  bool is_classdef_object (void) const { return true; }
1487 
1488  void print (std::ostream& os, bool pr_as_read_syntax = false);
1489 
1490  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
1491 
1492  bool print_name_tag (std::ostream& os, const std::string& name) const;
1493 
1494  void print_with_name (std::ostream& os, const std::string& name,
1495  bool print_padding = true);
1496 
1497  bool is_instance_of (const std::string& cls_name) const;
1498 
1500  const std::list<octave_value_list>& idx,
1501  int nargout);
1502 
1504  const std::list<octave_value_list>& idx)
1505  {
1506  octave_value_list retval = subsref (type, idx, 1);
1507  return (retval.length () > 0 ? retval(0) : octave_value ());
1508  }
1509 
1511  const std::list<octave_value_list>& idx,
1512  bool auto_add);
1513 
1515  const std::list<octave_value_list>& idx,
1516  const octave_value& rhs);
1517 
1518  octave_value
1519  undef_subsasgn (const std::string& type,
1520  const std::list<octave_value_list>& idx,
1521  const octave_value& rhs);
1522 
1524 
1525  string_vector map_keys (void) const { return object.map_keys (); }
1526 
1527  octave_map map_value (void) const { return object.map_value (); }
1528 
1529  dim_vector dims (void) const { return object.dims (); }
1530 
1532  const octave_value& pval)
1533  {
1534  object.set_property (idx, name, pval);
1535  }
1536 
1537  octave_value
1539  {
1540  return object.get_property (idx, name);
1541  }
1542 
1543 public:
1544  int type_id (void) const { return t_id; }
1545  std::string type_name (void) const { return t_name; }
1546  std::string class_name (void) const { return object.class_name (); }
1547 
1548  static int static_type_id (void) { return t_id; }
1549  static std::string static_type_name (void) { return t_name; }
1550  static std::string static_class_name (void) { return "<unknown>"; }
1551  static void register_type (octave::type_info&);
1552 
1553 private:
1554 
1556 
1557  static int t_id;
1558 
1559  static const std::string t_name;
1560 };
1561 
1562 inline octave_value
1563 to_ov (const cdef_object& obj)
1564 {
1565  if (obj.ok ())
1566  return octave_value (new octave_classdef (obj));
1567  else
1568  return octave_value (Matrix ());
1569 }
1570 
1571 inline octave_value
1572 to_ov (const octave_value& ov)
1573 { return ov; }
1574 
1575 inline cdef_object
1577 {
1578  if (val.type_name () != "object")
1579  error ("cannot convert `%s' into `object'", val.type_name().c_str ());
1580 
1581  return dynamic_cast<octave_classdef *> (val.internal_rep ())->get_object ();
1582 }
1583 
1584 inline cdef_object&
1586 {
1587  if (val.type_name () != "object")
1588  error ("cannot convert `%s' into `object'", val.type_name().c_str ());
1589 
1590  return dynamic_cast<octave_classdef *> (val.internal_rep ())->get_object_ref ();
1591 }
1592 
1593 inline cdef_object
1594 to_cdef (const cdef_object& obj)
1595 { return obj; }
1596 
1597 OCTINTERP_API void install_classdef (octave::interpreter& interp);
1598 
1599 class
1601 {
1602 public:
1603 
1605 
1606  // No copying!
1607 
1608  cdef_manager (const cdef_manager&) = delete;
1609 
1610  cdef_manager& operator = (const cdef_manager&) = delete;
1611 
1612  ~cdef_manager (void) = default;
1613 
1614  cdef_class find_class (const std::string& name, bool error_if_not_found = true,
1615  bool load_if_not_found = true);
1616 
1617  octave_function * find_method_symbol (const std::string& method_name,
1618  const std::string& class_name);
1619 
1620  cdef_package find_package (const std::string& name,
1621  bool error_if_not_found = true,
1622  bool load_if_not_found = true);
1623 
1624  octave_function * find_package_symbol (const std::string& pack_name);
1625 
1626  void register_class (const cdef_class& cls)
1627  {
1628  m_all_classes[cls.get_name ()] = cls;
1629  }
1630 
1631  void unregister_class (const cdef_class& cls)
1632  {
1633  m_all_classes.erase(cls.get_name ());
1634  }
1635 
1636  void register_package (const cdef_package& pkg)
1637  {
1638  m_all_packages[pkg.get_name ()] = pkg;
1639  }
1640 
1642  {
1643  m_all_packages.erase (pkg.get_name ());
1644  }
1645 
1646  const cdef_class& meta_class (void) const { return m_meta_class; }
1647  const cdef_class& meta_property (void) const { return m_meta_property; }
1648  const cdef_class& meta_method (void) const { return m_meta_method; }
1649  const cdef_class& meta_package (void) const { return m_meta_package; }
1650 
1651  const cdef_package& meta (void) const { return m_meta; }
1652 
1653  cdef_class
1654  make_class (const std::string& name,
1655  const std::list<cdef_class>& super_list = std::list<cdef_class> ());
1656 
1657  cdef_class
1658  make_class (const std::string& name, const cdef_class& super);
1659 
1660  cdef_class
1661  make_meta_class (const std::string& name, const cdef_class& super);
1662 
1664  make_property (const cdef_class& cls, const std::string& name,
1665  const octave_value& get_method = Matrix (),
1666  const std::string& get_access = "public",
1667  const octave_value& set_method = Matrix (),
1668  const std::string& set_access = "public");
1669 
1671  make_attribute (const cdef_class& cls, const std::string& name);
1672 
1673  cdef_method
1674  make_method (const cdef_class& cls, const std::string& name,
1675  const octave_value& fcn,
1676  const std::string& m_access = "public",
1677  bool is_static = false);
1678 
1679  cdef_method
1680  make_method (const cdef_class& cls, const std::string& name,
1682  const std::string& m_access = "public",
1683  bool is_static = false);
1684 
1685  cdef_method
1686  make_method (const cdef_class& cls, const std::string& name,
1688  const std::string& m_access = "public",
1689  bool is_static = false);
1690 
1691  cdef_package
1692  make_package (const std::string& nm, const std::string& parent = "");
1693 
1694 private:
1695 
1697 
1698  // All registered/loaded classes
1699  std::map<std::string, cdef_class> m_all_classes;
1700 
1701  // All registered/loaded packages
1702  std::map<std::string, cdef_package> m_all_packages;
1703 
1708 
1710 };
1711 
1712 #endif
1713 
1714 /*
1715 ;;; Local Variables: ***
1716 ;;; mode: C++ ***
1717 ;;; End: ***
1718 */
void unregister_class(const cdef_class &cls)
Definition: ov-classdef.h:1631
cdef_object get_object(void) const
Definition: ov-classdef.h:1476
cdef_object_rep * copy(void) const
Definition: ov-classdef.h:558
virtual bool is_meta_object(void) const
Definition: ov-classdef.h:100
std::map< std::string, cdef_package > package_map
Definition: ov-classdef.h:1371
cdef_package(const std::string &nm)
Definition: ov-classdef.h:1400
octave_value get_property(octave_idx_type idx, const std::string &pname) const
Definition: ov-classdef.h:277
string_vector map_keys(void) const
Definition: ov-classdef.h:1525
void unregister_object(void)
Definition: ov-classdef.h:1274
bool check_get_access(void) const
Definition: ov-classdef.h:1070
bool is_meta_class(void) const
Definition: ov-classdef.h:758
octave::interpreter & m_interpreter
Definition: ov-classdef.h:1696
bool is_sealed(void) const
Definition: ov-classdef.h:690
void unregister_object(void)
Definition: ov-classdef.h:941
virtual cdef_class get_class(void) const
Definition: ov-classdef.h:1231
bool is_array(void) const
Definition: ov-classdef.h:256
octave_value find(const std::string &nm)
Definition: ov-classdef.h:1443
octave_value get_property(octave_idx_type idx, const std::string &pname) const
Definition: ov-classdef.h:467
Definition: Cell.h:37
octave::refcount< octave_idx_type > object_count
Definition: ov-classdef.h:801
void set_property(octave_idx_type idx, const std::string &pname, const octave_value &pval)
Definition: ov-classdef.h:403
virtual bool is_property(void) const
Definition: ov-classdef.h:589
const cdef_class & meta_method(void) const
Definition: ov-classdef.h:1648
cdef_class(void)
Definition: ov-classdef.h:822
OCTAVE_NORETURN void err_invalid_object(const char *who) const
Definition: ov-classdef.h:199
Cell get_properties(int mode=property_normal)
Definition: ov-classdef.h:860
bool is_package(void) const
Definition: ov-classdef.h:643
cdef_meta_object(const cdef_meta_object &obj)
Definition: ov-classdef.h:626
cdef_object make_array(void) const
Definition: ov-classdef.h:250
static bool check_access(const cdef_class &cls, const octave_value &acc, const std::string &meth_name="", const std::string &prop_name="", bool is_prop_set=false)
Definition: ov-classdef.cc:300
std::string type_name(void) const
Definition: ov-classdef.h:1545
octave_value_list execute(const cdef_object &obj, const octave_value_list &args, int nargout, bool do_check_access=true, const std::string &who="")
Definition: ov-classdef.h:1196
static cdef_class make_meta_class(octave::interpreter &interp, octave::tree_classdef *t, bool is_at_folder=false)
Analyze the tree_classdef tree and transform it to a cdef_class.
void install_method(const cdef_method &meth)
Definition: ov-classdef.h:850
virtual cdef_object_rep * make_array(void) const
Definition: ov-classdef.h:89
std::string get_name(void) const
Definition: ov-classdef.h:1107
void assign(const std::string &k, const Cell &val)
Definition: oct-map.h:351
cdef_method_rep(const cdef_method_rep &m)
Definition: ov-classdef.h:1143
octave_value_list subsref(const std::string &type, const std::list< octave_value_list > &idx, int nargout, size_t &skip, const cdef_class &context, bool auto_add=false)
Definition: ov-classdef.h:281
octave_idx_type member_count
Definition: ov-classdef.h:789
bool is_abstract(void) const
Definition: ov-classdef.h:869
cdef_object_rep * clone(void) const
Definition: ov-classdef.h:555
cdef_object empty_clone(void) const
Definition: ov-classdef.h:245
std::map< std::string, octave_value >::const_iterator function_const_iterator
Definition: ov-classdef.h:1380
cdef_object_base(void)
Definition: ov-classdef.h:337
bool is_value_object(void) const
Definition: ov-classdef.h:562
virtual bool is_constructed_for(const cdef_class &) const
Definition: ov-classdef.h:151
cdef_meta_object(cdef_meta_object_rep *r)
Definition: ov-classdef.h:629
void set_value(cdef_object &obj, const octave_value &val, bool do_check_access=true, const std::string &who="")
Definition: ov-classdef.h:1065
dim_vector dims(void) const
Definition: ov-classdef.h:248
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:4986
cdef_object & operator=(const cdef_object &obj)
Definition: ov-classdef.h:222
bool is_external(void) const
Definition: ov-classdef.h:1119
cdef_object clone(void) const
Definition: ov-classdef.h:242
bool is_partially_constructed_for(const cdef_class &cls) const
Definition: ov-classdef.h:310
bool meta_accepts_postfix_index(char type) const
Definition: ov-classdef.h:720
void set_name(const std::string &nm)
Definition: ov-classdef.h:1325
Return the CPU time used by your Octave session The first output is the total time spent executing your process and is equal to the sum of second and third which are the number of CPU seconds spent executing in user mode and the number of CPU seconds spent executing in system mode
Definition: data.cc:6348
cdef_method(const cdef_method &meth)
Definition: ov-classdef.h:1170
idx subsref(val, idx) esult
Definition: ov.cc:3065
cdef_object_rep * copy(void) const
Definition: ov-classdef.h:1103
Cell get_functions(void) const
Definition: ov-classdef.h:1435
std::string get_name(void) const
Definition: ov-classdef.h:1204
void register_object(void)
Definition: ov-classdef.h:1262
virtual bool is_valid(void) const
Definition: ov-classdef.h:142
void mark_for_construction(const cdef_class &cls)
Definition: ov-classdef.h:302
cdef_property(const std::string &nm)
Definition: ov-classdef.h:1034
const cdef_property_rep * get_rep(void) const
Definition: ov-classdef.h:1084
void put(const std::string &pname, const octave_value &val)
Definition: ov-classdef.h:444
bool is_external(void) const
Definition: ov-classdef.h:1217
bool is_sealed(void) const
Definition: ov-classdef.h:871
const cdef_class_rep * get_rep(void) const
Definition: ov-classdef.h:955
Array< cdef_object > array
Definition: ov-classdef.h:420
octave_value_list(* fcn)(const octave_value_list &, int)
Definition: ov-builtin.h:60
void install_package(const cdef_package &pack, const std::string &nm)
Definition: ov-classdef.h:1429
std::map< std::string, cdef_class > m_all_classes
Definition: ov-classdef.h:1699
cdef_meta_object_rep(const cdef_meta_object_rep &obj)
Definition: ov-classdef.h:610
void mark_as_constructed(const cdef_class &cls)
Definition: ov-classdef.h:315
void error(const char *fmt,...)
Definition: error.cc:578
bool is_handle_class(void) const
Definition: ov-classdef.h:733
bool is_handle_object(void) const
Definition: ov-classdef.h:534
void release(const cdef_object &obj)
virtual octave_value_list meta_subsref(const std::string &, const std::list< octave_value_list > &, int)
Definition: ov-classdef.h:596
cdef_object_array(const Array< cdef_object > &a)
Definition: ov-classdef.h:380
cdef_object & to_cdef_ref(const octave_value &val)
Definition: ov-classdef.h:1585
void register_object(void)
Definition: ov-classdef.h:939
std::map< cdef_class, std::list< cdef_class > > ctor_list
Definition: ov-classdef.h:501
void register_class(const cdef_class &cls)
Definition: ov-classdef.h:1626
cdef_meta_object(const cdef_object &obj)
Definition: ov-classdef.h:632
bool is_valid(void) const
Definition: ov-classdef.h:532
virtual Array< cdef_object > array_value(void) const
Definition: ov-classdef.h:102
bool is_method(void) const
Definition: ov-classdef.h:1105
bool isobject(void) const
Definition: ov-classdef.h:1484
static llvm::LLVMContext & context
Definition: jit-typeinfo.cc:79
const cdef_class & meta_package(void) const
Definition: ov-classdef.h:1649
virtual bool is_partially_constructed_for(const cdef_class &) const
Definition: ov-classdef.h:156
Cell get_classes(void) const
Definition: ov-classdef.h:1432
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function t
Definition: ov-usr-fcn.cc:997
cdef_object_rep * copy(void) const
Definition: ov-classdef.h:993
bool is_value_object(void) const
Definition: ov-classdef.h:258
virtual octave_idx_type static_count(void) const
Definition: ov-classdef.h:176
void register_package(const cdef_package &pkg)
Definition: ov-classdef.h:1636
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
Definition: file-io.cc:587
void set_property(octave_idx_type idx, const std::string &name, const octave_value &pval)
Definition: ov-classdef.h:1531
bool check_access(void) const
Definition: ov-classdef.h:1202
virtual void meta_release(void)
Definition: ov-classdef.h:603
void set_name(const std::string &nm)
Definition: ov-classdef.h:686
std::string get_name(void) const
Definition: ov-classdef.h:1323
std::map< std::string, cdef_class >::iterator class_iterator
Definition: ov-classdef.h:1377
void fill_empty_values(void)
Definition: ov-classdef.h:422
handle_cdef_object(const handle_cdef_object &obj)
Definition: ov-classdef.h:538
virtual bool is_handle_object(void) const
Definition: ov-classdef.h:98
virtual bool is_value_object(void) const
Definition: ov-classdef.h:96
std::string get_name(void) const
Definition: ov-classdef.h:683
const cdef_package_rep * get_rep(void) const
Definition: ov-classdef.h:1449
cdef_package m_meta
Definition: ov-classdef.h:1709
octave_function * fcn
Definition: ov-class.cc:1754
std::map< std::string, cdef_property >::iterator property_iterator
Definition: ov-classdef.h:809
Array< cdef_object > array_value(void) const
Definition: ov-classdef.h:392
virtual string_vector map_keys(void) const
cdef_class wrap(void)
Definition: ov-classdef.h:772
cdef_property_rep(const cdef_property_rep &p)
Definition: ov-classdef.h:1019
void set_name(const std::string &nm)
Definition: ov-classdef.h:1109
virtual void mark_as_constructed(void)
Definition: ov-classdef.h:161
void initialize_object(cdef_object &obj)
Definition: ov-classdef.h:923
std::map< std::string, cdef_property >::const_iterator property_const_iterator
Definition: ov-classdef.h:810
octave_idx_type static_count(void) const
Definition: ov-classdef.h:1339
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
Definition: cellfun.cc:400
cdef_class & operator=(const cdef_class &cls)
Definition: ov-classdef.h:841
bool is_classdef_object(void) const
Definition: ov-classdef.h:1486
bool is_abstract(void) const
Definition: ov-classdef.h:688
bool is_handle_object(void) const
Definition: ov-classdef.h:260
virtual bool meta_accepts_postfix_index(char) const
Definition: ov-classdef.h:605
then the function must return scalars which will be concatenated into the return array(s). If code
Definition: cellfun.cc:400
cdef_object_rep * make_array(void) const
Definition: ov-classdef.h:1286
std::string class_name(void) const
Definition: ov-classdef.h:1237
bool is_static(void) const
Definition: ov-classdef.h:1111
virtual octave_value get(const std::string &) const
Definition: ov-classdef.h:110
cdef_method(void)
Definition: ov-classdef.h:1164
void set_property(octave_idx_type idx, const std::string &pname, const octave_value &pval)
Definition: ov-classdef.h:457
nd deftypefn *std::string name
Definition: sysdep.cc:647
void install_class(const cdef_class &cls, const std::string &nm)
Definition: ov-classdef.h:1423
cdef_package_rep * get_rep(void)
Definition: ov-classdef.h:1446
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
Definition: utils.cc:975
std::map< std::string, cdef_package >::const_iterator package_const_iterator
Definition: ov-classdef.h:1382
virtual bool is_constructed(void) const
Definition: ov-classdef.h:171
void set_directory(const std::string &dir)
Definition: ov-classdef.h:873
cdef_object_rep * rep
Definition: ov-classdef.h:330
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:997
cdef_object copy(void) const
Definition: ov-classdef.h:253
bool is_valid(void) const
Definition: ov-classdef.h:560
cdef_method find_method(const std::string &nm, bool local=false)
Definition: ov-classdef.h:1296
int type_id(void) const
Definition: ov-classdef.h:1544
Array< cdef_object > array_value(void) const
Definition: ov-classdef.h:264
cdef_object_rep * empty_clone(void) const
Definition: ov-classdef.h:349
OCTINTERP_API void install_classdef(octave::interpreter &interp)
octave_function * get_constructor_function(void)
Definition: ov-classdef.h:914
const cdef_object_rep * get_rep(void) const
Definition: ov-classdef.h:298
create a structure array and initialize its values The dimensions of each cell array of values must match Singleton cells and non cell values are repeated so that they fill the entire array If the cells are create an empty structure array with the specified field names If the argument is an object
Definition: ov-struct.cc:1736
virtual octave_value get_property(octave_idx_type, const std::string &) const
Definition: ov-classdef.h:121
cdef_object_base(const cdef_object_base &obj)
Definition: ov-classdef.h:356
void set_property(octave_idx_type idx, const std::string &pname, const octave_value &pval)
Definition: ov-classdef.h:272
octave_value get_value(bool do_check_access=true, const std::string &who="")
Definition: ov-classdef.h:1061
cdef_object_rep * get_rep(void)
Definition: ov-classdef.h:321
virtual octave_value subsasgn(const std::string &, const std::list< octave_value_list > &, const octave_value &)
Definition: ov-classdef.h:134
bool is_meta_object(void) const
Definition: ov-classdef.h:262
virtual void put(const std::string &, const octave_value &)
Definition: ov-classdef.h:107
void mark_as_external(const std::string &dtype)
Definition: ov-classdef.h:1219
void put(const std::string &pname, const octave_value &val)
Definition: ov-classdef.h:266
~cdef_object_base(void)
Definition: ov-classdef.h:343
cdef_object_rep * copy(void) const
Definition: ov-classdef.h:529
bool operator<(const cdef_class &clsa, const cdef_class &clsb)
Definition: ov-classdef.h:976
virtual void mark_for_construction(const cdef_class &)
Definition: ov-classdef.h:146
bool is_defined(void) const
Definition: ov-classdef.h:1480
bool meta_accepts_postfix_index(char type) const
Definition: ov-classdef.h:1362
octave_value_list execute(const octave_value_list &args, int nargout, bool do_check_access=true, const std::string &who="")
Definition: ov-classdef.h:1190
bool is_array(void) const
Definition: ov-classdef.h:390
bool is_constructed_for(const cdef_class &cls) const
Definition: ov-classdef.h:307
std::list< cdef_class > implicit_ctor_list
Definition: ov-classdef.h:798
octave_value to_ov(const cdef_object &obj)
Definition: ov-classdef.h:1563
void set_name(const std::string &nm)
Definition: ov-classdef.h:999
cdef_property(const cdef_property &prop)
Definition: ov-classdef.h:1038
cdef_method(const std::string &nm)
Definition: ov-classdef.h:1166
std::string get_name(void) const
Definition: ov-classdef.h:997
virtual void set_property(octave_idx_type, const std::string &, const octave_value &)
Definition: ov-classdef.h:115
cdef_package(void)
Definition: ov-classdef.h:1398
virtual void mark_as_constructed(const cdef_class &)
Definition: ov-classdef.h:166
double tmp
Definition: data.cc:6252
virtual bool is_class(void) const
Definition: ov-classdef.h:587
is false
Definition: cellfun.cc:400
const cdef_package & meta(void) const
Definition: ov-classdef.h:1651
octave_value retval
Definition: data.cc:6246
cdef_object object
Definition: ov-classdef.h:1555
octave_value get_function(void) const
Definition: ov-classdef.h:1211
static int static_type_id(void)
Definition: ov-classdef.h:1548
virtual ~cdef_object(void)
Definition: ov-classdef.h:217
octave_value_list(* meth)(octave::interpreter &, const octave_value_list &, int)
Definition: ov-builtin.h:57
const Cell & contents(const_iterator p) const
Definition: oct-map.h:317
bool is_property(void) const
Definition: ov-classdef.h:639
bool is_handle_class(void) const
Definition: ov-classdef.h:932
cdef_object klass
Definition: ov-classdef.h:368
cdef_package(const cdef_package &pack)
Definition: ov-classdef.h:1404
cdef_object_rep(const cdef_object_rep &)
Definition: ov-classdef.h:193
octave_classdef(const cdef_object &obj)
Definition: ov-classdef.h:1462
cdef_meta_object(void)
Definition: ov-classdef.h:622
const cdef_meta_object_rep * get_rep(void) const
Definition: ov-classdef.h:659
idx type
Definition: ov.cc:3114
Cell get_packages(void) const
Definition: ov-classdef.h:1438
std::string get_directory(void) const
Definition: ov-classdef.h:876
cdef_method_rep * get_rep(void)
Definition: ov-classdef.h:1223
Definition: dMatrix.h:36
void mark_as_meta_class(void)
Definition: ov-classdef.h:935
cdef_class get_class(void) const
Definition: ov-classdef.h:1245
std::string release(void)
Definition: defaults.cc:266
virtual cdef_object_rep * copy(void) const
Definition: ov-classdef.h:84
std::map< std::string, cdef_package >::iterator package_iterator
Definition: ov-classdef.h:1381
virtual cdef_object_rep * clone(void) const
Definition: ov-classdef.h:74
virtual void destroy(void)
Definition: ov-classdef.h:178
dim_vector dims(void) const
Definition: ov-classdef.h:1529
octave_value construct(const octave_value_list &args)
Definition: ov-classdef.h:917
void install_function(const octave_value &fcn, const std::string &nm)
Definition: ov-classdef.h:1426
std::string pname
Definition: graphics.cc:11810
cdef_object_rep * clone(void) const
Definition: ov-classdef.h:522
cdef_object_scalar(const cdef_object_scalar &obj)
Definition: ov-classdef.h:505
bool is_constructed(void) const
Definition: ov-classdef.h:494
cdef_property find_property(const std::string &nm)
Definition: ov-classdef.h:1300
bool isstruct(void) const
Definition: ov-classdef.h:1482
cdef_object(const cdef_object &obj)
Definition: ov-classdef.h:211
cdef_object(void)
Definition: ov-classdef.h:208
cdef_object_rep * copy(void) const
Definition: ov-classdef.h:679
cdef_object & get_object_ref(void)
Definition: ov-classdef.h:1478
cdef_class(const cdef_class &cls)
Definition: ov-classdef.h:829
static octave_idx_type find(octave_idx_type i, octave_idx_type *pp)
Definition: colamd.cc:103
octave_map map_value(void) const
cdef_property find_property(const std::string &nm)
octave_base_value * clone(void) const
Definition: ov-classdef.h:1468
virtual void set_class(const cdef_class &)
Definition: ov-classdef.h:71
octave_value get_property(octave_idx_type idx, const std::string &pname) const
Definition: ov-classdef.h:412
bool ok(void) const
Definition: ov-classdef.h:300
bool is_static(void) const
Definition: ov-classdef.h:1206
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
virtual octave_value_list subsref(const std::string &, const std::list< octave_value_list > &, int, size_t &, const cdef_class &, bool)
Definition: ov-classdef.h:127
cdef_class m_meta_package
Definition: ov-classdef.h:1707
bool operator!=(const cdef_class &clsa, const cdef_class &clsb)
Definition: ov-classdef.h:971
static int t_id
Definition: ov-classdef.h:1557
void make_unique(int ignore_copies)
Definition: ov-classdef.h:323
std::map< std::string, octave_value > function_map
Definition: ov-classdef.h:1370
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
Definition: ov-classdef.h:1503
bool is_valid(void) const
Definition: ov-classdef.h:388
T::size_type numel(const T &str)
Definition: oct-string.cc:61
bool check_set_access(void) const
Definition: ov-classdef.h:1073
string_vector map_keys(void) const
Definition: ov-classdef.h:294
octave_value get_property(octave_idx_type idx, const std::string &name) const
Definition: ov-classdef.h:1538
bool is_constant(void) const
Definition: ov-classdef.h:1078
octave::refcount< octave_idx_type > refcount
Definition: ov-classdef.h:187
cdef_object to_cdef(const octave_value &val)
Definition: ov-classdef.h:1576
bool is_constructed(void) const
Definition: ov-classdef.h:305
std::map< std::string, cdef_package > m_all_packages
Definition: ov-classdef.h:1702
bool is_meta_class(void) const
Definition: ov-classdef.h:937
std::string get_name(void) const
Definition: ov-classdef.h:879
void mark_as_handle_class(void)
Definition: ov-classdef.h:929
static const std::string t_name
Definition: ov-classdef.h:1559
std::map< std::string, cdef_class >::const_iterator class_const_iterator
Definition: ov-classdef.h:1378
std::map< std::string, cdef_property > property_map
Definition: ov-classdef.h:786
void set_class(const cdef_class &cls)
Definition: ov-classdef.h:237
void run_constructor(cdef_object &obj, const octave_value_list &args)
Definition: ov-classdef.h:926
static std::string static_class_name(void)
Definition: ov-classdef.h:1550
cdef_object construct_object(const octave_value_list &args)
Definition: ov-classdef.h:920
dim_vector dims(void) const
Definition: ov-classdef.h:386
std::map< std::string, cdef_method > method_map
Definition: ov-classdef.h:783
p
Definition: lu.cc:138
std::map< std::string, cdef_property > get_property_map(int mode=property_normal)
Definition: ov-classdef.h:864
octave_classdef(const octave_classdef &obj)
Definition: ov-classdef.h:1465
int register_type(const std::string &t_name, const std::string &c_name, const octave_value &val)
Definition: ov-typeinfo.cc:762
void mark_as_external(const std::string &dtype)
Definition: ov-classdef.h:1121
cdef_class_rep(const cdef_class_rep &c)
Definition: ov-classdef.h:812
octave_map map(dims)
virtual bool is_method(void) const
Definition: ov-classdef.h:591
cdef_object(cdef_object_rep *r)
Definition: ov-classdef.h:214
const cdef_method_rep * get_rep(void) const
Definition: ov-classdef.h:1226
void mark_as_constructed(void)
Definition: ov-classdef.h:490
virtual dim_vector dims(void) const
Definition: ov-classdef.h:182
bool is_class(void) const
Definition: ov-classdef.h:637
bool is(const cdef_object &obj) const
Definition: ov-classdef.h:318
idx subsasgn(val, idx, 0) esult
Definition: ov.cc:3114
cdef_class_rep * get_rep(void)
Definition: ov-classdef.h:952
void meta_release(void)
Definition: ov-classdef.h:650
std::string get_name(void) const
Definition: ov-classdef.h:1441
cdef_class m_meta_property
Definition: ov-classdef.h:1705
std::string get_name(void) const
Definition: ov-classdef.h:1076
const cdef_class & meta_property(void) const
Definition: ov-classdef.h:1647
std::string class_name(void) const
Definition: ov-classdef.h:1546
cdef_class m_meta_class
Definition: ov-classdef.h:1704
cdef_class m_meta_method
Definition: ov-classdef.h:1706
std::map< std::string, octave_value >::iterator function_iterator
Definition: ov-classdef.h:1379
cdef_class(const cdef_object &obj)
Definition: ov-classdef.h:832
bool is_method(void) const
Definition: ov-classdef.h:641
std::map< std::string, cdef_method >::const_iterator method_const_iterator
Definition: ov-classdef.h:808
const cdef_class & meta_class(void) const
Definition: ov-classdef.h:1646
cdef_property(void)
Definition: ov-classdef.h:1032
std::map< std::string, cdef_method >::iterator method_iterator
Definition: ov-classdef.h:807
cdef_property_rep * get_rep(void)
Definition: ov-classdef.h:1081
is a function function
Definition: bsxfun.cc:337
void mark_as_constructed(void)
Definition: ov-classdef.h:313
cdef_class(const std::string &nm, const std::list< cdef_class > &superclasses)
Definition: ov-classdef.h:825
virtual bool is_package(void) const
Definition: ov-classdef.h:593
value_cdef_object(const value_cdef_object &obj)
Definition: ov-classdef.h:566
cdef_object_array(const cdef_object_array &obj)
Definition: ov-classdef.h:427
cdef_object_rep * copy(void) const
Definition: ov-classdef.h:582
cdef_method find_method(const std::string &nm, bool local=false)
octave_value get_value(const cdef_object &obj, bool do_check_access=true, const std::string &who="")
Definition: ov-classdef.h:1057
Cell get_methods(void)
Definition: ov-classdef.h:853
bool operator==(const cdef_class &clsa, const cdef_class &clsb)
Definition: ov-classdef.h:966
virtual bool is_array(void) const
Definition: ov-classdef.h:94
cdef_property(const cdef_object &obj)
Definition: ov-classdef.h:1041
static std::string static_type_name(void)
Definition: ov-classdef.h:1549
bool is_constructor(void) const
Definition: ov-classdef.h:1214
bool is_meta_object(void) const
Definition: ov-classdef.h:585
void set_function(const octave_value &fcn)
Definition: ov-classdef.h:1115
bool meta_accepts_postfix_index(char type) const
Definition: ov-classdef.h:652
octave_classdef * classdef_object_value(bool=false)
Definition: ov-classdef.h:1474
cdef_object_rep * copy(void) const
Definition: ov-classdef.h:1319
octave_idx_type length(void) const
void set_directory(const std::string &dir)
Definition: ov-classdef.h:708
cdef_method(const cdef_object &obj)
Definition: ov-classdef.h:1173
void unregister_package(const cdef_package &pkg)
Definition: ov-classdef.h:1641
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
cdef_object_rep * clone(void) const
Definition: ov-classdef.h:383
void set_class(const cdef_class &cls)
Definition: ov-classdef.h:1249
void install_property(const cdef_property &prop)
Definition: ov-classdef.h:857
bool meta_accepts_postfix_index(char type) const
Definition: ov-classdef.h:1139
octave_map map_value(void) const
Definition: ov-classdef.h:1527
cdef_object_rep(void)
Definition: ov-classdef.h:62
string_vector get_names(void)
Definition: ov-classdef.h:867
octave_value get_function(void) const
Definition: ov-classdef.h:1113
cdef_package(const cdef_object &obj)
Definition: ov-classdef.h:1407
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:888
cdef_meta_object_rep * get_rep(void)
Definition: ov-classdef.h:656
octave_scalar_map map
Definition: ov-classdef.h:498
bool is_builtin(void) const
Definition: ov-classdef.h:882
octave_value_list meta_subsref(const std::string &type, const std::list< octave_value_list > &idx, int nargout)
Definition: ov-classdef.h:646
bool is_class(void) const
Definition: ov-classdef.h:681
virtual cdef_object_rep * empty_clone(void) const
Definition: ov-classdef.h:79
std::string get_directory(void) const
Definition: ov-classdef.h:710
cdef_package_rep(const cdef_package_rep &p)
Definition: ov-classdef.h:1384
dim_vector dims(void) const
Definition: ov-classdef.h:442
octave::stream os
Definition: file-io.cc:627
cdef_class get_class(void) const
Definition: ov-classdef.h:1241
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs, int ignore_copies=0)
Definition: ov-classdef.h:287
void delete_object(const cdef_object &obj)
Definition: ov-classdef.h:885
void set_function(const octave_value &fcn)
Definition: ov-classdef.h:1208
octave_base_value * empty_clone(void) const
Definition: ov-classdef.h:1471
std::map< std::string, cdef_class > class_map
Definition: ov-classdef.h:1369
octave_idx_type static_count(void) const
Definition: ov-classdef.h:739
std::string class_name(void) const
Definition: ov-classdef.h:239
OCTAVE_EXPORT octave_value_list directory
Definition: variables.cc:593