/*!\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*/ 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; } /*}}}*/ KML_Feature::~KML_Feature(){/*{{{*/ if (style) { delete style; style =NULL; } } /*}}}*/ /*Other*/ void KML_Feature::Echo(){/*{{{*/ bool flag=true; KML_Object::Echo(); if(flag) _printf0_(" name: \"" << name << "\"\n"); if(flag) _printf0_(" visibility: " << (visibility ? "true" : "false") << "\n"); if(flag) _printf0_(" open: " << (open ? "true" : "false") << "\n"); if(flag) _printf0_(" snippet: \"" << snippet << "\"\n"); if(flag) _printf0_(" descript: \"" << descript << "\"\n"); if(flag) _printf0_(" styleurl: \"" << styleurl << "\"\n"); if(flag) _printf0_(" style: (size=" << style->Size() << ")\n"); return; } /*}}}*/ void KML_Feature::DeepEcho(){/*{{{*/ char indent[81]=""; KML_Feature::DeepEcho(indent); return; } /*}}}*/ void KML_Feature::DeepEcho(const char* indent){/*{{{*/ int i; char indent2[81]; bool flag=true; KML_Object::DeepEcho(indent); if(flag) _printf0_(indent << " name: \"" << name << "\"\n"); if(flag) _printf0_(indent << " visibility: " << (visibility ? "true" : "false") << "\n"); if(flag) _printf0_(indent << " open: " << (open ? "true" : "false") << "\n"); if(flag) _printf0_(indent << " snippet: \"" << snippet << "\"\n"); if(flag) _printf0_(indent << " descript: \"" << descript << "\"\n"); if(flag) _printf0_(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) _printf0_(indent << " style: -------- begin [" << i << "] --------\n"); ((KML_Style *)style->GetObjectByOffset(i))->DeepEcho(indent2); if(flag) _printf0_(indent << " style: -------- end [" << i << "] --------\n"); } else if(flag) _printf0_(indent << " style: [empty]\n"); return; } /*}}}*/ 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; } /*}}}*/ 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; } /*}}}*/