|
From: | Michael Goffioul |
Subject: | Re: classdef array objects |
Date: | Thu, 12 Sep 2013 09:44:35 -0400 |
Michael, could you comment on the following?
I tried an example like
classdef classarray
properties
x
endproperties
methods
function obj = classarray (x, n)
if (nargin == 0)
disp ('constructing empty classarray object');
else
## pre-allocate array of classarray objects
obj(1, n) = classarray ();
for i = 1:n
obj(i).x = x;
endfor
endif
endfunction
endmethods
endclassdef
and it failed to create an array object with an invalid object message
coming from mark_as_constructed. I eventually realized that
cdef_object_array doesn't have the mark_as_constructed or
is_constructed methods. When I added
void mark_as_constructed (void) { }
void mark_as_constructed (const cdef_class&) { }
bool is_constructed (void) const { return true; }
to cdef_object_array, the above class appeared to work as I expected.
But I also noticed that scalar objects are considered constructed if
the list of constructors is empty. I'm not sure whether there should
be a similar check for array objects or whether they should always be
considered constructed.
Finally, I see that cdef_object_array is implemented using
Array<cdef_object>. Is it possible for each object in the array to
have a different set of properties? If not, then maybe it would be
better for cdef_object_array to contain an octave_map and for
cdef_object to contain an octave_scalar_map for storing properties and
values. That would avoid the duplication of storing the property
names N times. Even with reference counting, it makes sense to me to
avoid the duplication. If you agree, I can take a stab at changing the implementation to use octave_map and octave_scalar_map (Octave_map is currently used and is obsolete anyway).
[Prev in Thread] | Current Thread | [Next in Thread] |