Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: KML Driver 4 : * Purpose: Class for reading, parsing and handling a kmlfile. 5 : * Author: Jens Oberender, j.obi@troja.net 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2007, Jens Oberender 9 : * Copyright (c) 2008-2012, Even Rouault <even dot rouault at spatialys.com> 10 : * 11 : * SPDX-License-Identifier: MIT 12 : ****************************************************************************/ 13 : #ifndef OGR_KML_KML_H_INCLUDED 14 : #define OGR_KML_KML_H_INCLUDED 15 : 16 : #ifdef HAVE_EXPAT 17 : 18 : #include "ogr_expat.h" 19 : #include "cpl_vsi.h" 20 : 21 : // std 22 : #include <iostream> 23 : #include <string> 24 : #include <vector> 25 : 26 : #include "cpl_port.h" 27 : #include "kmlutility.h" 28 : 29 : class KMLNode; 30 : 31 : typedef enum 32 : { 33 : KML_VALIDITY_UNKNOWN, 34 : KML_VALIDITY_INVALID, 35 : KML_VALIDITY_VALID 36 : } OGRKMLValidity; 37 : 38 26 : class KML /* non final */ 39 : { 40 : public: 41 : virtual ~KML(); 42 : bool open(const char *pszFilename); 43 : bool isValid(); 44 : bool isHandled(std::string const &elem) const; 45 : virtual bool isLeaf(std::string const &elem) const = 0; 46 : virtual bool isFeature(std::string const &elem) const = 0; 47 : virtual bool isFeatureContainer(std::string const &elem) const = 0; 48 : virtual bool isContainer(std::string const &elem) const = 0; 49 : virtual bool isRest(std::string const &elem) const = 0; 50 : 51 : bool hasOnlyEmpty() const; 52 : 53 : bool parse(); 54 : void print(unsigned short what = 3); 55 : std::string getError() const; 56 : int classifyNodes(); 57 : void eliminateEmpty(); 58 : int getNumLayers() const; 59 : bool selectLayer(int); 60 : std::string getCurrentName() const; 61 : Nodetype getCurrentType() const; 62 : int is25D() const; 63 : int getNumFeatures(); 64 : Feature *getFeature(std::size_t nNum, int &nLastAsked, int &nLastCount); 65 : 66 : void unregisterLayerIfMatchingThisNode(KMLNode *poNode); 67 : 68 : protected: 69 : KML(); 70 : void checkValidity(); 71 : 72 : static void XMLCALL startElement(void *, const char *, const char **); 73 : static void XMLCALL startElementValidate(void *, const char *, 74 : const char **); 75 : static void XMLCALL dataHandler(void *, const char *, int); 76 : static void XMLCALL dataHandlerValidate(void *, const char *, int); 77 : static void XMLCALL endElement(void *, const char *); 78 : 79 : // Trunk of KMLnodes. 80 : KMLNode *poTrunk_ = nullptr; 81 : // Number of layers. 82 : int nNumLayers_ = -1; 83 : KMLNode **papoLayers_ = nullptr; 84 : 85 : private: 86 : // Depth of the DOM. 87 : unsigned int nDepth_ = 0; 88 : // KML version number. 89 : std::string sVersion_{}; 90 : // Set to KML_VALIDITY_VALID if the beginning of the file is detected as KML 91 : OGRKMLValidity validity = KML_VALIDITY_UNKNOWN; 92 : // File descriptor. 93 : VSILFILE *pKMLFile_ = nullptr; 94 : // Error text ("" when everything is OK"). 95 : std::string sError_{}; 96 : // Current KMLNode. 97 : KMLNode *poCurrent_ = nullptr; 98 : 99 : XML_Parser oCurrentParser{}; 100 : int nDataHandlerCounter = 0; 101 : int nWithoutEventCounter = 0; 102 : 103 : CPL_DISALLOW_COPY_ASSIGN(KML) 104 : }; 105 : 106 : #endif // HAVE_EXPAT 107 : 108 : #endif /* OGR_KML_KML_H_INCLUDED */