LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/arrow_common - ograrrowwritablefile.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 15 22 68.2 %
Date: 2025-07-08 21:33:46 Functions: 5 8 62.5 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  Arrow generic code
       4             :  * Purpose:  Arrow generic code
       5             :  * Author:   Even Rouault, <even.rouault at spatialys.com>
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2022, Planet Labs
       9             :  *
      10             :  * SPDX-License-Identifier: MIT
      11             :  ****************************************************************************/
      12             : 
      13             : #ifndef OGR_ARROW_WRITABLE_FILE_H
      14             : #define OGR_ARROW_WRITABLE_FILE_H
      15             : 
      16             : #include "cpl_vsi.h"
      17             : 
      18             : #include "arrow/buffer.h"
      19             : #include "arrow/io/file.h"
      20             : #include "arrow/io/interfaces.h"
      21             : 
      22             : #if defined(__clang__)
      23             : #pragma clang diagnostic push
      24             : #pragma clang diagnostic ignored "-Wweak-vtables"
      25             : #endif
      26             : 
      27             : /************************************************************************/
      28             : /*                        OGRArrowWritableFile                          */
      29             : /************************************************************************/
      30             : 
      31             : class OGRArrowWritableFile final : public arrow::io::OutputStream
      32             : {
      33             :     VSILFILE *m_fp;
      34             : 
      35             :     OGRArrowWritableFile(const OGRArrowWritableFile &) = delete;
      36             :     OGRArrowWritableFile &operator=(const OGRArrowWritableFile &) = delete;
      37             : 
      38             :   public:
      39         420 :     explicit OGRArrowWritableFile(VSILFILE *fp) : m_fp(fp)
      40             :     {
      41         420 :     }
      42             : 
      43         420 :     ~OGRArrowWritableFile() override
      44         420 :     {
      45         420 :         if (m_fp)
      46         420 :             VSIFCloseL(m_fp);
      47         420 :     }
      48             : 
      49           0 :     arrow::Status Close() override
      50             :     {
      51           0 :         int ret = VSIFCloseL(m_fp);
      52           0 :         m_fp = nullptr;
      53             :         return ret == 0 ? arrow::Status::OK()
      54           0 :                         : arrow::Status::IOError("Error while closing");
      55             :     }
      56             : 
      57       17401 :     arrow::Result<int64_t> Tell() const override
      58             :     {
      59       17401 :         return static_cast<int64_t>(VSIFTellL(m_fp));
      60             :     }
      61             : 
      62           0 :     bool closed() const override
      63             :     {
      64           0 :         return m_fp == nullptr;
      65             :     }
      66             : 
      67       22778 :     arrow::Status Write(const void *data, int64_t nbytes) override
      68             :     {
      69             :         CPLAssert(static_cast<int64_t>(static_cast<size_t>(nbytes)) == nbytes);
      70       22778 :         if (VSIFWriteL(data, 1, static_cast<size_t>(nbytes), m_fp) ==
      71       22778 :             static_cast<size_t>(nbytes))
      72       22778 :             return arrow::Status::OK();
      73           0 :         return arrow::Status::IOError("Error while writing");
      74             :     }
      75             : 
      76        4928 :     arrow::Status Write(const std::shared_ptr<arrow::Buffer> &data) override
      77             :     {
      78        4928 :         return Write(data->data(), data->size());
      79             :     }
      80             : };
      81             : 
      82             : #if defined(__clang__)
      83             : #pragma clang diagnostic pop
      84             : #endif
      85             : 
      86             : #endif  // OGR_ARROW_WRITABLE_FILE_H

Generated by: LCOV version 1.14