source: issm/trunk/src/m/kml/kml_substyle.m

Last change on this file was 13975, checked in by Mathieu Morlighem, 12 years ago

merged trunk-jpl and trunk for revision 13974

File size: 5.7 KB
Line 
1%
2% definition for the kml_substyle super (base) and sub (derived) abstract 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%
13classdef 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_substyle());
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))
44 warning('Argument ''%s'' for property ''%s'' is a ''%s'' class object, not ''%s''.',...
45 inputname(i),fnames{i},class(varargin{i}),class(kml.(fnames{i})));
46 else
47 warning('Argument %d for property ''%s'' is a ''%s'' class object, not ''%s''.',...
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
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
85% set the properties of the object
86
87 function [kml]=setprops(kml,varargin)
88
89 kmlref=feval(class(kml));
90 fnames=fieldnames(kmlref);
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)
96 if ismember(varargin{i},fnames) && (i+1 <= length(varargin))
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''.',...
102 inputname(i+2),varargin{i},class(varargin{i+1}),class(kmlref.(varargin{i})));
103 else
104 warning('Argument %d for property ''%s'' is a ''%s'' class object, not ''%s''.',...
105 i+2 ,varargin{i},class(varargin{i+1}),class(kmlref.(varargin{i})));
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
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 kmli=kml(i);
131 if strcmp(class(kml),'kml_substyle')
132 if ~isempty(kmli.id)
133 fprintf(fid,'%s<!SubStyle id="%s">\n',indent,kmli.id);
134 else
135 fprintf(fid,'%s<!SubStyle>\n',indent);
136 end
137 end
138 kml_write@kml_object(kmli,fid,indent);
139 if strcmp(class(kml),'kml_substyle')
140 fprintf(fid,'%s<!/SubStyle>\n',indent);
141 end
142 end
143
144 end
145
146% string write the object
147
148 function [sbuf]=kml_swrite(kml,sbuf,indent)
149
150 if ~exist('sbuf','var') || isempty(sbuf)
151 sbuf=string_buf;
152 end
153 if ~exist('indent','var') || isempty(indent)
154 indent='';
155 end
156
157% loop over the substyles
158
159 for i=1:numel(kml)
160 kmli=kml(i);
161 if strcmp(class(kml),'kml_substyle')
162 if ~isempty(kmli.id)
163 sbuf=add(sbuf,sprintf('%s<!SubStyle id="%s">\n',indent,kmli.id));
164 else
165 sbuf=add(sbuf,sprintf('%s<!SubStyle>\n',indent));
166 end
167 end
168 sbuf=kml_swrite@kml_object(kmli,sbuf,indent);
169 if strcmp(class(kml),'kml_substyle')
170 sbuf=add(sbuf,sprintf('%s<!/SubStyle>\n',indent));
171 end
172 end
173
174 end
175
176 end
177
178end
Note: See TracBrowser for help on using the repository browser.