Line data Source code
1 : /********************************************************************** 2 : * 3 : * Project: GML Reader 4 : * Purpose: Implementation of GMLReadState class. 5 : * Author: Frank Warmerdam, warmerdam@pobox.com 6 : * 7 : ********************************************************************** 8 : * Copyright (c) 2002, Frank Warmerdam 9 : * Copyright (c) 2011, Even Rouault <even dot rouault at spatialys.com> 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 OR 22 : * 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 : 30 : #include "cpl_port.h" 31 : #include "gmlreaderp.h" 32 : 33 : #include <cstddef> 34 : #include <memory> 35 : #include <string> 36 : #include <vector> 37 : 38 : #include "cpl_conv.h" 39 : #include "cpl_error.h" 40 : #include "cpl_string.h" 41 : 42 : /************************************************************************/ 43 : /* GMLReadState() */ 44 : /************************************************************************/ 45 : 46 777 : GMLReadState::GMLReadState() 47 777 : : m_poFeature(nullptr), m_poParentState(nullptr), m_nPathLength(0) 48 : { 49 777 : } 50 : 51 : /************************************************************************/ 52 : /* ~GMLReadState() */ 53 : /************************************************************************/ 54 : 55 777 : GMLReadState::~GMLReadState() 56 : { 57 777 : } 58 : 59 : /************************************************************************/ 60 : /* Reset() */ 61 : /************************************************************************/ 62 : 63 2965 : void GMLReadState::Reset() 64 : { 65 2965 : m_poFeature = nullptr; 66 2965 : m_poParentState = nullptr; 67 : 68 2965 : osPath.resize(0); 69 2965 : m_nPathLength = 0; 70 2965 : } 71 : 72 : /************************************************************************/ 73 : /* PushPath() */ 74 : /************************************************************************/ 75 : 76 14722 : void GMLReadState::PushPath(const char *pszElement, int nLen) 77 : 78 : { 79 14722 : if (m_nPathLength > 0) 80 5156 : osPath.append(1, '|'); 81 14722 : if (m_nPathLength < static_cast<int>(aosPathComponents.size())) 82 : { 83 13314 : if (nLen >= 0) 84 : { 85 13031 : aosPathComponents[m_nPathLength].assign(pszElement, nLen); 86 13031 : osPath.append(pszElement, nLen); 87 : } 88 : else 89 : { 90 283 : aosPathComponents[m_nPathLength].assign(pszElement); 91 283 : osPath.append(pszElement); 92 : } 93 : } 94 : else 95 : { 96 1408 : aosPathComponents.push_back(pszElement); 97 1408 : osPath.append(pszElement); 98 : } 99 14722 : m_nPathLength++; 100 14722 : } 101 : 102 : /************************************************************************/ 103 : /* PopPath() */ 104 : /************************************************************************/ 105 : 106 14641 : void GMLReadState::PopPath() 107 : 108 : { 109 14641 : CPLAssert(m_nPathLength > 0); 110 : 111 29282 : osPath.resize(osPath.size() - (aosPathComponents[m_nPathLength - 1].size() + 112 14641 : ((m_nPathLength > 1) ? 1 : 0))); 113 14641 : m_nPathLength--; 114 14641 : }