annotate libinterp/octave-value/ov-classdef.h @ 15910:dfd0dc594c4f classdef

Add object counting to cdef_class. * libinterp/octave-value/ov-classdef.h (cdef_class::cdef_class_rep::object_count): New member. (cdef_class::cdef_class_rep::cdef_class_rep): Initialize it. (cdef_class::cdef_class_rep::register_object, cdef_class::cdef_class_rep::unregister_object): New methods. (cdef_class::register_object, cdef_class::unregister_object): Likewise. (cdef_object_base::set_class, cdef_object_base::register_object, cdef_object_base::unregister_object): Use them. * libinterp/octave_value/ov-classdef.cc (cdef_class::cdef_class_rep::cdef_class_rep (std::list<cdef_class>)): Initialize object_count.
author Michael Goffioul <michael.goffioul@gmail.com>
date Sun, 06 Jan 2013 15:45:28 -0500
parents b8bff84022d6
children b18b7e560236
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1 /*
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3 Copyright (C) 2012 Michael Goffioul
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
4
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
5 This file is part of Octave.
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
6
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
10 option) any later version.
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
11
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
15 for more details.
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
16
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, see
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>.
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
20
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
21 */
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
22
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
23 #if !defined (octave_classdef_h)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
24 #define octave_classdef_h 1
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
25
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
26 #include <set>
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
27 #include <string>
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
28
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
29 #include "oct-map.h"
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
30 #include "oct-refcount.h"
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
31 #include "ov-base.h"
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
32
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
33 class cdef_object;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
34 class cdef_class;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
35 class cdef_property;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
36 class cdef_method;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
37 class cdef_package;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
38
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
39 class tree_classdef;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
40
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
41 // This is mainly a boostrap class to declare the expected interface.
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
42 // The actual base class is cdef_class_base, which is declared after
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
43 // cdef_object, such that it can contain cdef_object objects.
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
44 class
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
45 cdef_object_rep
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
46 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
47 public:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
48 friend class cdef_object;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
49
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
50 public:
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
51 cdef_object_rep (void) : refcount (1) { }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
52
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
53 virtual ~cdef_object_rep (void) { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
54
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
55 virtual cdef_class get_class (void) const;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
56
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
57 virtual void set_class (const cdef_class&)
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
58 { gripe_invalid_object ("set_class"); }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
59
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
60 virtual cdef_object_rep* clone (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
61 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
62 gripe_invalid_object ("clone");
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
63 return new cdef_object_rep ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
64 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
65
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
66 virtual bool is_class (void) const { return false; }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
67
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
68 virtual bool is_property (void) const { return false; }
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
69
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
70 virtual bool is_method (void) const { return false; }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
71
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
72 virtual bool is_package (void) const { return false; }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
73
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
74 virtual void put (const std::string&, const octave_value&)
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
75 { gripe_invalid_object ("put"); }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
76
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
77 virtual octave_value get (const std::string&) const
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
78 {
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
79 gripe_invalid_object ("get");
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
80 return octave_value ();
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
81 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
82
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
83 virtual octave_value_list
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
84 subsref (const std::string&, const std::list<octave_value_list>&,
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
85 int, size_t&, const cdef_class&)
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
86 {
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
87 gripe_invalid_object ("subsref");
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
88 return octave_value_list ();
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
89 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
90
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
91 virtual octave_value
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
92 subsasgn (const std::string&, const std::list<octave_value_list>&,
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
93 const octave_value&)
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
94 {
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
95 gripe_invalid_object ("subsasgn");
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
96 return octave_value ();
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
97 }
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
98
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
99 virtual string_vector map_keys(void) const;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
100
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
101 virtual bool is_valid (void) const { return false; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
102
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
103 std::string class_name (void) const;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
104
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
105 virtual void mark_for_construction (const cdef_class&)
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
106 { gripe_invalid_object ("mark_for_construction"); }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
107
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
108 virtual bool is_constructed_for (const cdef_class&) const
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
109 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
110 gripe_invalid_object ("is_constructed_for");
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
111 return false;
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
112 }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
113
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
114 virtual bool is_partially_constructed_for (const cdef_class&) const
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
115 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
116 gripe_invalid_object ("is_partially_constructed_for");
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
117 return false;
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
118 }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
119
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
120 virtual void mark_as_constructed (void)
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
121 { gripe_invalid_object ("mark_as_constructed"); }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
122
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
123 virtual void mark_as_constructed (const cdef_class&)
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
124 { gripe_invalid_object ("mark_as_constructed"); }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
125
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
126 virtual bool is_constructed (void) const
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
127 {
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
128 gripe_invalid_object ("is_constructed");
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
129 return false;
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
130 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
131
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
132 protected:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
133 /* reference count */
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
134 octave_refcount<int> refcount;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
135
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
136 protected:
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
137 /* Restricted copying */
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
138 cdef_object_rep (const cdef_object_rep&)
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
139 : refcount (1) { }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
140
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
141 private:
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
142 /* No assignment */
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
143 cdef_object_rep& operator = (const cdef_object_rep& );
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
144
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
145 void gripe_invalid_object (const char *who) const
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
146 { error ("%s: invalid object", who); }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
147 };
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
148
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
149 class
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
150 cdef_object
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
151 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
152 public:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
153 /* FIXME: use a null object */
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
154 cdef_object (void)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
155 : rep (new cdef_object_rep ()) { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
156
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
157 cdef_object (const cdef_object& obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
158 : rep (obj.rep)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
159 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
160 rep->refcount++;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
161 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
162
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
163 cdef_object (cdef_object_rep *r)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
164 : rep (r) { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
165
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
166 virtual ~cdef_object (void)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
167 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
168 if (--rep->refcount == 0)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
169 delete rep;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
170 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
171
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
172 cdef_object& operator = (const cdef_object& obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
173 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
174 if (rep != obj.rep)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
175 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
176 if (--rep->refcount == 0)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
177 delete rep;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
178
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
179 rep = obj.rep;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
180 rep->refcount++;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
181 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
182
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
183 return *this;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
184 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
185
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
186 cdef_class get_class (void) const;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
187
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
188 void set_class (const cdef_class& cls) { rep->set_class (cls); }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
189
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
190 std::string class_name (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
191 { return rep->class_name (); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
192
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
193 cdef_object clone (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
194 { return cdef_object (rep->clone ()); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
195
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
196 bool is_class (void) const { return rep->is_class (); }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
197
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
198 bool is_property (void) const { return rep->is_property (); }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
199
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
200 bool is_method (void) const { return rep->is_method (); }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
201
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
202 bool is_package (void) const { return rep->is_package (); }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
203
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
204 void put (const std::string& pname, const octave_value& val)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
205 { rep->put (pname, val); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
206
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
207 octave_value get (const std::string& pname) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
208 { return rep->get (pname); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
209
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
210 octave_value_list
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
211 subsref (const std::string& type, const std::list<octave_value_list>& idx,
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
212 int nargout, size_t& skip, const cdef_class& context)
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
213 { return rep->subsref (type, idx, nargout, skip, context); }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
214
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
215 octave_value
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
216 subsasgn (const std::string& type, const std::list<octave_value_list>& idx,
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
217 const octave_value& rhs)
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
218 { return rep->subsasgn (type, idx, rhs); }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
219
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
220 string_vector map_keys (void) const { return rep->map_keys (); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
221
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
222 const cdef_object_rep* get_rep (void) const { return rep; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
223
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
224 bool ok (void) const { return rep->is_valid (); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
225
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
226 void mark_for_construction (const cdef_class& cls)
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
227 { rep->mark_for_construction (cls); }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
228
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
229 bool is_constructed (void) const { return rep->is_constructed (); }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
230
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
231 bool is_constructed_for (const cdef_class& cls) const
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
232 { return rep->is_constructed_for (cls); }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
233
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
234 bool is_partially_constructed_for (const cdef_class& cls) const
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
235 { return rep->is_partially_constructed_for (cls); }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
236
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
237 void mark_as_constructed (void) { rep->mark_as_constructed (); }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
238
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
239 void mark_as_constructed (const cdef_class& cls)
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
240 { rep->mark_as_constructed (cls); }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
241
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
242 protected:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
243 cdef_object_rep* get_rep (void) { return rep; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
244
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
245 private:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
246 cdef_object_rep *rep;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
247 };
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
248
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
249 class
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
250 cdef_object_base : public cdef_object_rep
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
251 {
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
252 public:
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
253 cdef_object_base (void)
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
254 : cdef_object_rep (), klass ()
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
255 {
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
256 register_object ();
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
257 }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
258
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
259 ~cdef_object_base (void) { unregister_object (); }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
260
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
261 cdef_class get_class (void) const;
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
262
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
263 void set_class (const cdef_class& cls);
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
264
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
265 protected:
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
266 // Restricted copying!
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
267 cdef_object_base (const cdef_object_base& obj)
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
268 : cdef_object_rep (obj), klass (obj.klass)
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
269 {
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
270 register_object ();
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
271 }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
272
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
273 private:
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
274 void register_object (void);
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
275
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
276 void unregister_object (void);
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
277
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
278 private:
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
279 // The class of the object
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
280 cdef_object klass;
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
281
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
282 private:
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
283 // No assignment!
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
284 cdef_object_base& operator = (const cdef_object_base&);
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
285 };
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
286
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
287 class
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
288 cdef_object_scalar : public cdef_object_base
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
289 {
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
290 public:
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
291 cdef_object_scalar (void) : cdef_object_base () { }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
292
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
293 ~cdef_object_scalar (void) { }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
294
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
295 void put (const std::string& pname, const octave_value& val)
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
296 { map.assign (pname, val); }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
297
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
298 octave_value get (const std::string& pname) const
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
299 {
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
300 Cell val = map.contents (pname);
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
301
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
302 if (val.numel () > 0)
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
303 return val(0, 0);
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
304 else
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
305 {
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
306 error ("get: unknown slot: %s", pname.c_str ());
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
307 return octave_value ();
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
308 }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
309 }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
310
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
311 octave_value_list
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
312 subsref (const std::string& type, const std::list<octave_value_list>& idx,
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
313 int nargout, size_t& skip, const cdef_class& context);
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
314
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
315 octave_value
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
316 subsasgn (const std::string& type, const std::list<octave_value_list>& idx,
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
317 const octave_value& rhs);
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
318
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
319 void mark_for_construction (const cdef_class&);
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
320
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
321 bool is_constructed_for (const cdef_class& cls) const;
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
322
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
323 bool is_partially_constructed_for (const cdef_class& cls) const;
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
324
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
325 void mark_as_constructed (void) { ctor_list.clear (); }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
326
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
327 void mark_as_constructed (const cdef_class& cls) { ctor_list.erase (cls); }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
328
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
329 bool is_constructed (void) const { return ctor_list.empty (); }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
330
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
331 protected:
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
332 // Object property values
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
333 Octave_map map;
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
334
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
335 // Internal/temporary structure used during object construction
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
336 std::map< cdef_class, std::list<cdef_class> > ctor_list;
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
337
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
338 protected:
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
339 // Restricted object copying!
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
340 cdef_object_scalar (const cdef_object_scalar& obj)
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
341 : cdef_object_base (obj), map (obj.map), ctor_list (obj.ctor_list) { }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
342
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
343 private:
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
344 // No assignment!
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
345 cdef_object_scalar& operator = (const cdef_object_scalar&);
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
346 };
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
347
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
348 class
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
349 handle_cdef_object : public cdef_object_scalar
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
350 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
351 public:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
352 handle_cdef_object (void)
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
353 : cdef_object_scalar () { }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
354
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
355 ~handle_cdef_object (void);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
356
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
357 cdef_object_rep* clone (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
358 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
359 handle_cdef_object *obj = const_cast<handle_cdef_object *> (this);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
360 obj->refcount++;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
361 return obj;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
362 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
363
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
364 bool is_valid (void) const { return true; }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
365
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
366 private:
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
367 // No copying
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
368 handle_cdef_object (const handle_cdef_object&);
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
369 handle_cdef_object& operator = (const handle_cdef_object&);
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
370 };
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
371
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
372 class
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
373 value_cdef_object : public cdef_object_scalar
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
374 {
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
375 public:
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
376 value_cdef_object (void)
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
377 : cdef_object_scalar () { }
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
378
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
379 ~value_cdef_object (void);
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
380
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
381 cdef_object_rep* clone (void) const
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
382 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
383 value_cdef_object* obj = new value_cdef_object (*this);
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
384 return obj;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
385 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
386
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
387 bool is_valid (void) const { return true; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
388
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
389 private:
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
390 // Private copying!
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
391 value_cdef_object (const value_cdef_object& obj)
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
392 : cdef_object_scalar (obj) { }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
393
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
394 // No assignment!
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
395 value_cdef_object& operator = (const value_cdef_object&);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
396 };
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
397
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
398 class
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
399 cdef_class : public cdef_object
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
400 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
401 private:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
402
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
403 class
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
404 cdef_class_rep : public handle_cdef_object
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
405 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
406 public:
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
407 cdef_class_rep (void)
15910
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
408 : handle_cdef_object (), handle_class (false), object_count (0) { }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
409
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
410 cdef_class_rep (const std::list<cdef_class>& superclasses);
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
411
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
412 bool is_class (void) const { return true; }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
413
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
414 std::string get_name (void) const
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
415 { return get ("Name").string_value (); }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
416
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
417 void set_name (const std::string& nm) { put ("Name", nm); }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
418
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
419 cdef_method find_method (const std::string& nm, bool local = false);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
420
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
421 void install_method (const cdef_method& meth);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
422
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
423 Cell get_methods (void);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
424
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
425 cdef_property find_property (const std::string& nm);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
426
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
427 void install_property (const cdef_property& prop);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
428
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
429 Cell get_properties (void);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
430
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
431 string_vector get_names (void);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
432
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
433 void set_directory (const std::string& dir) { directory = dir; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
434
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
435 std::string get_directory (void) const { return directory; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
436
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
437 void delete_object (cdef_object obj);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
438
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
439 octave_value_list
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
440 subsref_meta (const std::string& type,
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
441 const std::list<octave_value_list>& idx, int nargout);
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
442
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
443 octave_value construct (const octave_value_list& args);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
444
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
445 void initialize_object (cdef_object& obj);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
446
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
447 void run_constructor (cdef_object& obj, const octave_value_list& args);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
448
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
449 void mark_as_handle_class (void) { handle_class = true; }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
450
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
451 bool is_handle_class (void) const { return handle_class; }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
452
15910
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
453 void register_object (void) { object_count++; }
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
454
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
455 void unregister_object (void) { object_count--; }
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
456
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
457 private:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
458 void load_all_methods (void);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
459
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
460 void find_names (std::set<std::string>& names, bool all);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
461
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
462 void find_properties (std::map<std::string,cdef_property>& props,
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
463 bool only_inherited);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
464
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
465 void find_methods (std::map<std::string, cdef_method>& meths,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
466 bool only_inherited);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
467
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
468 cdef_class wrap (void)
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
469 {
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
470 refcount++;
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
471 return cdef_class (this);
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
472 }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
473
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
474 private:
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
475 // The @-directory were this class is loaded from.
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
476 // (not used yet)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
477 std::string directory;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
478
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
479 // The methods defined by this class.
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
480 std::map<std::string,cdef_method> method_map;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
481
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
482 // The properties defined by this class.
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
483 std::map<std::string,cdef_property> property_map;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
484
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
485 // TRUE if this class is a handle class. A class is a handle
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
486 // class when the abstract "handle" class is one of its superclasses.
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
487 bool handle_class;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
488
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
489 // The list of super-class constructors that are called implicitly by the
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
490 // the classdef engine when creating an object. These constructors are not
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
491 // called explicitly by the class constructor.
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
492 std::list<cdef_class> implicit_ctor_list;
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
493
15910
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
494 // The number of objects of this class.
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
495 octave_refcount<octave_idx_type> object_count;
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
496
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
497 // Utility iterator typedef's.
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
498 typedef std::map<std::string,cdef_method>::iterator method_iterator;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
499 typedef std::map<std::string,cdef_method>::const_iterator method_const_iterator;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
500 typedef std::map<std::string,cdef_property>::iterator property_iterator;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
501 typedef std::map<std::string,cdef_property>::const_iterator property_const_iterator;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
502 };
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
503
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
504 public:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
505 // Create and invalid class object
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
506 cdef_class (void)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
507 : cdef_object () { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
508
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
509 cdef_class (const std::string& nm,
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
510 const std::list<cdef_class>& superclasses)
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
511 : cdef_object (new cdef_class_rep (superclasses))
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
512 { get_rep ()->set_name (nm); }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
513
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
514 cdef_class (const cdef_class& cls)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
515 : cdef_object (cls) { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
516
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
517 cdef_class (const cdef_object& obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
518 : cdef_object (obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
519 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
520 // This should never happen...
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
521 if (! is_class ())
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
522 error ("internal error: invalid assignment from %s to meta.class object",
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
523 class_name ().c_str ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
524 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
525
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
526 cdef_class& operator = (const cdef_class& cls)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
527 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
528 cdef_object::operator= (cls);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
529
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
530 return *this;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
531 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
532
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
533 cdef_class& operator = (const cdef_object& obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
534 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
535 if (obj.is_class ())
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
536 cdef_object::operator= (obj);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
537 else
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
538 error ("internal error: invalid assignment from %s to meta.class object",
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
539 class_name ().c_str ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
540
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
541 return *this;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
542 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
543
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
544 cdef_method find_method (const std::string& nm, bool local = false);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
545
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
546 void install_method (const cdef_method& meth)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
547 { get_rep ()->install_method (meth); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
548
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
549 Cell get_methods (void) { return get_rep ()->get_methods (); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
550
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
551 cdef_property find_property (const std::string& nm);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
552
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
553 void install_property (const cdef_property& prop)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
554 { get_rep ()->install_property (prop); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
555
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
556 Cell get_properties (void) { return get_rep ()->get_properties (); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
557
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
558 string_vector get_names (void) { return get_rep ()->get_names (); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
559
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
560 void set_directory (const std::string& dir)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
561 { get_rep ()->set_directory (dir); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
562
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
563 std::string get_directory (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
564 { return get_rep ()->get_directory (); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
565
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
566 std::string get_name (void) const
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
567 { return get_rep ()->get_name (); }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
568
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
569 bool is_builtin (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
570 { return get_directory ().empty (); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
571
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
572 void delete_object (cdef_object obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
573 { get_rep ()->delete_object (obj); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
574
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
575 octave_value_list subsref_meta (const std::string& type,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
576 const std::list<octave_value_list>& idx,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
577 int nargout)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
578 { return get_rep ()->subsref_meta (type, idx, nargout); }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
579
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
580 static cdef_class make_meta_class (tree_classdef* t);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
581
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
582 octave_function* get_method_function (const std::string& nm);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
583
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
584 octave_function* get_constructor_function (void)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
585 { return get_method_function (get_name ()); }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
586
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
587 octave_value construct (const octave_value_list& args)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
588 { return get_rep ()->construct (args); }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
589
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
590 void initialize_object (cdef_object& obj)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
591 { get_rep ()->initialize_object (obj); }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
592
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
593 void run_constructor (cdef_object& obj, const octave_value_list& args)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
594 { get_rep ()->run_constructor (obj, args); }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
595
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
596 void mark_as_handle_class (void)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
597 { get_rep ()->mark_as_handle_class (); }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
598
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
599 bool is_handle_class (void) const
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
600 { return get_rep ()->is_handle_class (); }
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
601
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
602 static const cdef_class& meta_class (void) { return _meta_class; }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
603 static const cdef_class& meta_property (void) { return _meta_property; }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
604 static const cdef_class& meta_method (void) { return _meta_method; }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
605 static const cdef_class& meta_package (void) { return _meta_package; }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
606
15910
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
607 void register_object (void) { get_rep ()->register_object (); }
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
608
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
609 void unregister_object (void) { get_rep ()->unregister_object (); }
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
610
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
611 private:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
612 cdef_class_rep* get_rep (void)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
613 { return dynamic_cast<cdef_class_rep *> (cdef_object::get_rep ()); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
614
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
615 const cdef_class_rep* get_rep (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
616 { return dynamic_cast<const cdef_class_rep *> (cdef_object::get_rep ()); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
617
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
618 friend bool operator == (const cdef_class&, const cdef_class&);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
619 friend bool operator != (const cdef_class&, const cdef_class&);
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
620 friend bool operator < (const cdef_class&, const cdef_class&);
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
621
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
622 private:
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
623 static cdef_class _meta_class;
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
624 static cdef_class _meta_property;
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
625 static cdef_class _meta_method;
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
626 static cdef_class _meta_package;
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
627
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
628 friend void install_classdef (void);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
629 };
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
630
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
631 inline bool
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
632 operator == (const cdef_class& clsa, const cdef_class& clsb)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
633 // FIXME: is this really the right way to check class equality?
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
634 { return (clsa.get_rep () == clsb.get_rep ()); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
635
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
636 inline bool
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
637 operator != (const cdef_class& clsa, const cdef_class& clsb)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
638 { return ! (clsa == clsb); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
639
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
640 // This is only to be able to use cdef_class as map keys.
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
641 inline bool
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
642 operator < (const cdef_class& clsa, const cdef_class& clsb)
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
643 { return clsa.get_rep () < clsb.get_rep (); }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
644
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
645 class
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
646 cdef_property : public cdef_object
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
647 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
648 private:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
649
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
650 class
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
651 cdef_property_rep : public handle_cdef_object
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
652 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
653 public:
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
654 cdef_property_rep (void)
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
655 : handle_cdef_object () { }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
656
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
657 bool is_property (void) const { return true; }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
658
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
659 std::string get_name (void) const { return get("Name").string_value (); }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
660
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
661 void set_name (const std::string& nm) { put ("Name", nm); }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
662
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
663 bool is_constant (void) const { return get("Constant").bool_value (); }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
664
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
665 octave_value get_value (void) const { return default_value; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
666
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
667 octave_value get_value (const cdef_object& obj);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
668
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
669 void set_value (const octave_value& val) { default_value = val; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
670
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
671 void set_value (cdef_object& obj, const octave_value& val);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
672
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
673 private:
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
674 bool is_recursive_set (const cdef_object& obj) const;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
675
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
676 private:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
677 octave_value default_value;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
678 };
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
679
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
680 public:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
681 cdef_property (void) : cdef_object () { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
682
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
683 cdef_property (const std::string& nm)
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
684 : cdef_object (new cdef_property_rep ())
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
685 { get_rep ()->set_name (nm); }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
686
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
687 cdef_property (const cdef_property& prop)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
688 : cdef_object (prop) { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
689
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
690 cdef_property (const cdef_object& obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
691 : cdef_object (obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
692 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
693 // This should never happen...
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
694 if (! is_property ())
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
695 error ("internal error: invalid assignment from %s to meta.property object",
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
696 class_name ().c_str ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
697 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
698
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
699 cdef_property& operator = (const cdef_property& prop)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
700 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
701 cdef_object::operator= (prop);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
702
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
703 return *this;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
704 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
705
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
706 octave_value get_value (const cdef_object& obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
707 { return get_rep ()->get_value (obj); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
708
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
709 octave_value get_value (void) { return get_rep ()->get_value (); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
710
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
711 void set_value (cdef_object& obj, const octave_value& val)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
712 { get_rep ()->set_value (obj, val); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
713
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
714 void set_value (const octave_value& val) { get_rep ()->set_value (val); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
715
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
716 bool check_get_access (void) const;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
717
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
718 bool check_set_access (void) const;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
719
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
720 std::string get_name (void) const { return get_rep ()->get_name (); }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
721
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
722 bool is_constant (void) const { return get_rep ()->is_constant (); }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
723
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
724 private:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
725 cdef_property_rep* get_rep (void)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
726 { return dynamic_cast<cdef_property_rep *> (cdef_object::get_rep ()); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
727
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
728 const cdef_property_rep* get_rep (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
729 { return dynamic_cast<const cdef_property_rep *> (cdef_object::get_rep ()); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
730 };
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
731
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
732 class
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
733 cdef_method : public cdef_object
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
734 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
735 private:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
736
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
737 class
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
738 cdef_method_rep : public handle_cdef_object
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
739 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
740 public:
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
741 cdef_method_rep (void) : handle_cdef_object () { }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
742
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
743 bool is_method (void) const { return true; }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
744
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
745 std::string get_name (void) const { return get("Name").string_value (); }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
746
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
747 void set_name (const std::string& nm) { put ("Name", nm); }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
748
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
749 bool is_static (void) const { return get("Static").bool_value (); }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
750
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
751 octave_value get_function (void) const { return function; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
752
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
753 void set_function (const octave_value& fcn) { function = fcn; }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
754
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
755 octave_value_list execute (const octave_value_list& args, int nargout);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
756
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
757 octave_value_list execute (const cdef_object& obj,
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
758 const octave_value_list& args, int nargout);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
759
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
760 bool is_constructor (void) const;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
761
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
762 private:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
763 void check_method (void);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
764
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
765 private:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
766 octave_value function;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
767 };
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
768
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
769 public:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
770 cdef_method (void) : cdef_object () { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
771
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
772 cdef_method (const std::string& nm)
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
773 : cdef_object (new cdef_method_rep ())
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
774 { get_rep ()->set_name (nm); }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
775
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
776 cdef_method (const cdef_property& prop)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
777 : cdef_object (prop) { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
778
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
779 cdef_method (const cdef_object& obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
780 : cdef_object (obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
781 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
782 // This should never happen...
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
783 if (! is_method ())
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
784 error ("internal error: invalid assignment from %s to meta.method object",
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
785 class_name ().c_str ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
786 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
787
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
788 cdef_method& operator = (const cdef_method& meth)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
789 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
790 cdef_object::operator= (meth);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
791
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
792 return *this;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
793 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
794
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
795 /* normal invokation */
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
796 octave_value_list execute (const octave_value_list& args, int nargout)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
797 { return get_rep ()->execute (args, nargout); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
798
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
799 /* dot-invokation: object is pushed as 1st argument */
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
800 octave_value_list execute (const cdef_object& obj,
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
801 const octave_value_list& args, int nargout)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
802 { return get_rep ()->execute (obj, args, nargout); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
803
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
804 bool check_access (void) const;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
805
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
806 std::string get_name (void) const { return get_rep ()->get_name (); }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
807
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
808 bool is_static (void) const { return get_rep ()->is_static (); }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
809
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
810 void set_function (const octave_value& fcn)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
811 { get_rep ()->set_function (fcn); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
812
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
813 octave_value get_function (void) const
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
814 { return get_rep ()->get_function (); }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
815
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
816 bool is_constructor (void) const
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
817 { return get_rep ()->is_constructor (); }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
818
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
819 private:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
820 cdef_method_rep* get_rep (void)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
821 { return dynamic_cast<cdef_method_rep *> (cdef_object::get_rep ()); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
822
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
823 const cdef_method_rep* get_rep (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
824 { return dynamic_cast<const cdef_method_rep *> (cdef_object::get_rep ()); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
825 };
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
826
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
827 inline cdef_class
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
828 cdef_object_rep::get_class (void) const
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
829 {
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
830 gripe_invalid_object ("get_class");
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
831 return cdef_class ();
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
832 }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
833
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
834 inline std::string
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
835 cdef_object_rep::class_name (void) const
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
836 { return get_class ().get_name (); }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
837
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
838 inline cdef_class
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
839 cdef_object::get_class (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
840 { return rep->get_class (); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
841
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
842 inline cdef_class
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
843 cdef_object_base::get_class (void) const
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
844 { return cdef_class (klass); }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
845
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
846 inline void
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
847 cdef_object_base::set_class (const cdef_class& cls)
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
848 {
15910
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
849 if ((klass.ok () && cls.ok () && cls != get_class ())
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
850 || (klass.ok () && ! cls.ok ())
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
851 || (! klass.ok () && cls.ok ()))
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
852 {
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
853 unregister_object ();
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
854 klass = cls;
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
855 register_object ();
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
856 }
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
857 }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
858
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
859 inline void
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
860 cdef_object_base::register_object (void)
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
861 {
15910
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
862 if (klass.ok ())
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
863 {
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
864 cdef_class cls (get_class ());
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
865
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
866 if (! error_state && cls.ok ())
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
867 cls.register_object ();
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
868 }
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
869 }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
870
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
871 inline void
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
872 cdef_object_base::unregister_object (void)
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
873 {
15910
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
874 if (klass.ok ())
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
875 {
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
876 cdef_class cls (get_class ());
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
877
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
878 if (! error_state && cls.ok ())
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
879 cls.unregister_object ();
dfd0dc594c4f Add object counting to cdef_class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15909
diff changeset
880 }
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
881 }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
882
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
883 inline cdef_method
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
884 cdef_class::find_method (const std::string& nm, bool local)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
885 { return get_rep ()->find_method (nm, local); }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
886
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
887 inline cdef_property
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
888 cdef_class::find_property (const std::string& nm)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
889 { return get_rep ()->find_property (nm); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
890
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
891 class
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
892 cdef_package : public cdef_object
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
893 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
894 private:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
895
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
896 class
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
897 cdef_package_rep : public handle_cdef_object
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
898 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
899 public:
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
900 cdef_package_rep (void) : handle_cdef_object () { }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
901
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
902 bool is_package (void) const { return true; }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
903
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
904 std::string get_name (void) const { return get("Name").string_value (); }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
905
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
906 void set_name (const std::string& nm) { put ("Name", nm); }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
907
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
908 void install_class (const cdef_class& cls, const std::string& nm);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
909
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
910 void install_function (const octave_value& fcn, const std::string& nm);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
911
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
912 void install_package (const cdef_package& pack, const std::string& nm);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
913
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
914 Cell get_classes (void) const;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
915
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
916 Cell get_functions (void) const;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
917
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
918 Cell get_packages (void) const;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
919
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
920 private:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
921 std::map<std::string, cdef_class> class_map;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
922 std::map<std::string, octave_value> function_map;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
923 std::map<std::string, cdef_package> package_map;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
924
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
925 typedef std::map<std::string, cdef_class>::iterator class_iterator;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
926 typedef std::map<std::string, cdef_class>::const_iterator class_const_iterator;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
927 typedef std::map<std::string, octave_value>::iterator function_iterator;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
928 typedef std::map<std::string, octave_value>::const_iterator function_const_iterator;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
929 typedef std::map<std::string, cdef_package>::iterator package_iterator;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
930 typedef std::map<std::string, cdef_package>::const_iterator package_const_iterator;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
931 };
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
932
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
933 public:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
934 cdef_package (void) : cdef_object () { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
935
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
936 cdef_package (const std::string& nm)
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
937 : cdef_object (new cdef_package_rep ())
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
938 { get_rep ()->set_name (nm); }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
939
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
940 cdef_package (const cdef_object& obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
941 : cdef_object (obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
942 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
943 // This should never happen...
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
944 if (! is_package ())
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
945 error ("internal error: invalid assignment from %s to meta.package object",
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
946 class_name ().c_str ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
947 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
948
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
949 cdef_package& operator = (const cdef_package& pack)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
950 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
951 cdef_object::operator= (pack);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
952
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
953 return *this;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
954 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
955
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
956 void install_class (const cdef_class& cls, const std::string& nm)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
957 { get_rep ()->install_class (cls, nm); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
958
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
959 void install_function (const octave_value& fcn, const std::string& nm)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
960 { get_rep ()->install_function (fcn, nm); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
961
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
962 void install_package (const cdef_package& pack, const std::string& nm)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
963 { get_rep ()->install_package (pack, nm); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
964
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
965 Cell get_classes (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
966 { return get_rep ()->get_classes (); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
967
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
968 Cell get_functions (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
969 { return get_rep ()->get_functions (); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
970
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
971 Cell get_packages (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
972 { return get_rep ()->get_packages (); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
973
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
974 std::string get_name (void) const { return get_rep ()->get_name (); }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
975
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
976 static const cdef_package& meta (void) { return _meta; }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
977
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
978 private:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
979 cdef_package_rep* get_rep (void)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
980 { return dynamic_cast<cdef_package_rep *> (cdef_object::get_rep ()); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
981
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
982 const cdef_package_rep* get_rep (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
983 { return dynamic_cast<const cdef_package_rep *> (cdef_object::get_rep ()); }
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
984
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
985 private:
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
986 static cdef_package _meta;
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
987
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
988 friend void install_classdef (void);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
989 };
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
990
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
991 class
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
992 octave_classdef : public octave_base_value
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
993 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
994 public:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
995 octave_classdef (void)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
996 : octave_base_value (), object () { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
997
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
998 octave_classdef (const cdef_object& obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
999 : octave_base_value (), object (obj) { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1000
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1001 octave_classdef (const octave_classdef& obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1002 : octave_base_value (obj), object (obj.object) { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1003
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1004 octave_base_value* clone (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1005 { return new octave_classdef (object.clone ()); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1006
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1007 octave_base_value* empty_clone (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1008 { return new octave_classdef (); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1009
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1010 cdef_object get_object (void) const { return object; }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1011
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1012 cdef_object& get_object_ref (void) { return object; }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1013
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1014 bool is_defined (void) const { return true; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1015
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1016 bool is_map (void) const { return true; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1017
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1018 bool print_as_scalar (void) const { return true; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1019
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1020 void print(std::ostream& os, bool pr_as_read_syntax = false) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1021 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1022 // FIXME: should call "display" method
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1023 print_raw(os, pr_as_read_syntax);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1024 newline(os);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1025 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1026
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1027 void print_raw(std::ostream& os, bool /* pr_as_read_syntax */ = false) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1028 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1029 os << object.class_name () << " object";
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1030 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1031
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1032 octave_value_list subsref (const std::string& type,
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1033 const std::list<octave_value_list>& idx, int nargout);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1034
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1035 octave_value subsref (const std::string& type,
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1036 const std::list<octave_value_list>& idx)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1037 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1038 octave_value_list retval = subsref (type, idx, 1);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1039 return (retval.length () > 0 ? retval(0) : octave_value ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1040 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1041
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1042 octave_value subsasgn (const std::string& type,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1043 const std::list<octave_value_list>& idx,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1044 const octave_value& rhs);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1045
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1046 string_vector map_keys (void) const { return object.map_keys (); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1047
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1048 dim_vector dims (void) const { return dim_vector (1, 1); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1049
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1050 private:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1051 cdef_object object;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1052
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1053 private:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1054 DECLARE_OCTAVE_ALLOCATOR
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1055
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1056 public:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1057 int type_id (void) const { return t_id; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1058 std::string type_name (void) const { return t_name; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1059 std::string class_name (void) const { return object.class_name (); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1060
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1061 static int static_type_id (void) { return t_id; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1062 static std::string static_type_name (void) { return t_name; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1063 static std::string static_class_name (void) { return "<unknown>"; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1064 static void register_type (void);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1065
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1066 private:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1067 static int t_id;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1068
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1069 static const std::string t_name;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1070 };
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1071
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1072 inline octave_value
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1073 to_ov (const cdef_object& obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1074 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1075 if (obj.ok ())
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1076 return octave_value (new octave_classdef (obj));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1077 else
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1078 return octave_value (Matrix ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1079 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1080
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1081 inline octave_value
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1082 to_ov (const octave_value& ov)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1083 { return ov; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1084
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1085 inline cdef_object
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1086 to_cdef (const octave_value& val)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1087 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1088 if (val.type_name () == "object")
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1089 return dynamic_cast<octave_classdef *> (val.internal_rep ())->get_object ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1090 else
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1091 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1092 warning ("trying to cast non-object into object");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1093 return cdef_object ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1094 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1095 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1096
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1097 inline cdef_object&
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1098 to_cdef_ref (octave_value& val)
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1099 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1100 static cdef_object empty;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1101
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1102 if (val.type_name () == "object")
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1103 return dynamic_cast<octave_classdef *> (val.internal_rep ())->get_object_ref ();
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1104 else
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1105 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1106 warning ("trying to cast non-object into object");
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1107 return empty;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1108 }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1109 }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1110
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1111 inline cdef_object
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1112 to_cdef (const cdef_object& obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1113 { return obj; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1114
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1115 OCTINTERP_API void install_classdef (void);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1116
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1117 #endif
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1118
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1119 /*
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1120 ;;; Local Variables: ***
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1121 ;;; mode: C++ ***
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1122 ;;; End: ***
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1123 */