LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/sosi - ogrsosidatatypes.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 59 82 72.0 %
Date: 2024-05-14 23:54:21 Functions: 13 17 76.5 %

          Line data    Source code
       1             : #include <map>
       2             : #include "ogr_sosi.h"
       3             : 
       4             : C2F *poTypes = nullptr;
       5             : 
       6             : /*** class definitions ***/
       7             : 
       8        1481 : OGRSOSIDataType::OGRSOSIDataType(int nSize)
       9        3271 :     : poElements(new OGRSOSISimpleDataType[nSize]), nElementCount(nSize)
      10             : {
      11        1481 : }
      12             : 
      13        5924 : OGRSOSIDataType::~OGRSOSIDataType()
      14             : {
      15        4752 :     delete[] poElements;
      16        2962 : }
      17             : 
      18        1781 : void OGRSOSIDataType::setElement(int nIndex, const char *name,
      19             :                                  OGRFieldType type)
      20             : {
      21        1781 :     poElements[nIndex].setType(name, type);
      22        1781 : }
      23             : 
      24        3580 : OGRSOSISimpleDataType::OGRSOSISimpleDataType() : osName(), nType(OFTString)
      25             : {
      26        3580 : }
      27             : 
      28           0 : OGRSOSISimpleDataType::OGRSOSISimpleDataType(const char *name,
      29           0 :                                              OGRFieldType type)
      30             : {
      31           0 :     setType(name, type);
      32           0 : }
      33             : 
      34        1781 : void OGRSOSISimpleDataType::setType(const char *name, OGRFieldType type)
      35             : {
      36        1781 :     osName = name;
      37        1781 :     nType = type;
      38        1781 : }
      39             : 
      40        1790 : OGRSOSISimpleDataType::~OGRSOSISimpleDataType()
      41             : {
      42        1790 : }
      43             : 
      44             : /*** utility methods ***/
      45             : 
      46        1481 : static void addType(C2F *map, const char *key, OGRSOSIDataType *type)
      47             : {
      48        1481 :     map->insert(std::pair<CPLString, OGRSOSIDataType>(CPLString(key), *type));
      49        1481 : }
      50             : 
      51        1377 : static void addSimpleType(C2F *map, const char *key, const char *gmlKey,
      52             :                           OGRFieldType type)
      53             : {
      54        1377 :     OGRSOSIDataType *poType = new OGRSOSIDataType(1);
      55        1377 :     poType->setElement(0, gmlKey, type);
      56        1377 :     addType(map, key, poType);
      57        1377 :     delete poType;
      58        1377 : }
      59             : 
      60           1 : void SOSIInitTypes()
      61             : {
      62           1 :     CPLAssert(poTypes == nullptr);
      63           1 :     poTypes = new C2F();
      64             : #include "ogrsosidatatypes.h"
      65             : 
      66             :     /* Actually not headers */
      67           1 :     addSimpleType(poTypes, "PUNKT", "", OFTInteger);  // ignore
      68           1 :     addSimpleType(poTypes, "KURVE", "", OFTInteger);  // ignore
      69           1 :     addSimpleType(poTypes, "FLATE", "", OFTInteger);  // ignore
      70           1 :     addSimpleType(poTypes, "BUEP", "", OFTInteger);   // ignore
      71           1 :     addSimpleType(poTypes, "TEKST", "", OFTInteger);  // ignore
      72           1 :     addSimpleType(poTypes, "REF", "", OFTString);     // ignore this
      73           1 : }
      74             : 
      75           0 : void SOSICleanupTypes()
      76             : {
      77           0 :     delete poTypes;
      78           0 :     poTypes = nullptr;
      79           0 : }
      80             : 
      81          96 : int SOSITypeToInt(const char *value)
      82             : {
      83          96 :     return atoi(value);
      84             : }
      85             : 
      86           0 : double SOSITypeToReal(const char *value)
      87             : {
      88           0 :     return CPLAtof(value);
      89             : }
      90             : 
      91           0 : void SOSITypeToDate(const char *value, int *date)
      92             : {
      93             :     char dato[9];
      94           0 :     snprintf(dato, 9, "%s", value);
      95           0 :     date[2] = atoi(dato + 6);
      96           0 :     dato[6] = '\0';
      97           0 :     date[1] = atoi(dato + 4);
      98           0 :     dato[4] = '\0';
      99           0 :     date[0] = atoi(dato);
     100           0 : }
     101             : 
     102         117 : void SOSITypeToDateTime(const char *value, int *date)
     103             : {
     104             :     char dato[15];
     105         117 :     snprintf(dato, 15, "%s", value);
     106         117 :     if (strlen(dato) == 14)
     107             :     {
     108           0 :         date[5] = atoi(dato + 12);
     109           0 :         dato[12] = '\0';
     110           0 :         date[4] = atoi(dato + 10);
     111           0 :         dato[10] = '\0';
     112           0 :         date[3] = atoi(dato + 8);
     113             :     }
     114             :     else
     115             :     {
     116         117 :         date[3] = 0;
     117         117 :         date[4] = 0;
     118         117 :         date[5] = 0;
     119             :     }
     120         117 :     dato[8] = '\0';
     121         117 :     date[2] = atoi(dato + 6);
     122         117 :     dato[6] = '\0';
     123         117 :     date[1] = atoi(dato + 4);
     124         117 :     dato[4] = '\0';
     125         117 :     date[0] = atoi(dato);
     126         117 : }
     127             : 
     128           2 : static OGRSOSIDataType *SOSIGetTypeFallback(const CPLString &name)
     129             : {
     130           2 :     addSimpleType(poTypes, name.c_str(), name.c_str(), OFTString);
     131           2 :     return SOSIGetType(name);
     132             : }
     133             : 
     134         488 : OGRSOSIDataType *SOSIGetType(const CPLString &name)
     135             : {
     136         488 :     auto iTypes = poTypes->find(name);
     137         488 :     if (iTypes != poTypes->end())
     138             :     {
     139         486 :         return &(iTypes->second);
     140             :     }
     141             :     else
     142             :     {
     143           2 :         return SOSIGetTypeFallback(name);
     144             :     }
     145             : }

Generated by: LCOV version 1.14