This repository has been archived by the owner on Jun 27, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for python-side class-specific wrappers. This is implem…
…ented similar to the py.types hierarchy, except in reverse: the python package "mltypes" contains subclasses of mx.Array, and whenever an mx.Array wrapper is needed an MRO list for the MATLAB object is computed (see mro.m) and an appropriate class is chosen from that list. Currently the only subclass is "cell", and it has no specialized behavior. It will be changed soonish so that its get/setitem hooks use mxGet/SetCell.
- Loading branch information
Ken Watford
committed
Nov 18, 2009
1 parent
ad8aee5
commit c971522
Showing
5 changed files
with
182 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,6 @@ | |
*~ | ||
.nfs* | ||
build/* | ||
*.pyc | ||
*.pyo | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from matlab import mx | ||
import sys | ||
|
||
def _findtype(typelist): | ||
for (modstr, clsstr) in typelist: | ||
if len(modstr): | ||
adjusted_modstr = "mltypes.%s" % modstr | ||
else: | ||
adjusted_modstr = "mltypes" | ||
try: | ||
tempmod = __import__(adjusted_modstr, globals(), locals(), [clsstr], 0) | ||
cls = getattr(tempmod, clsstr); | ||
return cls; | ||
except: | ||
pass | ||
# if we got this far and found nothing, just use mx.Array | ||
return mx.Array; | ||
|
||
|
||
class cell(mx.Array): pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
% mrolist = mro(object, addvirtual=true, autosplit=true) | ||
% Determines something similar to the method resolution order for an object. | ||
% Note that this is probably not the actual order, since a cursory inspection | ||
% did not reveal any clues as to what the correct order might be. So this just | ||
% produces a list of all of the object's classes from most to least specific. | ||
% | ||
% If addvirtual is true, a virtual class may be appended to the end of the | ||
% mro list to indicate the nonexistent root of a particular hierarchy. | ||
% The virtual classes are: | ||
% _numeric: Numbers, logicals, and characters. | ||
% _object: MATLAB objects | ||
% _java: Java objects | ||
% _com: COM objects (windows only) | ||
% _interface: COM interface (windows only) | ||
% | ||
% Note that no attempt is made to enumerate the class hierarchy | ||
% of Java classes. We could probably do that, but let's keep it simple for now. | ||
function [mrolist] = mro(object,addvirtual,autosplit) | ||
if nargin < 2, addvirtual = true; end | ||
if nargin < 3, autosplit = true; end | ||
classname = class(object); | ||
mrolist = {classname}; | ||
classqueue = {classname}; | ||
while ~isempty(classqueue) | ||
mco = meta.class.fromName(classqueue{1}); | ||
classqueue = classqueue(2:end); | ||
if isempty(mco) | ||
% MATLAB doesn't abstract Java class reflection, | ||
% so it will return an empty metaclass handle. | ||
continue; | ||
end | ||
supers = mco.SuperClasses; | ||
for i=1:numel(supers) | ||
name = supers{i}.Name; | ||
if ~ismember(name, mrolist) | ||
mrolist = [mrolist name]; %#ok<AGROW> | ||
classqueue = [classqueue name]; %#ok<AGROW> | ||
end | ||
end | ||
end | ||
|
||
if addvirtual | ||
if isnumeric(object) || ischar(object) || islogical(object) | ||
mrolist{end+1} = '_numeric'; | ||
elseif isobject(object) | ||
mrolist{end+1} = '_object'; | ||
elseif isjava(object) | ||
mrolist{end+1} = '_java'; | ||
% In case this gets used on Windows... | ||
elseif iscom(object) | ||
mrolist{end+1} = '_com'; | ||
elseif isinterface(object) | ||
mrolist{end+1} = '_interface'; | ||
end | ||
end | ||
|
||
if autosplit | ||
for i=1:numel(mrolist) | ||
classname = mrolist{i}; | ||
dots = strfind(classname, '.'); | ||
if isempty(dots) | ||
mrolist{i} = {'', classname}; | ||
else | ||
d = dots(end); | ||
mrolist{i} = {classname(1:d-1), classname(d+1:end)}; | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters