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