Ice Sheet System Model  4.18
Code documentation
KML_Feature.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 "../shared/shared.h"
14 /*}}}*/
15 /*{{{*/
16 #ifdef HAVE_CONFIG_H
17  #include <config.h>
18 #else
19 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
20 #endif
21 
22 #include "./KML_Feature.h"
23 #include "./KML_Style.h"
24 #include "./KMLFileReadUtils.h"
25 #include "../shared/shared.h"
26 /*}}}*/
27 
28 /*Constructors/destructor/copy*/
30 
31  memcpy(name,"",(strlen("")+1)*sizeof(char));
32 
33  visibility=true;
34  open =false;
35  memcpy(snippet,"",(strlen("")+1)*sizeof(char));
36  memcpy(descript,"",(strlen("")+1)*sizeof(char));
37  memcpy(styleurl,"",(strlen("")+1)*sizeof(char));
38  style =new DataSet;
39 
40 }
41 /*}}}*/
43 
44  if (style) {
45  delete style;
46  style =NULL;
47  }
48 
49 }
50 /*}}}*/
51 
52 /*Other*/
53 void KML_Feature::Echo(){/*{{{*/
54 
55  bool flag=true;
56 
58 
59  if(flag) _printf0_(" name: \"" << name << "\"\n");
60  if(flag) _printf0_(" visibility: " << (visibility ? "true" : "false") << "\n");
61  if(flag) _printf0_(" open: " << (open ? "true" : "false") << "\n");
62  if(flag) _printf0_(" snippet: \"" << snippet << "\"\n");
63  if(flag) _printf0_(" descript: \"" << descript << "\"\n");
64  if(flag) _printf0_(" styleurl: \"" << styleurl << "\"\n");
65  if(flag) _printf0_(" style: (size=" << style->Size() << ")\n");
66 
67  return;
68 }
69 /*}}}*/
70 void KML_Feature::DeepEcho(){/*{{{*/
71 
72  char indent[81]="";
73 
74  KML_Feature::DeepEcho(indent);
75 
76  return;
77 }
78 /*}}}*/
79 void KML_Feature::DeepEcho(const char* indent){/*{{{*/
80 
81  int i;
82  char indent2[81];
83  bool flag=true;
84 
85  KML_Object::DeepEcho(indent);
86 
87  if(flag) _printf0_(indent << " name: \"" << name << "\"\n");
88  if(flag) _printf0_(indent << " visibility: " << (visibility ? "true" : "false") << "\n");
89  if(flag) _printf0_(indent << " open: " << (open ? "true" : "false") << "\n");
90  if(flag) _printf0_(indent << " snippet: \"" << snippet << "\"\n");
91  if(flag) _printf0_(indent << " descript: \"" << descript << "\"\n");
92  if(flag) _printf0_(indent << " styleurl: \"" << styleurl << "\"\n");
93 
94 /* loop over any styles for the feature */
95 
96  memcpy(indent2,indent,(strlen(indent)+1)*sizeof(char));
97  strcat(indent2," ");
98 
99  if (style->Size())
100  for (i=0; i<style->Size(); i++) {
101  if(flag) _printf0_(indent << " style: -------- begin [" << i << "] --------\n");
102  ((KML_Style *)style->GetObjectByOffset(i))->DeepEcho(indent2);
103  if(flag) _printf0_(indent << " style: -------- end [" << i << "] --------\n");
104  }
105  else
106  if(flag) _printf0_(indent << " style: [empty]\n");
107 
108  return;
109 }
110 /*}}}*/
111 void KML_Feature::Write(FILE* filout,const char* indent){/*{{{*/
112 
113  int i;
114  char indent2[81];
115 
116  KML_Object::Write(filout,indent);
117 
118  if (name && strlen(name))
119  fprintf(filout,"%s <name>%s</name>\n",indent,name);
120  fprintf(filout,"%s <visibility>%d</visibility>\n",indent,(visibility ? 1 : 0));
121  fprintf(filout,"%s <open>%d</open>\n",indent,(open ? 1 : 0));
122  if (snippet && strlen(snippet))
123  fprintf(filout,"%s <Snippet maxLines=\"2\">%s</Snippet>\n",indent,snippet);
124  if (descript && strlen(descript))
125  fprintf(filout,"%s <description>%s</description>\n",indent,descript);
126  if (styleurl && strlen(styleurl))
127  fprintf(filout,"%s <styleUrl>%s</styleUrl>\n",indent,styleurl);
128 
129 /* loop over any styles for the feature */
130 
131  memcpy(indent2,indent,(strlen(indent)+1)*sizeof(char));
132 
133  strcat(indent2," ");
134 
135  for (i=0; i<style->Size(); i++)
136  ((KML_Style *)style->GetObjectByOffset(i))->Write(filout,indent2);
137 
138  return;
139 }
140 /*}}}*/
141 void KML_Feature::Read(FILE* fid,char* kstr){/*{{{*/
142 
143  KML_Object* kobj;
144 
145 /* process field within opening and closing tags */
146 
147  if (!strncmp(kstr,"</Feature", 9))
148  return;
149  else if (!strncmp(kstr,"</",2))
150  {_error_("KML_Feature::Read -- Unexpected closing tag " << kstr);}
151  else if (strncmp(kstr,"<",1))
152  {_error_("KML_Feature::Read -- Unexpected field \"" << kstr << "\"");}
153 
154  else if (!strncmp(kstr,"<Style", 6)) {
155  kobj=(KML_Object*)new KML_Style();
156  kobj->Read(fid,kstr);
157  style ->AddObject((Object*)kobj);
158  }
159 
160  else if (!strcmp(kstr,"<name>"))
162  else if (!strcmp(kstr,"<visibility>"))
163  KMLFileTokenParse(&visibility, kstr, fid);
164  else if (!strcmp(kstr,"<open>"))
165  KMLFileTokenParse(&open , kstr, fid);
166  else if (!strncmp(kstr,"<snippet", 8))
168  else if (!strcmp(kstr,"<description>"))
170  else if (!strcmp(kstr,"<styleUrl>"))
172 
173  else if (!strncmp(kstr,"<",1))
174  KML_Object::Read(fid,kstr);
175 
176  return;
177 }
178 /*}}}*/
DataSet::Size
int Size()
Definition: DataSet.cpp:399
KML_Object
Definition: KML_Object.h:13
KML_Feature::name
char name[KML_FEATURE_NAME_LENGTH+1]
Definition: KML_Feature.h:25
_printf0_
#define _printf0_(StreamArgs)
Definition: Print.h:29
DataSet::AddObject
int AddObject(Object *object)
Definition: DataSet.cpp:252
KMLFileReadUtils.h
: header file for kml file reading utilities.
KML_Feature::~KML_Feature
~KML_Feature()
Definition: KML_Feature.cpp:42
KML_Feature::style
DataSet * style
Definition: KML_Feature.h:31
KML_Feature::open
bool open
Definition: KML_Feature.h:27
KML_Object::Read
virtual void Read(FILE *fid, char *kstr)=0
Definition: KML_Object.cpp:143
Object
Definition: Object.h:13
KML_Feature::styleurl
char styleurl[KML_FEATURE_STYLEURL_LENGTH+1]
Definition: KML_Feature.h:30
KML_Style
Definition: KML_Style.h:16
KML_FEATURE_STYLEURL_LENGTH
#define KML_FEATURE_STYLEURL_LENGTH
Definition: KML_Feature.h:11
KML_Object::Write
virtual void Write(FILE *fid, const char *indent)=0
Definition: KML_Object.cpp:122
KML_Object::DeepEcho
virtual void DeepEcho()
Definition: KML_Object.cpp:72
KML_Feature::snippet
char snippet[KML_FEATURE_SNIPPET_LENGTH+1]
Definition: KML_Feature.h:28
KML_Feature::DeepEcho
void DeepEcho()
Definition: KML_Feature.cpp:70
KMLFileTokenParse
int KMLFileTokenParse(int *pival, char *ktag, FILE *fid)
Definition: KMLFileReadUtils.cpp:335
KML_Style.h
: header file for kml_style object
KML_Feature::Write
void Write(FILE *fid, const char *indent)
Definition: KML_Feature.cpp:111
KML_Feature::descript
char descript[KML_FEATURE_DESCRIPT_LENGTH+1]
Definition: KML_Feature.h:29
KML_FEATURE_NAME_LENGTH
#define KML_FEATURE_NAME_LENGTH
Definition: KML_Feature.h:8
KML_Feature::visibility
bool visibility
Definition: KML_Feature.h:26
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
KML_FEATURE_DESCRIPT_LENGTH
#define KML_FEATURE_DESCRIPT_LENGTH
Definition: KML_Feature.h:10
KML_Object::Echo
virtual void Echo()
Definition: KML_Object.cpp:61
DataSet::GetObjectByOffset
Object * GetObjectByOffset(int offset)
Definition: DataSet.cpp:334
KML_Feature.h
: header file for kml_feature abstract object
KML_Feature::Echo
void Echo()
Definition: KML_Feature.cpp:53
DataSet
Declaration of DataSet class.
Definition: DataSet.h:14
KML_Feature::KML_Feature
KML_Feature()
Definition: KML_Feature.cpp:29
KML_FEATURE_SNIPPET_LENGTH
#define KML_FEATURE_SNIPPET_LENGTH
Definition: KML_Feature.h:9
KML_Feature::Read
void Read(FILE *fid, char *kstr)
Definition: KML_Feature.cpp:141