annotate libinterp/octave-value/ov-classdef.h @ 15870:2b6fe094e615 classdef

Implement embryonic value-class semantic. * libinterp/octave-value/ov-classdef.h (cdef_object_rep::set_class): Delete method. (cdef_object_rep::get, cdef_object_rep::put): Copy implementation from handle_cdef_object. (cdef_object_rep::subsref, cdef_oject_rep::subsasgn): Move implementation to source file. (cdef_object_rep::map): Copy field from handle_cdef_object. (handle_cdef_rep::get, handle_cdef_rep::put): Move implementation to cdef_object_rep. (handle_cdef_rep::map): Move field to cdef_object_rep. (cdef_object_rep::cdef_object_rep, cdef_object_rep::operator=): Private declaration to disable copying. (handle_cdef_rep::handle_cdef_rep, handle_cdef_rep::operator=): Likewise. (class value_cdef_object): New class for value-class semantic. * libinterp/octave-value/ov-classdef.cc (cdef_object_rep::subsref, cdef_object_rep::subsasgn): Copy implementation from handle_cdef_object. (cdef_class_rep::run_constructor): Do not try to assign constructor result in case of error. (cdef_class_rep::construct): Create value_cdef_object object for value classes.
author Michael Goffioul <michael.goffioul@gmail.com>
date Tue, 01 Jan 2013 19:54:15 -0500
parents 5e5705b3e505
children 57be060d7672
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
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
41 class
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
42 cdef_object_rep
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
43 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
44 public:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
45 friend class cdef_object;
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 cdef_object_rep (void)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
49 : refcount (1), cname () { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
50
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
51 cdef_object_rep (const std::string& nm)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
52 : refcount (1), cname (nm) { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
53
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
54 virtual ~cdef_object_rep (void) { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
55
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
56 virtual cdef_class get_class (void) const;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
57
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
58 virtual cdef_object_rep* clone (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
59 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
60 error ("clone: invalid object");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
61 return new cdef_object_rep ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
62 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
63
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
64 virtual void put (const std::string& pname, const octave_value& val)
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
65 { map.assign (pname, val); }
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
66
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
67 virtual octave_value get (const std::string& pname) const
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
68 {
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
69 Cell val = map.contents (pname);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
70
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
71 if (val.numel () > 0)
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
72 return val(0, 0);
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
73 else
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
74 {
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
75 error ("get: unknown slot: %s", pname.c_str ());
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
76 return octave_value ();
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
77 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
78 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
79
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
80 virtual octave_value_list subsref (const std::string& type,
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
81 const std::list<octave_value_list>& idx,
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
82 int nargout, int& skip);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
83
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
84 virtual octave_value subsasgn (const std::string& type,
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
85 const std::list<octave_value_list>& idx,
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
86 const octave_value& rhs);
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
87
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
88 virtual string_vector map_keys(void) const;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
89
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
90 virtual bool is_valid (void) const { return false; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
91
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
92 std::string class_name (void) const { return cname; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
93
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
94 void set_class_name (const std::string& nm)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
95 { cname = nm; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
96
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
97 protected:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
98 /* reference count */
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
99 octave_refcount<int> refcount;
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 /* class name */
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
102 std::string cname;
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
103
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
104 /* object property values */
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
105 Octave_map map;
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
106
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
107 private:
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
108 // No copying
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
109 cdef_object_rep (const cdef_object_rep&);
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
110 cdef_object_rep& operator = (const cdef_object_rep& );
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
111 };
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
112
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
113 class
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
114 cdef_object
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
115 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
116 public:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
117 /* FIXME: use a null object */
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
118 cdef_object (void)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
119 : rep (new cdef_object_rep ()) { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
120
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
121 cdef_object (const cdef_object& obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
122 : rep (obj.rep)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
123 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
124 rep->refcount++;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
125 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
126
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
127 cdef_object (cdef_object_rep *r)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
128 : rep (r) { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
129
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
130 virtual ~cdef_object (void)
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 if (--rep->refcount == 0)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
133 delete rep;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
134 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
135
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
136 cdef_object& operator = (const cdef_object& obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
137 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
138 if (rep != obj.rep)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
139 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
140 if (--rep->refcount == 0)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
141 delete rep;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
142
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
143 rep = obj.rep;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
144 rep->refcount++;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
145 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
146
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
147 return *this;
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
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
150 cdef_class get_class (void) const;
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 void set_class_name (const std::string& nm)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
153 { rep->set_class_name (nm); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
154
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
155 std::string class_name (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
156 { return rep->class_name (); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
157
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
158 cdef_object clone (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
159 { return cdef_object (rep->clone ()); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
160
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
161 void put (const std::string& pname, const octave_value& val)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
162 { rep->put (pname, val); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
163
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
164 octave_value get (const std::string& pname) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
165 { return rep->get (pname); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
166
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
167 octave_value_list subsref (const std::string& type,
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
168 const std::list<octave_value_list>& idx,
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
169 int nargout, int& skip)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
170 { return rep->subsref (type, idx, nargout, skip); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
171
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
172 octave_value subsasgn (const std::string& type,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
173 const std::list<octave_value_list>& idx,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
174 const octave_value& rhs)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
175 { return rep->subsasgn (type, idx, rhs); }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
176
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
177 string_vector map_keys (void) const { return rep->map_keys (); }
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 const cdef_object_rep* get_rep (void) const { return rep; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
180
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
181 bool ok (void) const { return rep->is_valid (); }
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 protected:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
184 cdef_object_rep* get_rep (void) { return rep; }
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 private:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
187 cdef_object_rep *rep;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
188 };
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 class
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
191 handle_cdef_object : public cdef_object_rep
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 public:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
194 handle_cdef_object (void)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
195 : cdef_object_rep () { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
196
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
197 handle_cdef_object (const std::string& nm)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
198 : cdef_object_rep (nm) { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
199
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
200 ~handle_cdef_object (void);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
201
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
202 cdef_object_rep* clone (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
203 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
204 handle_cdef_object *obj = const_cast<handle_cdef_object *> (this);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
205 obj->refcount++;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
206 return obj;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
207 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
208
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
209 bool is_valid (void) const { return true; }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
210
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
211 private:
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
212 // No copying
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
213 handle_cdef_object (const handle_cdef_object&);
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
214 handle_cdef_object& operator = (const handle_cdef_object&);
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
215 };
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
216
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
217 class
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
218 value_cdef_object : public cdef_object_rep
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
219 {
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
220 public:
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
221 value_cdef_object (void)
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
222 : cdef_object_rep () { }
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
223
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
224 value_cdef_object (const std::string& nm)
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
225 : cdef_object_rep (nm) { }
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
226
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
227 ~value_cdef_object (void);
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
228
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
229 cdef_object_rep* clone (void) const
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
230 {
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
231 value_cdef_object* obj = new value_cdef_object (cname);
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
232 obj->map = map;
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
233 return obj;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
234 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
235
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
236 bool is_valid (void) const { return true; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
237
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
238 private:
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
239 // No copying
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
240 value_cdef_object (const value_cdef_object&);
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
241 value_cdef_object& operator = (const value_cdef_object&);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
242 };
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
243
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
244 class
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
245 cdef_class : public cdef_object
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
246 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
247 private:
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
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
250 cdef_class_rep : public handle_cdef_object
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
251 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
252 public:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
253 cdef_class_rep (const std::string& nm)
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
254 : handle_cdef_object (nm), handle_class (false) { }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
255
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
256 std::string get_name (void) const
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
257 { return get ("Name").string_value (); }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
258
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
259 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
260
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
261 void install_method (const cdef_method& meth);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
262
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
263 Cell get_methods (void);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
264
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
265 cdef_property find_property (const std::string& nm);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
266
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
267 void install_property (const cdef_property& prop);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
268
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
269 Cell get_properties (void);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
270
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
271 string_vector get_names (void);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
272
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
273 void set_directory (const std::string& dir) { directory = dir; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
274
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
275 std::string get_directory (void) const { return directory; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
276
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
277 void delete_object (cdef_object obj);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
278
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
279 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
280 const std::list<octave_value_list>& idx,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
281 int nargout);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
282
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
283 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
284
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
285 void initialize_object (cdef_object& obj);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
286
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
287 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
288
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
289 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
290
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
291 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
292
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
293 private:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
294 void load_all_methods (void);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
295
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
296 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
297
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
298 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
299 bool only_inherited);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
300
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
301 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
302 bool only_inherited);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
303
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
304 private:
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
305 // 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
306 // (not used yet)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
307 std::string directory;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
308
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
309 // The methods defined by this class.
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
310 std::map<std::string,cdef_method> method_map;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
311
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
312 // The properties defined by this class.
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
313 std::map<std::string,cdef_property> property_map;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
314
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
315 // 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
316 // 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
317 bool handle_class;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
318
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
319 // Utility iterator typedef's.
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
320 typedef std::map<std::string,cdef_method>::iterator method_iterator;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
321 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
322 typedef std::map<std::string,cdef_property>::iterator property_iterator;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
323 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
324 };
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
325
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
326 public:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
327 // Create and invalid class object
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
328 cdef_class (void)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
329 : cdef_object () { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
330
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
331 cdef_class (const std::string& nm)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
332 : cdef_object (new cdef_class_rep (nm)) { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
333
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
334 cdef_class (const cdef_class& cls)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
335 : cdef_object (cls) { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
336
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
337 cdef_class (const cdef_object& obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
338 : cdef_object (obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
339 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
340 // This should never happen...
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
341 if (class_name () != "meta.class")
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
342 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
343 class_name ().c_str ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
344 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
345
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
346 cdef_class& operator = (const cdef_class& cls)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
347 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
348 cdef_object::operator= (cls);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
349
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
350 return *this;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
351 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
352
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
353 cdef_class& operator = (const cdef_object& obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
354 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
355 if (obj.class_name () == "meta.class")
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
356 cdef_object::operator= (obj);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
357 else
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
358 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
359 class_name ().c_str ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
360
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
361 return *this;
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
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
364 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
365
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
366 void install_method (const cdef_method& meth)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
367 { get_rep ()->install_method (meth); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
368
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
369 Cell get_methods (void) { return get_rep ()->get_methods (); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
370
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
371 cdef_property find_property (const std::string& nm);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
372
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
373 void install_property (const cdef_property& prop)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
374 { get_rep ()->install_property (prop); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
375
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
376 Cell get_properties (void) { return get_rep ()->get_properties (); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
377
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
378 string_vector get_names (void) { return get_rep ()->get_names (); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
379
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
380 void set_directory (const std::string& dir)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
381 { get_rep ()->set_directory (dir); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
382
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
383 std::string get_directory (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
384 { return get_rep ()->get_directory (); }
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 std::string get_name (void) const
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
387 { return get_rep ()->get_name (); }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
388
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
389 bool is_builtin (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
390 { return get_directory ().empty (); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
391
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
392 void delete_object (cdef_object obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
393 { get_rep ()->delete_object (obj); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
394
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
395 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
396 const std::list<octave_value_list>& idx,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
397 int nargout)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
398 { 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
399
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
400 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
401
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
402 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
403
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
404 octave_function* get_constructor_function (void)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
405 { return get_method_function (get_name ()); }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
406
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
407 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
408 { return get_rep ()->construct (args); }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
409
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
410 void initialize_object (cdef_object& obj)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
411 { get_rep ()->initialize_object (obj); }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
412
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
413 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
414 { get_rep ()->run_constructor (obj, args); }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
415
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
416 void mark_as_handle_class (void)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
417 { get_rep ()->mark_as_handle_class (); }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
418
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
419 bool is_handle_class (void) const
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
420 { return get_rep ()->is_handle_class (); }
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
421
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
422 private:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
423 cdef_class_rep* get_rep (void)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
424 { return dynamic_cast<cdef_class_rep *> (cdef_object::get_rep ()); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
425
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
426 const cdef_class_rep* get_rep (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
427 { 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
428
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
429 friend bool operator == (const cdef_class&, const cdef_class&);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
430 friend bool operator != (const cdef_class&, const cdef_class&);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
431 };
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 inline bool
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
434 operator == (const cdef_class& clsa, const cdef_class& clsb)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
435 // 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
436 { return (clsa.get_rep () == clsb.get_rep ()); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
437
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
438 inline bool
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
439 operator != (const cdef_class& clsa, const cdef_class& clsb)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
440 { return ! (clsa == clsb); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
441
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
442 class
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
443 cdef_property : public cdef_object
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
444 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
445 private:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
446
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
447 class
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
448 cdef_property_rep : public handle_cdef_object
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
449 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
450 public:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
451 cdef_property_rep (const std::string& nm)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
452 : handle_cdef_object (nm) { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
453
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
454 octave_value get_value (void) const { return default_value; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
455
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
456 octave_value get_value (const cdef_object& obj);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
457
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
458 void set_value (const octave_value& val) { default_value = val; }
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 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
461
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
462 private:
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
463 bool is_recursive_set (const cdef_object& obj) const;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
464
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
465 private:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
466 octave_value default_value;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
467 };
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
468
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
469 public:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
470 cdef_property (void) : cdef_object () { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
471
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
472 cdef_property (const std::string& nm)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
473 : cdef_object (new cdef_property_rep (nm)) { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
474
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
475 cdef_property (const cdef_property& prop)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
476 : cdef_object (prop) { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
477
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
478 cdef_property (const cdef_object& obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
479 : cdef_object (obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
480 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
481 // This should never happen...
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
482 if (class_name () != "meta.property")
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
483 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
484 class_name ().c_str ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
485 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
486
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
487 cdef_property& operator = (const cdef_property& prop)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
488 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
489 cdef_object::operator= (prop);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
490
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
491 return *this;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
492 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
493
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
494 octave_value get_value (const cdef_object& obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
495 { return get_rep ()->get_value (obj); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
496
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
497 octave_value get_value (void) { return get_rep ()->get_value (); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
498
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
499 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
500 { get_rep ()->set_value (obj, val); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
501
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
502 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
503
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
504 bool check_get_access (void) const;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
505
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
506 bool check_set_access (void) const;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
507
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
508 std::string get_name (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
509 { return get ("Name").string_value (); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
510
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
511 bool is_constant (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
512 { return get ("Constant").bool_value (); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
513
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
514 private:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
515 cdef_property_rep* get_rep (void)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
516 { return dynamic_cast<cdef_property_rep *> (cdef_object::get_rep ()); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
517
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
518 const cdef_property_rep* get_rep (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
519 { 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
520 };
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
521
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
522 class
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
523 cdef_method : public cdef_object
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 private:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
526
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
527 class
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
528 cdef_method_rep : public handle_cdef_object
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 public:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
531 cdef_method_rep (const std::string& nm)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
532 : handle_cdef_object (nm) { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
533
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
534 octave_value get_function (void) const { return function; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
535
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
536 void set_function (const octave_value& fcn)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
537 { function = fcn; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
538
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
539 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
540
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
541 octave_value_list execute (const cdef_object& obj,
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
542 const octave_value_list& args, int nargout);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
543
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
544 private:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
545 void check_method (void);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
546
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
547 private:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
548 octave_value function;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
549 };
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 public:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
552 cdef_method (void) : cdef_object () { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
553
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
554 cdef_method (const std::string& nm)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
555 : cdef_object (new cdef_method_rep (nm)) { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
556
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
557 cdef_method (const cdef_property& prop)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
558 : cdef_object (prop) { }
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 cdef_method (const cdef_object& obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
561 : cdef_object (obj)
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 // This should never happen...
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
564 if (class_name () != "meta.method")
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
565 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
566 class_name ().c_str ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
567 }
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 cdef_method& operator = (const cdef_method& meth)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
570 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
571 cdef_object::operator= (meth);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
572
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
573 return *this;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
574 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
575
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
576 /* normal invokation */
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
577 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
578 { return get_rep ()->execute (args, nargout); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
579
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
580 /* dot-invokation: object is pushed as 1st argument */
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
581 octave_value_list execute (const cdef_object& obj,
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
582 const octave_value_list& args, int nargout)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
583 { return get_rep ()->execute (obj, args, nargout); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
584
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
585 bool check_access (void) const;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
586
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
587 std::string get_name (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
588 { return get ("Name").string_value (); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
589
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
590 bool is_static (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
591 { return get ("Static").bool_value (); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
592
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
593 void set_function (const octave_value& fcn)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
594 { get_rep ()->set_function (fcn); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
595
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
596 private:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
597 cdef_method_rep* get_rep (void)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
598 { return dynamic_cast<cdef_method_rep *> (cdef_object::get_rep ()); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
599
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
600 const cdef_method_rep* get_rep (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
601 { 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
602 };
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
603
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
604 inline cdef_class
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
605 cdef_object::get_class (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
606 { return rep->get_class (); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
607
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
608 inline cdef_method
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
609 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
610 { return get_rep ()->find_method (nm, local); }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
611
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
612 inline cdef_property
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
613 cdef_class::find_property (const std::string& nm)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
614 { return get_rep ()->find_property (nm); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
615
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
616 class
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
617 cdef_package : public cdef_object
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
618 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
619 private:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
620
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
621 class
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
622 cdef_package_rep : public handle_cdef_object
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
623 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
624 public:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
625 cdef_package_rep (const std::string& nm)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
626 : handle_cdef_object (nm) { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
627
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
628 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
629
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
630 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
631
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
632 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
633
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
634 octave_value_list subsref (const std::string& type,
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
635 const std::list<octave_value_list>& idx,
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
636 int nargout, int& skip);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
637
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
638 Cell get_classes (void) const;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
639
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
640 Cell get_functions (void) const;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
641
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
642 Cell get_packages (void) const;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
643
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
644 private:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
645 std::map<std::string, cdef_class> class_map;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
646 std::map<std::string, octave_value> function_map;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
647 std::map<std::string, cdef_package> package_map;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
648
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
649 typedef std::map<std::string, cdef_class>::iterator class_iterator;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
650 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
651 typedef std::map<std::string, octave_value>::iterator function_iterator;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
652 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
653 typedef std::map<std::string, cdef_package>::iterator package_iterator;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
654 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
655 };
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
656
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
657 public:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
658 cdef_package (void) : cdef_object () { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
659
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
660 cdef_package (const std::string& nm)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
661 : cdef_object (new cdef_package_rep (nm)) { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
662
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
663 cdef_package (const cdef_object& obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
664 : cdef_object (obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
665 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
666 // This should never happen...
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
667 if (class_name () != "meta.package")
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
668 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
669 class_name ().c_str ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
670 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
671
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
672 cdef_package& operator = (const cdef_package& pack)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
673 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
674 cdef_object::operator= (pack);
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 return *this;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
677 }
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 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
680 { get_rep ()->install_class (cls, nm); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
681
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
682 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
683 { get_rep ()->install_function (fcn, nm); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
684
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
685 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
686 { get_rep ()->install_package (pack, nm); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
687
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
688 Cell get_classes (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
689 { return get_rep ()->get_classes (); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
690
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
691 Cell get_functions (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
692 { return get_rep ()->get_functions (); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
693
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
694 Cell get_packages (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
695 { return get_rep ()->get_packages (); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
696
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
697 private:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
698 cdef_package_rep* get_rep (void)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
699 { return dynamic_cast<cdef_package_rep *> (cdef_object::get_rep ()); }
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 const cdef_package_rep* get_rep (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
702 { return dynamic_cast<const cdef_package_rep *> (cdef_object::get_rep ()); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
703 };
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 class
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
706 octave_classdef : public octave_base_value
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
707 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
708 public:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
709 octave_classdef (void)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
710 : octave_base_value (), object () { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
711
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
712 octave_classdef (const cdef_object& obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
713 : octave_base_value (), object (obj) { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
714
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
715 octave_classdef (const octave_classdef& obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
716 : octave_base_value (obj), object (obj.object) { }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
717
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
718 octave_base_value* clone (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
719 { return new octave_classdef (object.clone ()); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
720
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
721 octave_base_value* empty_clone (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
722 { return new octave_classdef (); }
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 cdef_object get_object (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
725 { return object; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
726
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
727 bool is_defined (void) const { return true; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
728
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
729 bool is_map (void) const { return true; }
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 bool print_as_scalar (void) const { return true; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
732
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
733 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
734 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
735 // FIXME: should call "display" method
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
736 print_raw(os, pr_as_read_syntax);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
737 newline(os);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
738 }
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 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
741 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
742 os << object.class_name () << " object";
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
743 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
744
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
745 octave_value_list subsref (const std::string& type,
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
746 const std::list<octave_value_list>& idx, int nargout);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
747
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
748 octave_value subsref (const std::string& type,
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
749 const std::list<octave_value_list>& idx)
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_list retval = subsref (type, idx, 1);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
752 return (retval.length () > 0 ? retval(0) : octave_value ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
753 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
754
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
755 octave_value subsasgn (const std::string& type,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
756 const std::list<octave_value_list>& idx,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
757 const octave_value& rhs);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
758
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
759 string_vector map_keys (void) const { return object.map_keys (); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
760
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
761 dim_vector dims (void) const { return dim_vector (1, 1); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
762
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
763 private:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
764 cdef_object object;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
765
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
766 private:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
767 DECLARE_OCTAVE_ALLOCATOR
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 int type_id (void) const { return t_id; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
771 std::string type_name (void) const { return t_name; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
772 std::string class_name (void) const { return object.class_name (); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
773
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
774 static int static_type_id (void) { return t_id; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
775 static std::string static_type_name (void) { return t_name; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
776 static std::string static_class_name (void) { return "<unknown>"; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
777 static void register_type (void);
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 private:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
780 static int t_id;
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 static const std::string t_name;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
783 };
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
784
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
785 inline octave_value
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
786 to_ov (const cdef_object& obj)
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 if (obj.ok ())
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
789 return octave_value (new octave_classdef (obj));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
790 else
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
791 return octave_value (Matrix ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
792 }
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 inline octave_value
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
795 to_ov (const octave_value& ov)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
796 { return ov; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
797
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
798 inline cdef_object
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
799 to_cdef (const octave_value& val)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
800 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
801 if (val.type_name () == "object")
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
802 return dynamic_cast<octave_classdef *> (val.internal_rep ())->get_object ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
803 else
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
804 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
805 warning ("trying to cast non-object into object");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
806 return cdef_object ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
807 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
808 }
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 inline cdef_object
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
811 to_cdef (const cdef_object& obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
812 { return obj; }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
813
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
814 OCTINTERP_API void install_classdef (void);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
815
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
816 #endif
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
817
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
818 /*
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
819 ;;; Local Variables: ***
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
820 ;;; mode: C++ ***
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
821 ;;; End: ***
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
822 */