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

Last change on this file since 12915 was 12915, checked in by jschierm, 13 years ago

Implementation of xNew and xDelete in KML classes.

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