Skip to content

Commit 5b1dbf5

Browse files
committed
Port changes from DSS_Python. Includes debug version, PDElements extensions, LegacyModels and ExtendedErrors.
1 parent 30015ad commit 5b1dbf5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+2548
-1770
lines changed

+DSS_MATLAB/APIUtil.m

Lines changed: 73 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,20 @@
99
CountPtr_PDouble
1010
CountPtr_PInteger
1111
CountPtr_PByte
12+
libname
1213
end
1314
methods
1415
function obj = APIUtil()
16+
if getenv('DSS_EXTENSIONS_DEBUG') == '1'
17+
warnings.warn('Environment variable DSS_EXTENSIONS_DEBUG=1 is set: loading the debug version of the DSS C-API library')
18+
obj.libname = 'dss_capi_v7d';
19+
else
20+
obj.libname = 'dss_capi_v7';
21+
end
22+
1523
MfilePath = fileparts(mfilename('fullpath'));
16-
DLLfilePath = fullfile(MfilePath, 'dss_capi_v7');
17-
if libisloaded('dss_capi_v7')
24+
DLLfilePath = fullfile(MfilePath, obj.libname);
25+
if libisloaded(obj.libname)
1826
return
1927
else
2028
orig_state = warning;
@@ -36,17 +44,17 @@ function delete(obj)
3644
% the COM behavior
3745

3846
% if (obj.libraryWasLoaded ~= 0)
39-
% unloadlibrary('dss_capi_v7');
47+
% unloadlibrary(obj.libname);
4048
% end
4149
end
4250

4351
function obj = InitBuffers(obj)
44-
% obj.DataPtr_PDouble = calllib('dss_capi_v7', 'DSS_GR_DataPtr_PDouble');
45-
% obj.DataPtr_PInteger = calllib('dss_capi_v7', 'DSS_GR_DataPtr_PInteger');
46-
% obj.DataPtr_PByte = calllib('dss_capi_v7', 'DSS_GR_DataPtr_PByte');
47-
obj.CountPtr_PDouble = calllib('dss_capi_v7', 'DSS_GR_CountPtr_PDouble');
48-
obj.CountPtr_PInteger = calllib('dss_capi_v7', 'DSS_GR_CountPtr_PInteger');
49-
obj.CountPtr_PByte = calllib('dss_capi_v7', 'DSS_GR_CountPtr_PByte');
52+
% obj.DataPtr_PDouble = calllib(obj.libname, 'DSS_GR_DataPtr_PDouble');
53+
% obj.DataPtr_PInteger = calllib(obj.libname, 'DSS_GR_DataPtr_PInteger');
54+
% obj.DataPtr_PByte = calllib(obj.libname, 'DSS_GR_DataPtr_PByte');
55+
obj.CountPtr_PDouble = calllib(obj.libname, 'DSS_GR_CountPtr_PDouble');
56+
obj.CountPtr_PInteger = calllib(obj.libname, 'DSS_GR_CountPtr_PInteger');
57+
obj.CountPtr_PByte = calllib(obj.libname, 'DSS_GR_CountPtr_PByte');
5058

5159
% if (obj.DataPtr_PDouble.isNull || obj.DataPtr_PDouble.isNull || obj.DataPtr_PByte.isNull)
5260
% disp('Null-pointer return from the API! Cannot continue!');
@@ -64,23 +72,62 @@ function delete(obj)
6472
end
6573

6674

67-
function result = get_float64_gr_array(obj)
68-
data = calllib('dss_capi_v7', 'DSS_GR_DataPtr_PDouble');
69-
setdatatype(data, 'doublePtr', 1, obj.CountPtr_PDouble.Value(1));
70-
result = data.Value;
71-
end
72-
73-
function result = get_int32_gr_array(obj)
74-
data = calllib('dss_capi_v7', 'DSS_GR_DataPtr_PInteger');
75-
setdatatype(data, 'int32Ptr', 1, obj.CountPtr_PInteger.Value(1));
76-
result = data.Value;
77-
end
78-
79-
function result = get_int8_gr_array(obj)
80-
data = calllib('dss_capi_v7', 'DSS_GR_DataPtr_PByte');
81-
setdatatype(data, 'int8Ptr', 1, obj.CountPtr_PByte.Value(1));
82-
result = data.Value;
83-
end
75+
function result = get_float64_gr_array(obj)
76+
data = calllib(obj.libname, 'DSS_GR_DataPtr_PDouble');
77+
setdatatype(data, 'doublePtr', 1, obj.CountPtr_PDouble.Value(1));
78+
result = data.Value;
79+
end
80+
81+
function result = get_int32_gr_array(obj)
82+
data = calllib(obj.libname, 'DSS_GR_DataPtr_PInteger');
83+
setdatatype(data, 'int32Ptr', 1, obj.CountPtr_PInteger.Value(1));
84+
result = data.Value;
85+
end
86+
87+
function result = get_int8_gr_array(obj)
88+
data = calllib(obj.libname, 'DSS_GR_DataPtr_PByte');
89+
setdatatype(data, 'int8Ptr', 1, obj.CountPtr_PByte.Value(1));
90+
result = data.Value;
91+
end
8492

93+
function result = get_string_array(obj, funcname, varargin)
94+
dataPointer = libpointer('voidPtr', 0);
95+
countPointer = libpointer('int32Ptr', [0, 0]);
96+
calllib(obj.libname, funcname, dataPointer, countPointer, varargin{:});
97+
result = cell(countPointer.Value(1), 1);
98+
for i=1:countPointer.Value(1)
99+
result(i) = cellstr(calllib(obj.libname, 'DSS_Get_PAnsiChar', dataPointer, i - 1));
100+
end
101+
calllib(obj.libname, 'DSS_Dispose_PPAnsiChar', dataPointer, countPointer.Value(2));
102+
end
103+
104+
function result = get_int8_array(obj, funcname, varargin)
105+
dataPointer = libpointer('int8PtrPtr');
106+
countPointer = libpointer('int32Ptr', [0, 0]);
107+
calllib(obj.libname, funcname, dataPointer, countPointer, varargin{:});
108+
dataPointer.Value
109+
setdatatype(dataPointer.Value, 'int8Ptr', 1, countPointer.Value(1));
110+
result = dataPointer.Value;
111+
calllib(obj.libname, 'DSS_Dispose_PByte', dataPointer);
112+
end
113+
114+
function result = get_int32_array(obj, funcname, varargin)
115+
dataPointer = libpointer('int32PtrPtr');
116+
countPointer = libpointer('int32Ptr', [0, 0]);
117+
calllib(obj.libname, funcname, dataPointer, countPointer, varargin{:});
118+
setdatatype(dataPointer.Value, 'int32Ptr', 1, countPointer.Value(1));
119+
result = dataPointer.Value;
120+
calllib(obj.libname, 'DSS_Dispose_PInteger', dataPointer);
121+
end
122+
123+
function result = get_float64_array(obj, funcname, varargin)
124+
dataPointer = libpointer('doublePtrPtr');
125+
countPointer = libpointer('int32Ptr', [0, 0]);
126+
calllib(obj.libname, funcname, dataPointer, countPointer, varargin{:});
127+
setdatatype(dataPointer.Value, 'doublePtr', 1, countPointer.Value(1));
128+
result = dataPointer.Value;
129+
calllib(obj.libname, 'DSS_Dispose_PDouble', dataPointer);
130+
end
131+
85132
end
86133
end

+DSS_MATLAB/Base.m

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
classdef Base < handle & matlab.mixin.CustomDisplay & matlab.mixin.SetGet
2+
properties (Access = protected, Hidden = true)
3+
apiutil
4+
libname
5+
end
6+
27
methods (Access = protected)
38
function propgrp = getPropertyGroups(obj)
49
propgrp = matlab.mixin.util.PropertyGroup();
@@ -16,17 +21,27 @@
1621
end
1722

1823
methods (Access = public)
24+
function obj = Base(apiutil)
25+
obj.apiutil = apiutil;
26+
obj.libname = apiutil.libname;
27+
end
1928

2029
end
2130

2231
methods
2332

24-
function obj = CheckForError(obj)
25-
error = calllib('dss_capi_v7', 'Error_Get_Number');
33+
function varargout = CheckForError(obj, varargin)
34+
error = calllib(obj.libname, 'Error_Get_Number');
2635
if error ~= 0
27-
ME = MException(['DSS_MATLAB:Error' int2str(error)], strrep(calllib('dss_capi_v7', 'Error_Get_Description'), '\', '\\'));
36+
ME = MException(['DSS_MATLAB:Error' int2str(error)], strrep(calllib(obj.libname, 'Error_Get_Description'), '\', '\\'));
2837
throw(ME);
2938
end
39+
varargout = varargin;
40+
end
41+
42+
function obj = clear_api_buffers(obj)
43+
calllib(obj.libname, 'DSS_DisposeGRData');
44+
calllib(obj.libname, 'DSS_ResetStringBuffer');
3045
end
3146
end
3247
end

+DSS_MATLAB/IActiveClass.m

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
% NumElements - Number of elements in this class. Same as Count property.
1212
% ActiveClassParent - Get the name of the parent class of the active class
1313

14-
properties (Access = protected)
15-
apiutil
16-
end
17-
1814
properties
1915
ActiveClassName
2016
AllNames
@@ -28,54 +24,62 @@
2824

2925
methods (Access = public)
3026
function obj = IActiveClass(apiutil)
31-
obj.apiutil = apiutil;
27+
obj@DSS_MATLAB.Base(apiutil);
3228
end
3329

3430
end
3531
methods
3632

3733
function result = get.ActiveClassName(obj)
3834
% (read-only) Returns name of active class.
39-
result = calllib('dss_capi_v7', 'ActiveClass_Get_ActiveClassName');
35+
result = calllib(obj.libname, 'ActiveClass_Get_ActiveClassName');
36+
obj.CheckForError();
4037
end
4138

4239
function result = get.AllNames(obj)
4340
% (read-only) Array of strings consisting of all element names in the active class.
44-
result = DSS_MATLAB.get_string_array('ActiveClass_Get_AllNames');
41+
result = obj.apiutil.get_string_array('ActiveClass_Get_AllNames');
42+
obj.CheckForError();
4543
end
4644

4745
function result = get.Count(obj)
4846
% (read-only) Number of elements in Active Class. Same as NumElements Property.
49-
result = calllib('dss_capi_v7', 'ActiveClass_Get_Count');
47+
result = calllib(obj.libname, 'ActiveClass_Get_Count');
48+
obj.CheckForError();
5049
end
5150

5251
function result = get.First(obj)
5352
% (read-only) Sets first element in the active class to be the active DSS object. If object is a CktElement, ActiveCktELment also points to this element. Returns 0 if none.
54-
result = calllib('dss_capi_v7', 'ActiveClass_Get_First');
53+
result = calllib(obj.libname, 'ActiveClass_Get_First');
54+
obj.CheckForError();
5555
end
5656

5757
function result = get.Name(obj)
5858
% Name of the Active Element of the Active Class
59-
result = calllib('dss_capi_v7', 'ActiveClass_Get_Name');
59+
result = calllib(obj.libname, 'ActiveClass_Get_Name');
60+
obj.CheckForError();
6061
end
6162
function obj = set.Name(obj, Value)
62-
calllib('dss_capi_v7', 'ActiveClass_Set_Name', Value);
63+
calllib(obj.libname, 'ActiveClass_Set_Name', Value);
6364
obj.CheckForError();
6465
end
6566

6667
function result = get.Next(obj)
6768
% (read-only) Sets next element in active class to be the active DSS object. If object is a CktElement, ActiveCktElement also points to this element. Returns 0 if no more.
68-
result = calllib('dss_capi_v7', 'ActiveClass_Get_Next');
69+
result = calllib(obj.libname, 'ActiveClass_Get_Next');
70+
obj.CheckForError();
6971
end
7072

7173
function result = get.NumElements(obj)
7274
% (read-only) Number of elements in this class. Same as Count property.
73-
result = calllib('dss_capi_v7', 'ActiveClass_Get_NumElements');
75+
result = calllib(obj.libname, 'ActiveClass_Get_NumElements');
76+
obj.CheckForError();
7477
end
7578

7679
function result = get.ActiveClassParent(obj)
7780
% Get the name of the parent class of the active class
78-
result = calllib('dss_capi_v7', 'ActiveClass_Get_ActiveClassParent');
81+
result = calllib(obj.libname, 'ActiveClass_Get_ActiveClassParent');
82+
obj.CheckForError();
7983
end
8084
end
8185
end

0 commit comments

Comments
 (0)