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 : * SPDX-License-Identifier: MIT 12 : ****************************************************************************/ 13 : 14 : #include "cpl_port.h" 15 : #include "gmlreaderp.h" 16 : 17 : #include <cstddef> 18 : #include <memory> 19 : #include <string> 20 : #include <vector> 21 : 22 : #include "cpl_conv.h" 23 : #include "cpl_error.h" 24 : #include "cpl_string.h" 25 : 26 : /************************************************************************/ 27 : /* Reset() */ 28 : /************************************************************************/ 29 : 30 3735 : void GMLReadState::Reset() 31 : { 32 3735 : m_poFeature = nullptr; 33 3735 : m_poParentState = nullptr; 34 : 35 3735 : osPath.clear(); 36 3735 : m_nPathLength = 0; 37 3735 : } 38 : 39 : /************************************************************************/ 40 : /* PushPath() */ 41 : /************************************************************************/ 42 : 43 17484 : void GMLReadState::PushPath(const char *pszElement, int nLen) 44 : 45 : { 46 17484 : if (m_nPathLength > 0) 47 5534 : osPath.append(1, '|'); 48 17484 : if (m_nPathLength < static_cast<int>(aosPathComponents.size())) 49 : { 50 15876 : if (nLen >= 0) 51 : { 52 15486 : aosPathComponents[m_nPathLength].assign(pszElement, nLen); 53 15486 : osPath.append(pszElement, nLen); 54 : } 55 : else 56 : { 57 390 : aosPathComponents[m_nPathLength].assign(pszElement); 58 390 : osPath.append(pszElement); 59 : } 60 : } 61 : else 62 : { 63 1608 : aosPathComponents.push_back(pszElement); 64 1608 : osPath.append(pszElement); 65 : } 66 17484 : m_nPathLength++; 67 17484 : } 68 : 69 : /************************************************************************/ 70 : /* PopPath() */ 71 : /************************************************************************/ 72 : 73 17396 : void GMLReadState::PopPath() 74 : 75 : { 76 17396 : CPLAssert(m_nPathLength > 0); 77 : 78 34792 : osPath.resize(osPath.size() - (aosPathComponents[m_nPathLength - 1].size() + 79 17396 : ((m_nPathLength > 1) ? 1 : 0))); 80 17396 : m_nPathLength--; 81 17396 : }