GDAL
nasakeywordhandler.h
1 /******************************************************************************
2  *
3  * Project: PDS Driver; Planetary Data System Format
4  * Purpose: Implementation of NASAKeywordHandler - a class to read
5  * keyword data from PDS, ISIS2 and ISIS3 data products.
6  * Author: Frank Warmerdam <warmerdam@pobox.com
7  *
8  ******************************************************************************
9  * Copyright (c) 2006, Frank Warmerdam <warmerdam@pobox.com>
10  * Copyright (c) 2008-2010, Even Rouault <even dot rouault at spatialys.com>
11  * Copyright (c) 2017 Hobu Inc
12  * Copyright (c) 2017, Dmitry Baryshnikov <polimax@mail.ru>
13  * Copyright (c) 2017, NextGIS <info@nextgis.com>
14  *
15  * Permission is hereby granted, free of charge, to any person obtaining a
16  * copy of this software and associated documentation files (the "Software"),
17  * to deal in the Software without restriction, including without limitation
18  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
19  * and/or sell copies of the Software, and to permit persons to whom the
20  * Software is furnished to do so, subject to the following conditions:
21  *
22  * The above copyright notice and this permission notice shall be included
23  * in all copies or substantial portions of the Software.
24  *
25  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
26  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
28  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
30  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
31  * DEALINGS IN THE SOFTWARE.
32  ****************************************************************************/
33 
34 #ifndef NASAKEYWORDHANDLER_H
35 #define NASAKEYWORDHANDLER_H
36 
38 
39 #include "cpl_json.h"
40 #include "cpl_string.h"
41 
42 /************************************************************************/
43 /* ==================================================================== */
44 /* NASAKeywordHandler */
45 /* ==================================================================== */
46 /************************************************************************/
47 
48 // Only exported for HDF4 plugin needs. Do not use outside of GDAL please.
49 
50 class CPL_DLL NASAKeywordHandler
51 {
52  CPLStringList aosKeywordList{};
53 
54  const char *pszHeaderNext = nullptr;
55 
56  CPLJSONObject oJSon{};
57 
58  bool m_bStripSurroundingQuotes = false;
59 
60  void SkipWhite();
61  bool ReadWord(CPLString &osWord, bool bStripSurroundingQuotes = false,
62  bool bParseList = false, bool *pbIsString = nullptr);
63  bool ReadPair(CPLString &osName, CPLString &osValue, CPLJSONObject &oCur);
64  bool ReadGroup(const std::string &osPathPrefix, CPLJSONObject &oCur,
65  int nRecLevel);
66 
67  NASAKeywordHandler(const NASAKeywordHandler &) = delete;
68  NASAKeywordHandler &operator=(const NASAKeywordHandler &) = delete;
69 
70  public:
71  NASAKeywordHandler();
72  ~NASAKeywordHandler();
73 
74  void SetStripSurroundingQuotes(bool bStripSurroundingQuotes)
75  {
76  m_bStripSurroundingQuotes = bStripSurroundingQuotes;
77  }
78 
79  bool Ingest(VSILFILE *fp, int nOffset);
80  bool Parse(const char *pszStr);
81 
82  const char *GetKeyword(const char *pszPath, const char *pszDefault);
83  char **GetKeywordList();
84  CPLJSONObject GetJsonObject() const;
85 };
86 
88 
89 #endif // NASAKEYWORDHANDLER_H
The CPLJSONArray class holds JSON object from CPLJSONDocument.
Definition: cpl_json.h:57
String list class designed around our use of C "char**" string lists.
Definition: cpl_string.h:449
Convenient string class based on std::string.
Definition: cpl_string.h:320
Interface for read and write JSON documents.
Various convenience functions for working with strings and string lists.
Virtual file handle.
Definition: cpl_vsi_virtual.h:63