source: issm/trunk-jpl/src/c/classes/KML/KML_Feature.cpp@ 15012

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

CHG: moved classes/objects back to classes

File size: 4.9 KB
Line 
1/*!\file KML_Feature.cpp
2 * \brief: implementation of the kml_feature 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 "../classes.h"
14#include "shared/shared.h"
15/*}}}*/
16
17/*Constructors/destructor/copy*/
18/*FUNCTION KML_Feature::KML_Feature(){{{*/
19KML_Feature::KML_Feature(){
20
21 memcpy(name,"",(strlen("")+1)*sizeof(char));
22
23 visibility=true;
24 open =false;
25 memcpy(snippet,"",(strlen("")+1)*sizeof(char));
26 memcpy(descript,"",(strlen("")+1)*sizeof(char));
27 memcpy(styleurl,"",(strlen("")+1)*sizeof(char));
28 style =new DataSet;
29
30}
31/*}}}*/
32/*FUNCTION KML_Feature::~KML_Feature(){{{*/
33KML_Feature::~KML_Feature(){
34
35 if (style) {
36 delete style;
37 style =NULL;
38 }
39
40}
41/*}}}*/
42
43/*Other*/
44/*FUNCTION KML_Feature::Echo {{{*/
45void KML_Feature::Echo(){
46
47 bool flag=true;
48
49 KML_Object::Echo();
50
51 if(flag) _pprintLine_(" name: \"" << name << "\"");
52 if(flag) _pprintLine_(" visibility: " << (visibility ? "true" : "false"));
53 if(flag) _pprintLine_(" open: " << (open ? "true" : "false"));
54 if(flag) _pprintLine_(" snippet: \"" << snippet << "\"");
55 if(flag) _pprintLine_(" descript: \"" << descript << "\"");
56 if(flag) _pprintLine_(" styleurl: \"" << styleurl << "\"");
57 if(flag) _pprintLine_(" style: (size=" << style->Size() << ")");
58
59 return;
60}
61/*}}}*/
62/*FUNCTION KML_Feature::DeepEcho {{{*/
63void KML_Feature::DeepEcho(){
64
65 char indent[81]="";
66
67 KML_Feature::DeepEcho(indent);
68
69 return;
70}
71/*}}}*/
72/*FUNCTION KML_Feature::DeepEcho {{{*/
73void KML_Feature::DeepEcho(const char* indent){
74
75 int i;
76 char indent2[81];
77 bool flag=true;
78
79 KML_Object::DeepEcho(indent);
80
81 if(flag) _pprintLine_(indent << " name: \"" << name << "\"");
82 if(flag) _pprintLine_(indent << " visibility: " << (visibility ? "true" : "false"));
83 if(flag) _pprintLine_(indent << " open: " << (open ? "true" : "false"));
84 if(flag) _pprintLine_(indent << " snippet: \"" << snippet << "\"");
85 if(flag) _pprintLine_(indent << " descript: \"" << descript << "\"");
86 if(flag) _pprintLine_(indent << " styleurl: \"" << styleurl << "\"");
87
88/* loop over any styles for the feature */
89
90 memcpy(indent2,indent,(strlen(indent)+1)*sizeof(char));
91 strcat(indent2," ");
92
93 if (style->Size())
94 for (i=0; i<style->Size(); i++) {
95 if(flag) _pprintLine_(indent << " style: -------- begin [" << i << "] --------");
96 ((KML_Style *)style->GetObjectByOffset(i))->DeepEcho(indent2);
97 if(flag) _pprintLine_(indent << " style: -------- end [" << i << "] --------");
98 }
99 else
100 if(flag) _pprintLine_(indent << " style: [empty]");
101
102 return;
103}
104/*}}}*/
105/*FUNCTION KML_Feature::Write {{{*/
106void KML_Feature::Write(FILE* filout,const char* indent){
107
108 int i;
109 char indent2[81];
110
111 KML_Object::Write(filout,indent);
112
113 if (name && strlen(name))
114 fprintf(filout,"%s <name>%s</name>\n",indent,name);
115 fprintf(filout,"%s <visibility>%d</visibility>\n",indent,(visibility ? 1 : 0));
116 fprintf(filout,"%s <open>%d</open>\n",indent,(open ? 1 : 0));
117 if (snippet && strlen(snippet))
118 fprintf(filout,"%s <Snippet maxLines=\"2\">%s</Snippet>\n",indent,snippet);
119 if (descript && strlen(descript))
120 fprintf(filout,"%s <description>%s</description>\n",indent,descript);
121 if (styleurl && strlen(styleurl))
122 fprintf(filout,"%s <styleUrl>%s</styleUrl>\n",indent,styleurl);
123
124/* loop over any styles for the feature */
125
126 memcpy(indent2,indent,(strlen(indent)+1)*sizeof(char));
127
128 strcat(indent2," ");
129
130 for (i=0; i<style->Size(); i++)
131 ((KML_Style *)style->GetObjectByOffset(i))->Write(filout,indent2);
132
133 return;
134}
135/*}}}*/
136/*FUNCTION KML_Feature::Read {{{*/
137void KML_Feature::Read(FILE* fid,char* kstr){
138
139 KML_Object* kobj;
140
141/* process field within opening and closing tags */
142
143 if (!strncmp(kstr,"</Feature", 9))
144 return;
145 else if (!strncmp(kstr,"</",2))
146 {_error_("KML_Feature::Read -- Unexpected closing tag " << kstr);}
147 else if (strncmp(kstr,"<",1))
148 {_error_("KML_Feature::Read -- Unexpected field \"" << kstr << "\"");}
149
150 else if (!strncmp(kstr,"<Style", 6)) {
151 kobj=(KML_Object*)new KML_Style();
152 kobj->Read(fid,kstr);
153 style ->AddObject((Object*)kobj);
154 }
155
156 else if (!strcmp(kstr,"<name>"))
157 KMLFileTokenParse( name ,NULL,KML_FEATURE_NAME_LENGTH, kstr, fid);
158 else if (!strcmp(kstr,"<visibility>"))
159 KMLFileTokenParse(&visibility, kstr, fid);
160 else if (!strcmp(kstr,"<open>"))
161 KMLFileTokenParse(&open , kstr, fid);
162 else if (!strncmp(kstr,"<snippet", 8))
163 KMLFileTokenParse( snippet ,NULL,KML_FEATURE_SNIPPET_LENGTH, kstr, fid);
164 else if (!strcmp(kstr,"<description>"))
165 KMLFileTokenParse( descript ,NULL,KML_FEATURE_DESCRIPT_LENGTH, kstr, fid);
166 else if (!strcmp(kstr,"<styleUrl>"))
167 KMLFileTokenParse( styleurl ,NULL,KML_FEATURE_STYLEURL_LENGTH, kstr, fid);
168
169 else if (!strncmp(kstr,"<",1))
170 KML_Object::Read(fid,kstr);
171
172 return;
173}
174/*}}}*/
Note: See TracBrowser for help on using the repository browser.