Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: S-101 driver 4 : * Purpose: Header file for OGRS101FeatureCatalog 5 : * Author: Even Rouault <even dot rouault at spatialys.com> 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2026, Even Rouault <even dot rouault at spatialys.com> 9 : * 10 : * SPDX-License-Identifier: MIT 11 : ****************************************************************************/ 12 : 13 : #ifndef OGR_S101_FEATURE_CATALOG_H_INCLUDED 14 : #define OGR_S101_FEATURE_CATALOG_H_INCLUDED 15 : 16 : struct CPLXMLNode; 17 : 18 : #include <map> 19 : #include <set> 20 : #include <string> 21 : #include <utility> 22 : 23 : namespace OGRS101FeatureCatalogTypes 24 : { 25 : struct SimpleAttribute 26 : { 27 : std::string code{}; // short string 28 : std::string name{}; // longer string 29 : std::string type{}; 30 : std::map<int, std::string> enumeratedValues{}; 31 : }; 32 : 33 : struct ComplexAttribute 34 : { 35 : std::string code{}; // short string 36 : std::string name{}; // longer string 37 : std::set<std::string> attributeBindings{}; 38 : }; 39 : 40 : struct InformationType 41 : { 42 : std::string code{}; // short string 43 : std::string name{}; // longer string 44 : std::string definition{}; 45 : std::string alias{}; 46 : std::set<std::string> attributeBindings{}; 47 : }; 48 : 49 : struct FeatureType 50 : { 51 : std::string code{}; // short string 52 : std::string name{}; // longer string 53 : std::string definition{}; 54 : std::string alias{}; 55 : std::set<std::string> attributeBindings{}; 56 : std::set<std::string> permittedPrimitives{}; 57 : }; 58 : } // namespace OGRS101FeatureCatalogTypes 59 : 60 : /************************************************************************/ 61 : /* OGRS101FeatureCatalog */ 62 : /************************************************************************/ 63 : 64 : class OGRS101FeatureCatalog 65 : { 66 : public: 67 : using SimpleAttribute = OGRS101FeatureCatalogTypes::SimpleAttribute; 68 : using ComplexAttribute = OGRS101FeatureCatalogTypes::ComplexAttribute; 69 : using InformationType = OGRS101FeatureCatalogTypes::InformationType; 70 : using FeatureType = OGRS101FeatureCatalogTypes::FeatureType; 71 : 72 : // Valid values for <permittedPrimitives> element of <S100_FC_FeatureType> 73 : static constexpr const char *PERMITTED_PRIMITIVE_NO_GEOMETRY = "noGeometry"; 74 : static constexpr const char *PERMITTED_PRIMITIVE_POINT = "point"; 75 : static constexpr const char *PERMITTED_PRIMITIVE_POINTSET = "pointSet"; 76 : static constexpr const char *PERMITTED_PRIMITIVE_CURVE = "curve"; 77 : static constexpr const char *PERMITTED_PRIMITIVE_SURFACE = "surface"; 78 : 79 : // Valid values for <valueType> element of <S100_FC_SimpleAttribute> 80 : static constexpr const char *VALUE_TYPE_BOOLEAN = "boolean"; 81 : static constexpr const char *VALUE_TYPE_ENUMERATION = "enumeration"; 82 : static constexpr const char *VALUE_TYPE_INTEGER = "integer"; 83 : static constexpr const char *VALUE_TYPE_REAL = "real"; 84 : static constexpr const char *VALUE_TYPE_TRUNCATED_DATE = 85 : "S100_TruncatedDate"; 86 : static constexpr const char *VALUE_TYPE_TEXT = "text"; 87 : static constexpr const char *VALUE_TYPE_TIME = "time"; 88 : static constexpr const char *VALUE_TYPE_URI = "URI"; 89 : static constexpr const char *VALUE_TYPE_URN = "URN"; 90 : 91 : explicit OGRS101FeatureCatalog(bool bStrict); 92 : 93 : static void CleanupSingletonFeatureCatalog(); 94 : 95 : enum class LoadingStatus 96 : { 97 : UNINIT, 98 : OK, 99 : SKIPPED, 100 : ERROR 101 : }; 102 : 103 : static std::pair<LoadingStatus, const OGRS101FeatureCatalog *> 104 : GetSingletonFeatureCatalog(bool bStrict); 105 : 106 : std::string GetFilename(bool &bError) const; 107 : 108 : LoadingStatus Load(); 109 : 110 : /* Return a map from the code of a simple attribute to its definition */ 111 407 : const std::map<std::string, SimpleAttribute> &GetSimpleAttributes() const 112 : { 113 407 : return m_simpleAttributes; 114 : } 115 : 116 : /* Return a map from the code of a complex attribute to its definition */ 117 : const std::map<std::string, ComplexAttribute> &GetComplexAttributes() const 118 : { 119 : return m_complexAttributes; 120 : } 121 : 122 : /* Return a map from the code of an information type to its definition */ 123 : const std::map<std::string, InformationType> &GetInformationTypes() const 124 : { 125 : return m_informationTypes; 126 : } 127 : 128 : /* Return a map from the code of a feature type to its definition */ 129 566 : const std::map<std::string, FeatureType> &GetFeatureTypes() const 130 : { 131 566 : return m_featureTypes; 132 : } 133 : 134 : private: 135 : const bool m_bStrict; 136 : 137 : std::map<std::string, SimpleAttribute> m_simpleAttributes{}; 138 : std::map<std::string, ComplexAttribute> m_complexAttributes{}; 139 : std::map<std::string, InformationType> m_informationTypes{}; 140 : std::map<std::string, FeatureType> m_featureTypes{}; 141 : 142 : static bool EmitErrorOrWarning(const char *pszFile, const char *pszFunc, 143 : int nLine, const char *pszMsg, bool bError, 144 : bool bRecoverable); 145 : 146 : bool LoadSimpleAttributes(const char *pszFC, const CPLXMLNode *psRoot); 147 : bool LoadComplexAttributes(const char *pszFC, const CPLXMLNode *psRoot); 148 : bool LoadInformationTypes(const char *pszFC, const CPLXMLNode *psRoot); 149 : bool LoadFeatureTypes(const char *pszFC, const CPLXMLNode *psRoot); 150 : }; 151 : 152 : #endif // OGR_S101_FEATURE_CATALOG_H_INCLUDED