/*!\file KML_Feature.cpp * \brief: implementation of the kml_feature abstract object */ /*Headers:*/ /*{{{*/ #ifdef HAVE_CONFIG_H #include #else #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" #endif #include "../shared/shared.h" /*}}}*/ /*{{{*/ #ifdef HAVE_CONFIG_H #include #else #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" #endif #include "./KML_Feature.h" #include "./KML_Style.h" #include "./KMLFileReadUtils.h" #include "../shared/shared.h" /*}}}*/ /*Constructors/destructor/copy*/ /*FUNCTION KML_Feature::KML_Feature(){{{*/ KML_Feature::KML_Feature(){ memcpy(name,"",(strlen("")+1)*sizeof(char)); visibility=true; open =false; memcpy(snippet,"",(strlen("")+1)*sizeof(char)); memcpy(descript,"",(strlen("")+1)*sizeof(char)); memcpy(styleurl,"",(strlen("")+1)*sizeof(char)); style =new DataSet; } /*}}}*/ /*FUNCTION KML_Feature::~KML_Feature(){{{*/ KML_Feature::~KML_Feature(){ if (style) { delete style; style =NULL; } } /*}}}*/ /*Other*/ /*FUNCTION KML_Feature::Echo {{{*/ void KML_Feature::Echo(){ bool flag=true; KML_Object::Echo(); if(flag) _pprintString_(" name: \"" << name << "\"" << "\n"); if(flag) _pprintString_(" visibility: " << (visibility ? "true" : "false") << "\n"); if(flag) _pprintString_(" open: " << (open ? "true" : "false") << "\n"); if(flag) _pprintString_(" snippet: \"" << snippet << "\"" << "\n"); if(flag) _pprintString_(" descript: \"" << descript << "\"" << "\n"); if(flag) _pprintString_(" styleurl: \"" << styleurl << "\"" << "\n"); if(flag) _pprintString_(" style: (size=" << style->Size() << ")" << "\n"); return; } /*}}}*/ /*FUNCTION KML_Feature::DeepEcho {{{*/ void KML_Feature::DeepEcho(){ char indent[81]=""; KML_Feature::DeepEcho(indent); return; } /*}}}*/ /*FUNCTION KML_Feature::DeepEcho {{{*/ void KML_Feature::DeepEcho(const char* indent){ int i; char indent2[81]; bool flag=true; KML_Object::DeepEcho(indent); if(flag) _pprintString_(indent << " name: \"" << name << "\"" << "\n"); if(flag) _pprintString_(indent << " visibility: " << (visibility ? "true" : "false") << "\n"); if(flag) _pprintString_(indent << " open: " << (open ? "true" : "false") << "\n"); if(flag) _pprintString_(indent << " snippet: \"" << snippet << "\"" << "\n"); if(flag) _pprintString_(indent << " descript: \"" << descript << "\"" << "\n"); if(flag) _pprintString_(indent << " styleurl: \"" << styleurl << "\"" << "\n"); /* loop over any styles for the feature */ memcpy(indent2,indent,(strlen(indent)+1)*sizeof(char)); strcat(indent2," "); if (style->Size()) for (i=0; iSize(); i++) { if(flag) _pprintString_(indent << " style: -------- begin [" << i << "] --------" << "\n"); ((KML_Style *)style->GetObjectByOffset(i))->DeepEcho(indent2); if(flag) _pprintString_(indent << " style: -------- end [" << i << "] --------" << "\n"); } else if(flag) _pprintString_(indent << " style: [empty]" << "\n"); return; } /*}}}*/ /*FUNCTION KML_Feature::Write {{{*/ void KML_Feature::Write(FILE* filout,const char* indent){ int i; char indent2[81]; KML_Object::Write(filout,indent); if (name && strlen(name)) fprintf(filout,"%s %s\n",indent,name); fprintf(filout,"%s %d\n",indent,(visibility ? 1 : 0)); fprintf(filout,"%s %d\n",indent,(open ? 1 : 0)); if (snippet && strlen(snippet)) fprintf(filout,"%s %s\n",indent,snippet); if (descript && strlen(descript)) fprintf(filout,"%s %s\n",indent,descript); if (styleurl && strlen(styleurl)) fprintf(filout,"%s %s\n",indent,styleurl); /* loop over any styles for the feature */ memcpy(indent2,indent,(strlen(indent)+1)*sizeof(char)); strcat(indent2," "); for (i=0; iSize(); i++) ((KML_Style *)style->GetObjectByOffset(i))->Write(filout,indent2); return; } /*}}}*/ /*FUNCTION KML_Feature::Read {{{*/ void KML_Feature::Read(FILE* fid,char* kstr){ KML_Object* kobj; /* process field within opening and closing tags */ if (!strncmp(kstr,"Read(fid,kstr); style ->AddObject((Object*)kobj); } else if (!strcmp(kstr,"")) KMLFileTokenParse( name ,NULL,KML_FEATURE_NAME_LENGTH, kstr, fid); else if (!strcmp(kstr,"")) KMLFileTokenParse(&visibility, kstr, fid); else if (!strcmp(kstr,"")) KMLFileTokenParse(&open , kstr, fid); else if (!strncmp(kstr,"")) KMLFileTokenParse( descript ,NULL,KML_FEATURE_DESCRIPT_LENGTH, kstr, fid); else if (!strcmp(kstr,"")) KMLFileTokenParse( styleurl ,NULL,KML_FEATURE_STYLEURL_LENGTH, kstr, fid); else if (!strncmp(kstr,"<",1)) KML_Object::Read(fid,kstr); return; } /*}}}*/