source: issm/trunk-jpl/src/c/objects/KML/KML_File.cpp@ 11200

Last change on this file since 11200 was 11200, checked in by Mathieu Morlighem, 13 years ago

Fixed some g++ warnings: deprecated conversion from string constant to ‘char*’

File size: 6.2 KB
Line 
1/*!\file KML_File.cpp
2 * \brief: implementation of the kml_file object
3 */
4
5/*Headers:*/
6/*{{{1*/
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_File::KML_File(){{{1*/
24KML_File::KML_File(){
25
26 kmlobj =new DataSet;
27
28}
29/*}}}*/
30/*FUNCTION KML_File::~KML_File(){{{1*/
31KML_File::~KML_File(){
32
33 if (kmlobj) {
34 delete kmlobj;
35 kmlobj =NULL;
36 }
37
38}
39/*}}}*/
40
41/*Other*/
42/*FUNCTION KML_File::Echo {{{1*/
43void KML_File::Echo(){
44
45 bool flag=true;
46
47 _printf_(flag,"KML_File:\n");
48 KML_Object::Echo();
49
50 _printf_(flag," kmlobj: (size=%d)\n" ,kmlobj->Size());
51
52 return;
53}
54/*}}}*/
55/*FUNCTION KML_File::DeepEcho {{{1*/
56void KML_File::DeepEcho(){
57
58 char indent[81]="";
59
60 KML_File::DeepEcho(indent);
61
62 return;
63}
64/*}}}*/
65/*FUNCTION KML_File::DeepEcho {{{1*/
66void KML_File::DeepEcho(char* indent){
67
68 int i;
69 char indent2[81];
70 bool flag=true;
71
72 _printf_(flag,"%sKML_File:\n",indent);
73 KML_Object::DeepEcho(indent);
74
75/* loop over the kml objects for the file */
76
77 memcpy(indent2,indent,(strlen(indent)+1)*sizeof(char));
78
79 strcat(indent2," ");
80
81 if (kmlobj->Size())
82 for (i=0; i<kmlobj->Size(); i++) {
83 _printf_(flag,"%s kmlobj: -------- begin [%d] --------\n" ,indent,i);
84 ((KML_Object *)kmlobj->GetObjectByOffset(i))->DeepEcho(indent2);
85 _printf_(flag,"%s kmlobj: -------- end [%d] --------\n" ,indent,i);
86 }
87 else
88 _printf_(flag,"%s kmlobj: [empty]\n" ,indent);
89
90 return;
91}
92/*}}}*/
93/*FUNCTION KML_File::Write {{{1*/
94void KML_File::Write(FILE* filout,char* indent){
95
96 int i;
97 char indent2[81];
98
99 fprintf(filout,"%s<kml",indent);
100 WriteAttrib(filout," ");
101 fprintf(filout,">\n");
102 WriteCommnt(filout,indent);
103
104 KML_Object::Write(filout,indent);
105
106/* loop over the kml objects for the file */
107
108 memcpy(indent2,indent,(strlen(indent)+1)*sizeof(char));
109
110 strcat(indent2," ");
111
112 for (i=0; i<kmlobj->Size(); i++)
113 ((KML_Object *)kmlobj->GetObjectByOffset(i))->Write(filout,indent2);
114
115 fprintf(filout,"%s</kml>\n",indent);
116
117 return;
118}
119/*}}}*/
120/*FUNCTION KML_File::Read {{{1*/
121void KML_File::Read(FILE* fid,char* kstr){
122
123 char* kstri;
124 int ncom=0;
125 char** pcom=NULL;
126 KML_Object* kobj;
127
128/* get object attributes and check for solo tag */
129
130 if (KMLFileTagAttrib(this,
131 kstr))
132 return;
133
134/* loop over and process fields within opening and closing tags */
135
136 while (kstri=KMLFileToken(fid,
137 &ncom,&pcom)) {
138 if (!strncmp(kstri,"</kml", 5)) {
139 xfree((void**)&kstri);
140 break;
141 }
142 else if (!strncmp(kstri,"</",2))
143 _error_("KML_File::Read -- Unexpected closing tag %s.\n",kstri);
144 else if (strncmp(kstri,"<",1))
145 _error_("KML_File::Read -- Unexpected field \"%s\".\n",kstri);
146
147 else if (!strncmp(kstri,"<Placemark",10)) {
148 kobj=(KML_Object*)new KML_Placemark();
149 kobj->Read(fid,kstri);
150 kmlobj ->AddObject((Object*)kobj);
151 }
152
153 else if (!strncmp(kstri,"<Folder", 7)) {
154 kobj=(KML_Object*)new KML_Folder();
155 kobj->Read(fid,kstri);
156 kmlobj ->AddObject((Object*)kobj);
157 }
158
159 else if (!strncmp(kstri,"<Document", 9)) {
160 kobj=(KML_Object*)new KML_Document();
161 kobj->Read(fid,kstri);
162 kmlobj ->AddObject((Object*)kobj);
163 }
164
165 else if (!strncmp(kstri,"<GroundOverlay",14)) {
166 kobj=(KML_Object*)new KML_GroundOverlay();
167 kobj->Read(fid,kstri);
168 kmlobj ->AddObject((Object*)kobj);
169 }
170
171 else if (!strncmp(kstri,"<LatLonBox",10)) {
172 kobj=(KML_Object*)new KML_LatLonBox();
173 kobj->Read(fid,kstri);
174 kmlobj ->AddObject((Object*)kobj);
175 }
176
177 else if (!strncmp(kstri,"<Icon", 5)) {
178 kobj=(KML_Object*)new KML_Icon();
179 kobj->Read(fid,kstri);
180 kmlobj ->AddObject((Object*)kobj);
181 }
182
183 else if (!strncmp(kstri,"<Point", 6)) {
184 kobj=(KML_Object*)new KML_Point();
185 kobj->Read(fid,kstri);
186 kmlobj ->AddObject((Object*)kobj);
187 }
188
189 else if (!strncmp(kstri,"<LineString",11)) {
190 kobj=(KML_Object*)new KML_LineString();
191 kobj->Read(fid,kstri);
192 kmlobj ->AddObject((Object*)kobj);
193 }
194
195 else if (!strncmp(kstri,"<LinearRing",11)) {
196 kobj=(KML_Object*)new KML_LinearRing();
197 kobj->Read(fid,kstri);
198 kmlobj ->AddObject((Object*)kobj);
199 }
200
201 else if (!strncmp(kstri,"<Polygon", 8)) {
202 kobj=(KML_Object*)new KML_Polygon();
203 kobj->Read(fid,kstri);
204 kmlobj ->AddObject((Object*)kobj);
205 }
206
207 else if (!strncmp(kstri,"<MultiGeometry",14)) {
208 kobj=(KML_Object*)new KML_MultiGeometry();
209 kobj->Read(fid,kstri);
210 kmlobj ->AddObject((Object*)kobj);
211 }
212
213// else if (!strncmp(kstri,"<IconStyle",10)) {
214// kobj=(KML_Object*)new KML_IconStyle();
215// kobj->Read(fid,kstri);
216// kmlobj ->AddObject((Object*)kobj);
217// }
218
219// else if (!strncmp(kstri,"<LabelStyle",11)) {
220// kobj=(KML_Object*)new KML_LabelStyle();
221// kobj->Read(fid,kstri);
222// kmlobj ->AddObject((Object*)kobj);
223// }
224
225 else if (!strncmp(kstri,"<LineStyle",10)) {
226 kobj=(KML_Object*)new KML_LineStyle();
227 kobj->Read(fid,kstri);
228 kmlobj ->AddObject((Object*)kobj);
229 }
230
231 else if (!strncmp(kstri,"<PolyStyle",10)) {
232 kobj=(KML_Object*)new KML_PolyStyle();
233 kobj->Read(fid,kstri);
234 kmlobj ->AddObject((Object*)kobj);
235 }
236
237// else if (!strncmp(kstri,"<BalloonStyle",13)) {
238// kobj=(KML_Object*)new KML_BalloonStyle();
239// kobj->Read(fid,kstri);
240// kmlobj ->AddObject((Object*)kobj);
241// }
242
243// else if (!strncmp(kstri,"<ListStyle",10)) {
244// kobj=(KML_Object*)new KML_ListStyle();
245// kobj->Read(fid,kstri);
246// kmlobj ->AddObject((Object*)kobj);
247// }
248
249 else if (!strncmp(kstri,"<",1))
250 KML_Object::Read(fid,kstri);
251
252 xfree((void**)&kstri);
253 }
254
255 this->AddCommnt(ncom,pcom);
256
257 for (ncom; ncom>0; ncom--)
258 xfree((void**)&(pcom[ncom-1]));
259 xfree((void**)&pcom);
260
261 return;
262}
263/*}}}*/
264/*FUNCTION KML_File::WriteExp {{{1*/
265void KML_File::WriteExp(FILE* fid,const char* nstr,int sgn,double cm,double sp){
266
267 int i;
268
269/* loop over the kml objects for the file */
270
271 for (i=0; i<kmlobj->Size(); i++)
272 ((KML_Object *)kmlobj->GetObjectByOffset(i))->WriteExp(fid,nstr,sgn,cm,sp);
273
274 return;
275}
276/*}}}*/
Note: See TracBrowser for help on using the repository browser.