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