/gdal/ogr/ogrsf_frmts/kml/kml.h

https://github.com/jehc/MondocosmOS · C Header · 124 lines · 70 code · 16 blank · 38 comment · 1 complexity · 3041fb4990da0d325ad2e87d1bd36a8a MD5 · raw file

  1. /******************************************************************************
  2. * $Id: kml.h 20996 2010-10-28 18:38:15Z rouault $
  3. *
  4. * Project: KML Driver
  5. * Purpose: Class for reading, parsing and handling a kmlfile.
  6. * Author: Jens Oberender, j.obi@troja.net
  7. *
  8. ******************************************************************************
  9. * Copyright (c) 2007, Jens Oberender
  10. *
  11. * Permission is hereby granted, free of charge, to any person obtaining a
  12. * copy of this software and associated documentation files (the "Software"),
  13. * to deal in the Software without restriction, including without limitation
  14. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  15. * and/or sell copies of the Software, and to permit persons to whom the
  16. * Software is furnished to do so, subject to the following conditions:
  17. *
  18. * The above copyright notice and this permission notice shall be included
  19. * in all copies or substantial portions of the Software.
  20. *
  21. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  22. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  24. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  25. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  26. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  27. * DEALINGS IN THE SOFTWARE.
  28. ****************************************************************************/
  29. #ifndef OGR_KML_KML_H_INCLUDED
  30. #define OGR_KML_KML_H_INCLUDED
  31. #include "ogr_expat.h"
  32. #include "cpl_vsi.h"
  33. // std
  34. #include <iostream>
  35. #include <string>
  36. #include <vector>
  37. /* Workaround VC6 bug */
  38. #if defined(_MSC_VER) && (_MSC_VER <= 1200)
  39. namespace std
  40. {
  41. typedef ::size_t size_t;
  42. }
  43. #endif
  44. #include "cpl_port.h"
  45. #include "kmlutility.h"
  46. class KMLNode;
  47. typedef enum
  48. {
  49. KML_VALIDITY_UNKNOWN,
  50. KML_VALIDITY_INVALID,
  51. KML_VALIDITY_VALID
  52. } OGRKMLValidity;
  53. class KML
  54. {
  55. public:
  56. KML();
  57. virtual ~KML();
  58. bool open(const char* pszFilename);
  59. bool isValid();
  60. bool isHandled(std::string const& elem) const;
  61. virtual bool isLeaf(std::string const& elem) const;
  62. virtual bool isFeature(std::string const& elem) const;
  63. virtual bool isFeatureContainer(std::string const& elem) const;
  64. virtual bool isContainer(std::string const& elem) const;
  65. virtual bool isRest(std::string const& elem) const;
  66. virtual void findLayers(KMLNode* poNode);
  67. void parse();
  68. void print(unsigned short what = 3);
  69. std::string getError() const;
  70. void classifyNodes();
  71. void eliminateEmpty();
  72. int getNumLayers() const;
  73. bool selectLayer(int);
  74. std::string getCurrentName() const;
  75. Nodetype getCurrentType() const;
  76. int is25D() const;
  77. int getNumFeatures();
  78. Feature* getFeature(std::size_t nNum, int& nLastAsked, int &nLastCount);
  79. protected:
  80. void checkValidity();
  81. static void XMLCALL startElement(void *, const char *, const char **);
  82. static void XMLCALL startElementValidate(void *, const char *, const char **);
  83. static void XMLCALL dataHandler(void *, const char *, int);
  84. static void XMLCALL dataHandlerValidate(void *, const char *, int);
  85. static void XMLCALL endElement(void *, const char *);
  86. // trunk of KMLnodes
  87. KMLNode* poTrunk_;
  88. // number of layers;
  89. int nNumLayers_;
  90. KMLNode** papoLayers_;
  91. private:
  92. // depth of the DOM
  93. unsigned int nDepth_;
  94. // KML version number
  95. std::string sVersion_;
  96. // set to KML_VALIDITY_VALID if the beginning of the file is detected as KML
  97. OGRKMLValidity validity;
  98. // file descriptor
  99. VSILFILE *pKMLFile_;
  100. // error text ("" when everything is OK")
  101. std::string sError_;
  102. // current KMLNode
  103. KMLNode *poCurrent_;
  104. XML_Parser oCurrentParser;
  105. int nDataHandlerCounter;
  106. int nWithoutEventCounter;
  107. };
  108. #endif /* OGR_KML_KML_H_INCLUDED */