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