source: issm/trunk-jpl/src/c/classes/objects/KML/KML_Object.cpp@ 14950

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

CHG: moved io to shared/io

File size: 8.8 KB
Line 
1/*!\file KML_Object.cpp
2 * \brief: implementation of the kml_object abstract object
3 */
4
5/*Headers:*/
6/*{{{*/
7#ifdef HAVE_CONFIG_H
8 #include <config.h>
9#else
10#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
11#endif
12
13#include <stdio.h>
14#include <string.h>
15#include "../objects.h"
16#include "../../../shared/shared.h"
17#include "../../../shared/io/io.h"
18#include "../../../Container/Container.h"
19/*}}}*/
20
21/*Constructors/destructor/copy*/
22/*FUNCTION KML_Object::KML_Object(){{{*/
23KML_Object::KML_Object(){
24
25 attrib =new DataSet;
26 commnt =new DataSet;
27 kmlobj =new DataSet;
28
29}
30/*}}}*/
31/*FUNCTION KML_Object::~KML_Object(){{{*/
32KML_Object::~KML_Object(){
33
34 if (attrib) {
35 delete attrib;
36 attrib =NULL;
37 }
38 if (commnt) {
39 delete commnt;
40 commnt =NULL;
41 }
42 if (kmlobj) {
43 delete kmlobj;
44 kmlobj =NULL;
45 }
46
47}
48/*}}}*/
49
50/*Other*/
51/*FUNCTION KML_Object::Echo {{{*/
52void KML_Object::Echo(){
53
54 bool flag=true;
55
56 if(flag) _pprintLine_(" attrib: (size=" << attrib->Size() << ")");
57 if(flag) _pprintLine_(" commnt: (size=" << commnt->Size() << ")");
58 if(flag) _pprintLine_(" kmlobj: (size=" << kmlobj->Size() << ")");
59
60 return;
61}
62/*}}}*/
63/*FUNCTION KML_Object::DeepEcho {{{*/
64void KML_Object::DeepEcho(){
65
66 char indent[81]="";
67
68 KML_Object::DeepEcho(indent);
69
70 return;
71}
72/*}}}*/
73/*FUNCTION KML_Object::DeepEcho {{{*/
74void KML_Object::DeepEcho(const char* indent){
75
76 int i;
77 char indent2[81];
78 bool flag=true;
79
80/* loop over the attributes for the object */
81
82 if (attrib->Size())
83 for (i=0; i<attrib->Size(); i++) {
84 ((KML_Attribute *)attrib->GetObjectByOffset(i))->DeepEcho(indent);
85 }
86 else
87 if(flag) _pprintLine_(indent << " attrib: [empty]");
88
89/* loop over the comments for the object */
90
91 if (commnt->Size())
92 for (i=0; i<commnt->Size(); i++) {
93 ((KML_Comment *)commnt->GetObjectByOffset(i))->DeepEcho(indent);
94 }
95 else
96 if(flag) _pprintLine_(indent << " commnt: [empty]");
97
98/* loop over the unknown objects for the object */
99
100 memcpy(indent2,indent,(strlen(indent)+1)*sizeof(char));
101 strcat(indent2," ");
102
103 if (kmlobj->Size())
104 for (i=0; i<kmlobj->Size(); i++) {
105 if(flag) _pprintLine_(indent << " kmlobj: -------- begin [" << i << "] --------");
106 ((KML_Unknown *)kmlobj->GetObjectByOffset(i))->DeepEcho(indent2);
107 if(flag) _pprintLine_(indent << " kmlobj: -------- end [" << i << "] --------");
108 }
109 else
110 if(flag) _pprintLine_(indent << " kmlobj: [empty]");
111
112 return;
113}
114/*}}}*/
115/*FUNCTION KML_Object::Write {{{*/
116void KML_Object::Write(FILE* filout,const char* indent){
117
118 int i;
119 char indent2[81];
120
121// attributes always written in keyword line of derived classes
122// comments always written after keyword line of derived classes
123
124/* loop over the unknown objects for the object */
125
126 memcpy(indent2,indent,(strlen(indent)+1)*sizeof(char));
127 strcat(indent2," ");
128
129 if (kmlobj->Size())
130 for (i=0; i<kmlobj->Size(); i++) {
131 ((KML_Unknown *)kmlobj->GetObjectByOffset(i))->Write(filout,indent2);
132 }
133
134 return;
135}
136/*}}}*/
137/*FUNCTION KML_Object::Read {{{*/
138void KML_Object::Read(FILE* fid,char* kstr){
139
140 KML_Object* kobj;
141
142/* process field within opening and closing tags */
143
144 if (!strncmp(kstr,"</Object", 8))
145 return;
146 else if (!strncmp(kstr,"</",2))
147 {_error_("KML_Object::Read -- Unexpected closing tag " << kstr << ".\n");}
148 else if (strncmp(kstr,"<",1))
149 {_error_("KML_Object::Read -- Unexpected field \"" << kstr << "\".\n");}
150
151 else if (!strncmp(kstr,"<Placemark",10)) {
152 kobj=(KML_Object*)new KML_Placemark();
153 kobj->Read(fid,kstr);
154 kmlobj ->AddObject((Object*)kobj);
155 }
156
157 else if (!strncmp(kstr,"<Folder", 7)) {
158 kobj=(KML_Object*)new KML_Folder();
159 kobj->Read(fid,kstr);
160 kmlobj ->AddObject((Object*)kobj);
161 }
162
163 else if (!strncmp(kstr,"<Document", 9)) {
164 kobj=(KML_Object*)new KML_Document();
165 kobj->Read(fid,kstr);
166 kmlobj ->AddObject((Object*)kobj);
167 }
168
169 else if (!strncmp(kstr,"<GroundOverlay",14)) {
170 kobj=(KML_Object*)new KML_GroundOverlay();
171 kobj->Read(fid,kstr);
172 kmlobj ->AddObject((Object*)kobj);
173 }
174
175 else if (!strncmp(kstr,"<LatLonBox",10)) {
176 kobj=(KML_Object*)new KML_LatLonBox();
177 kobj->Read(fid,kstr);
178 kmlobj ->AddObject((Object*)kobj);
179 }
180
181 else if (!strncmp(kstr,"<Icon", 5)) {
182 kobj=(KML_Object*)new KML_Icon();
183 kobj->Read(fid,kstr);
184 kmlobj ->AddObject((Object*)kobj);
185 }
186
187 else if (!strncmp(kstr,"<Point", 6)) {
188 kobj=(KML_Object*)new KML_Point();
189 kobj->Read(fid,kstr);
190 kmlobj ->AddObject((Object*)kobj);
191 }
192
193 else if (!strncmp(kstr,"<LineString",11)) {
194 kobj=(KML_Object*)new KML_LineString();
195 kobj->Read(fid,kstr);
196 kmlobj ->AddObject((Object*)kobj);
197 }
198
199 else if (!strncmp(kstr,"<LinearRing",11)) {
200 kobj=(KML_Object*)new KML_LinearRing();
201 kobj->Read(fid,kstr);
202 kmlobj ->AddObject((Object*)kobj);
203 }
204
205 else if (!strncmp(kstr,"<Polygon", 8)) {
206 kobj=(KML_Object*)new KML_Polygon();
207 kobj->Read(fid,kstr);
208 kmlobj ->AddObject((Object*)kobj);
209 }
210
211 else if (!strncmp(kstr,"<MultiGeometry",14)) {
212 kobj=(KML_Object*)new KML_MultiGeometry();
213 kobj->Read(fid,kstr);
214 kmlobj ->AddObject((Object*)kobj);
215 }
216
217// else if (!strncmp(kstr,"<IconStyle",10)) {
218// kobj=(KML_Object*)new KML_IconStyle();
219// kobj->Read(fid,kstr);
220// kmlobj ->AddObject((Object*)kobj);
221// }
222
223// else if (!strncmp(kstr,"<LabelStyle",11)) {
224// kobj=(KML_Object*)new KML_LabelStyle();
225// kobj->Read(fid,kstr);
226// kmlobj ->AddObject((Object*)kobj);
227// }
228
229 else if (!strncmp(kstr,"<LineStyle",10)) {
230 kobj=(KML_Object*)new KML_LineStyle();
231 kobj->Read(fid,kstr);
232 kmlobj ->AddObject((Object*)kobj);
233 }
234
235 else if (!strncmp(kstr,"<PolyStyle",10)) {
236 kobj=(KML_Object*)new KML_PolyStyle();
237 kobj->Read(fid,kstr);
238 kmlobj ->AddObject((Object*)kobj);
239 }
240
241// else if (!strncmp(kstr,"<BalloonStyle",13)) {
242// kobj=(KML_Object*)new KML_BalloonStyle();
243// kobj->Read(fid,kstr);
244// kmlobj ->AddObject((Object*)kobj);
245// }
246
247// else if (!strncmp(kstr,"<ListStyle",10)) {
248// kobj=(KML_Object*)new KML_ListStyle();
249// kobj->Read(fid,kstr);
250// kmlobj ->AddObject((Object*)kobj);
251// }
252
253 else if (!strncmp(kstr,"<",1)) {
254 _pprintLine_("KML_Object::Read -- Unrecognized opening tag " << kstr << ".");
255// KMLFileTagSkip(kstr,
256// fid);
257 kobj=(KML_Object*)new KML_Unknown();
258 kobj->Read(fid,kstr);
259 kmlobj ->AddObject((Object*)kobj);
260 }
261
262 return;
263}
264/*}}}*/
265/*FUNCTION KML_Object::WriteExp {{{*/
266void KML_Object::WriteExp(FILE* fid,const char* nstr,int sgn,double cm,double sp){
267
268 ;
269
270 return;
271}
272/*}}}*/
273/*FUNCTION KML_Object::AddAttrib {{{*/
274void KML_Object::AddAttrib(const char* name,const char* value){
275
276 KML_Attribute* katt=NULL;
277
278 katt=new KML_Attribute();
279 katt->Alloc(name,value);
280 katt->Add(attrib);
281
282 return;
283}
284/*}}}*/
285/*FUNCTION KML_Object::FindAttrib {{{*/
286void KML_Object::FindAttrib(char** pvalue,char* name,char* deflt){
287
288 int i;
289 KML_Attribute* katt=NULL;
290
291/* loop over any attributes for the object */
292
293 if (attrib->Size())
294 for (i=0; i<attrib->Size(); i++)
295 if (!strcmp(((KML_Attribute *)attrib->GetObjectByOffset(i))->name,name)) {
296 katt=(KML_Attribute *)attrib->GetObjectByOffset(i);
297 break;
298 }
299
300/* if found, get the value; otherwise use the default */
301
302 if (katt)
303 katt->Get(pvalue,deflt);
304 else {
305 *pvalue=xNew<char>(strlen(deflt)+1);
306 memcpy(*pvalue,deflt,(strlen(deflt)+1)*sizeof(char));
307 }
308
309 return;
310}
311/*}}}*/
312/*FUNCTION KML_Object::WriteAttrib {{{*/
313void KML_Object::WriteAttrib(FILE* filout,const char* indent){
314
315// attributes always written in keyword line of kml_object
316
317/* loop over any attributes for the object */
318
319 if (attrib->Size())
320 for (int i=0; i<attrib->Size(); i++)
321 ((KML_Attribute *)attrib->GetObjectByOffset(i))->Write(filout,indent);
322
323 return;
324}
325/*}}}*/
326/*FUNCTION KML_Object::AddCommnt {{{*/
327void KML_Object::AddCommnt(int ncom,char** pcom){
328
329 int i;
330 KML_Comment* kcom=NULL;
331
332 for (i=0; i<ncom; i++) {
333 kcom=new KML_Comment();
334 kcom->Alloc(pcom[i]);
335 kcom->Add(commnt);
336 }
337
338 return;
339}
340/*}}}*/
341/*FUNCTION KML_Object::AddCommnt {{{*/
342void KML_Object::AddCommnt(char* value){
343
344 KML_Comment* kcom=NULL;
345
346 kcom=new KML_Comment();
347 kcom->Alloc(value);
348 kcom->Add(commnt);
349
350 return;
351}
352/*}}}*/
353/*FUNCTION KML_Object::FindCommnt {{{*/
354void KML_Object::FindCommnt(char** pvalue,int inum){
355
356 KML_Comment* kcom=NULL;
357
358/* loop over any comments for the object */
359
360 if (inum <= commnt->Size())
361 kcom=(KML_Comment *)commnt->GetObjectByOffset(inum-1);
362
363/* if found, get the value; otherwise use the NULL */
364
365 if (kcom)
366 kcom->Get(pvalue);
367
368 return;
369}
370/*}}}*/
371/*FUNCTION KML_Object::WriteCommnt {{{*/
372void KML_Object::WriteCommnt(FILE* filout,const char* indent){
373
374 int i;
375
376// comments always written after keyword line of kml_object
377
378/* loop over any comments for the object */
379
380 if (commnt->Size())
381 for (i=0; i<commnt->Size(); i++)
382 ((KML_Comment *)commnt->GetObjectByOffset(i))->Write(filout,indent);
383
384 return;
385}
386/*}}}*/
Note: See TracBrowser for help on using the repository browser.