[6454] | 1 | %
|
---|
| 2 | % definition for the kml_substyle super (base) and sub (derived) class.
|
---|
| 3 | %
|
---|
| 4 | % [kml]=kml_substyle(varargin)
|
---|
| 5 | %
|
---|
| 6 | % where the optional varargin and defaults are:
|
---|
| 7 | % id (char, substyle id, '')
|
---|
| 8 | %
|
---|
| 9 | % note that zero arguments constructs a default instance; one
|
---|
| 10 | % argument of the class copies the instance; and two or more
|
---|
| 11 | % arguments constructs a new instance from the arguments.
|
---|
| 12 | %
|
---|
| 13 | classdef kml_substyle < kml_object
|
---|
| 14 | properties
|
---|
| 15 | end
|
---|
| 16 |
|
---|
| 17 | methods
|
---|
| 18 | function [kml]=kml_substyle(varargin)
|
---|
| 19 |
|
---|
| 20 | kml=kml@kml_object(varargin{:});
|
---|
| 21 |
|
---|
| 22 | switch nargin
|
---|
| 23 |
|
---|
| 24 | % create a default object
|
---|
| 25 |
|
---|
| 26 | case 0
|
---|
| 27 |
|
---|
| 28 | % copy the object or create the object from the input
|
---|
| 29 |
|
---|
| 30 | otherwise
|
---|
| 31 | if (nargin == 1) && isa(varargin{1},class(kml))
|
---|
| 32 | kml=varargin{1};
|
---|
| 33 |
|
---|
| 34 | else
|
---|
| 35 | fnames=fieldnames(kml);
|
---|
| 36 |
|
---|
| 37 | for i=length(fieldnames(kml_object()))+1:min(nargin,length(fnames))
|
---|
| 38 | if isa(varargin{i},class(kml.(fnames{i})))
|
---|
| 39 | if ~isempty(varargin{i})
|
---|
| 40 | kml.(fnames{i})=varargin{i};
|
---|
| 41 | end
|
---|
| 42 | else
|
---|
| 43 | if ~isempty(inputname(i))
|
---|
[6455] | 44 | warning('Argument ''%s'' for property ''%s'' is a ''%s'' class object, not ''%s''.',...
|
---|
[6454] | 45 | inputname(i),fnames{i},class(varargin{i}),class(kml.(fnames{i})));
|
---|
| 46 | else
|
---|
[6455] | 47 | warning('Argument %d for property ''%s'' is a ''%s'' class object, not ''%s''.',...
|
---|
[6454] | 48 | i ,fnames{i},class(varargin{i}),class(kml.(fnames{i})));
|
---|
| 49 | end
|
---|
| 50 | end
|
---|
| 51 | end
|
---|
| 52 | end
|
---|
| 53 |
|
---|
| 54 | end
|
---|
| 55 |
|
---|
| 56 | end
|
---|
| 57 |
|
---|
| 58 | % display the object
|
---|
| 59 |
|
---|
| 60 | function []=disp(kml)
|
---|
| 61 |
|
---|
| 62 | for i=1:numel(kml)
|
---|
| 63 | if strcmp(class(kml),'kml_substyle')
|
---|
| 64 | disp(sprintf('class ''%s'' object ''%s%s'' = \n',...
|
---|
| 65 | class(kml),inputname(1),string_dim(kml,i)));
|
---|
| 66 | end
|
---|
| 67 | disp@kml_object(kml(i));
|
---|
| 68 | if strcmp(class(kml),'kml_substyle')
|
---|
| 69 | disp(sprintf('\n'));
|
---|
| 70 | end
|
---|
| 71 | end
|
---|
| 72 |
|
---|
| 73 | end
|
---|
| 74 |
|
---|
[6479] | 75 | % return the fieldnames of the object
|
---|
| 76 |
|
---|
| 77 | function [fnames]=fieldnames(kml)
|
---|
| 78 |
|
---|
| 79 | % fieldnames for a sub (derived) class list those before super (base)
|
---|
| 80 |
|
---|
| 81 | fnames=fieldnames(kml_object());
|
---|
| 82 |
|
---|
| 83 | end
|
---|
| 84 |
|
---|
[6455] | 85 | % set the properties of the object
|
---|
| 86 |
|
---|
| 87 | function [kml]=set(kml,varargin)
|
---|
| 88 |
|
---|
| 89 | kmlref=feval(class(kml));
|
---|
[6456] | 90 | fnames=fieldnames(kmlref);
|
---|
[6455] | 91 |
|
---|
| 92 | % loop through each parameter in the input list (comparing to the reference
|
---|
| 93 | % object in case property types have been changed)
|
---|
| 94 |
|
---|
| 95 | for i=1:2:length(varargin)
|
---|
[6456] | 96 | if ismember(varargin{i},fnames) && (i+1 <= length(varargin))
|
---|
[6455] | 97 | if isa(varargin{i+1},class(kmlref.(varargin{i})))
|
---|
| 98 | kml.(varargin{i})=varargin{i+1};
|
---|
| 99 | else
|
---|
| 100 | if ~isempty(inputname(i+1))
|
---|
| 101 | warning('Argument ''%s'' for property ''%s'' is a ''%s'' class object, not ''%s''.',...
|
---|
[6456] | 102 | inputname(i+2),varargin{i},class(varargin{i+1}),class(kmlref.(varargin{i})));
|
---|
[6455] | 103 | else
|
---|
| 104 | warning('Argument %d for property ''%s'' is a ''%s'' class object, not ''%s''.',...
|
---|
[6456] | 105 | i+2 ,varargin{i},class(varargin{i+1}),class(kmlref.(varargin{i})));
|
---|
[6455] | 106 | end
|
---|
| 107 | end
|
---|
| 108 | else
|
---|
| 109 | warning('Property ''%s'' for class ''%s'' does not exist.',...
|
---|
| 110 | varargin{i},class(kmlref));
|
---|
| 111 | end
|
---|
| 112 | end
|
---|
| 113 |
|
---|
| 114 | end
|
---|
| 115 |
|
---|
[6454] | 116 | % write the object
|
---|
| 117 |
|
---|
| 118 | function []=kml_write(kml,fid,indent)
|
---|
| 119 |
|
---|
| 120 | if ~exist('fid','var') || isempty(fid)
|
---|
| 121 | fid=1;
|
---|
| 122 | end
|
---|
| 123 | if ~exist('indent','var') || isempty(indent)
|
---|
| 124 | indent='';
|
---|
| 125 | end
|
---|
| 126 |
|
---|
| 127 | % loop over the substyles
|
---|
| 128 |
|
---|
| 129 | for i=1:numel(kml)
|
---|
| 130 | if strcmp(class(kml),'kml_substyle')
|
---|
| 131 | if ~isempty(kml(i).id)
|
---|
| 132 | fprintf(fid,'%s<!SubStyle id="%s">\n',indent,kml(i).id);
|
---|
| 133 | else
|
---|
| 134 | fprintf(fid,'%s<!SubStyle>\n',indent);
|
---|
| 135 | end
|
---|
| 136 | end
|
---|
| 137 | kml_write@kml_object(kml(i),fid,indent);
|
---|
| 138 | if strcmp(class(kml),'kml_substyle')
|
---|
| 139 | fprintf(fid,'%s<!/SubStyle>\n',indent);
|
---|
| 140 | end
|
---|
| 141 | end
|
---|
| 142 |
|
---|
| 143 | end
|
---|
| 144 |
|
---|
| 145 | end
|
---|
| 146 |
|
---|
| 147 | end
|
---|
| 148 |
|
---|