LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/hana - ogrhanafeaturewriter.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 23 26 88.5 %
Date: 2024-05-14 13:00:50 Functions: 9 11 81.8 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  SAP HANA Spatial Driver
       4             :  * Purpose:  OGRHanaFeatureWriter class declaration
       5             :  * Author:   Maxim Rylov
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2020, SAP SE
       9             :  *
      10             :  * Permission is hereby granted, free of charge, to any person obtaining a
      11             :  * copy of this software and associated documentation files (the "Software"),
      12             :  * to deal in the Software without restriction, including without limitation
      13             :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      14             :  * and/or sell copies of the Software, and to permit persons to whom the
      15             :  * Software is furnished to do so, subject to the following conditions:
      16             :  *
      17             :  * The above copyright notice and this permission notice shall be included
      18             :  * in all copies or substantial portions of the Software.
      19             :  *
      20             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      21             :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      22             :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      23             :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      24             :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      25             :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      26             :  * DEALINGS IN THE SOFTWARE.
      27             :  ****************************************************************************/
      28             : 
      29             : #ifndef OGRHANAFEATUREWRITER_H_INCLUDED
      30             : #define OGRHANAFEATUREWRITER_H_INCLUDED
      31             : 
      32             : #include "gdal_priv.h"
      33             : #include "odbc/Types.h"
      34             : 
      35             : namespace OGRHANA
      36             : {
      37             : 
      38             : class OGRHanaFeatureWriter
      39             : {
      40             :   public:
      41             :     explicit OGRHanaFeatureWriter(OGRFeature &feature);
      42             : 
      43             :     template <typename T>
      44             :     void SetFieldValue(int fieldIndex, const odbc::Nullable<T> &value);
      45             : 
      46             :     void SetFieldValue(int fieldIndex, const odbc::Long &value);
      47             :     void SetFieldValue(int fieldIndex, const odbc::Float &value);
      48             :     void SetFieldValue(int fieldIndex, const odbc::Decimal &value);
      49             :     void SetFieldValue(int fieldIndex, const odbc::String &value);
      50             :     void SetFieldValue(int fieldIndex, const odbc::Date &value);
      51             :     void SetFieldValue(int fieldIndex, const odbc::Time &value);
      52             :     void SetFieldValue(int fieldIndex, const odbc::Timestamp &value);
      53             :     void SetFieldValue(int fieldIndex, const odbc::Binary &value);
      54             :     void SetFieldValue(int fieldIndex, const char *value);
      55             :     void SetFieldValue(int fieldIndex, const void *value, std::size_t size);
      56             : 
      57             :     template <typename InputT, typename ResultT>
      58             :     void SetFieldValueAsArray(int fieldIndex, const odbc::Binary &value);
      59             :     void SetFieldValueAsStringArray(int fieldIndex, const odbc::Binary &value);
      60             : 
      61             :   private:
      62             :     OGRFeature &feature_;
      63             : };
      64             : 
      65             : template <typename T>
      66         522 : void OGRHanaFeatureWriter::SetFieldValue(int fieldIndex,
      67             :                                          const odbc::Nullable<T> &value)
      68             : {
      69         522 :     if (value.isNull())
      70          14 :         feature_.SetFieldNull(fieldIndex);
      71             :     else
      72         508 :         feature_.SetField(fieldIndex, *value);
      73         522 : }
      74             : 
      75             : template <typename InputT, typename ResultT>
      76           8 : void OGRHanaFeatureWriter::SetFieldValueAsArray(int fieldIndex,
      77             :                                                 const odbc::Binary &value)
      78             : {
      79           8 :     if (value.isNull() || value->size() == 0)
      80             :     {
      81           0 :         feature_.SetFieldNull(fieldIndex);
      82           0 :         return;
      83             :     }
      84             : 
      85           8 :     const uint8_t *ptr = reinterpret_cast<const uint8_t *>(value->data());
      86           8 :     const uint32_t numElements = *reinterpret_cast<const uint32_t *>(ptr);
      87           8 :     ptr += sizeof(uint32_t);
      88             : 
      89          16 :     std::vector<ResultT> values;
      90           8 :     values.reserve(numElements);
      91             : 
      92           8 :     bool elemHasLength =
      93           8 :         numElements * sizeof(InputT) != (value->size() - sizeof(uint32_t));
      94             : 
      95          24 :     for (uint32_t i = 0; i < numElements; ++i)
      96             :     {
      97          16 :         if (elemHasLength)
      98             :         {
      99          11 :             uint8_t len = *ptr;
     100          11 :             ++ptr;
     101             : 
     102          11 :             if (len > 0)
     103          11 :                 values.push_back(*reinterpret_cast<const InputT *>(ptr));
     104             :             else
     105           0 :                 values.push_back(ResultT());
     106             :         }
     107             :         else
     108           5 :             values.push_back(*reinterpret_cast<const InputT *>(ptr));
     109             : 
     110          16 :         ptr += sizeof(InputT);
     111             :     }
     112             : 
     113           8 :     feature_.SetField(fieldIndex, static_cast<int32_t>(values.size()),
     114             :                       values.data());
     115             : }
     116             : 
     117             : }  // namespace OGRHANA
     118             : 
     119             : #endif  // OGRHANAFEATUREWRITER_H_INCLUDED

Generated by: LCOV version 1.14