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: 2024-11-21 22:18:42 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             : /************************************************************************/
      23             : /*                        OGRArrowWritableFile                          */
      24             : /************************************************************************/
      25             : 
      26             : class OGRArrowWritableFile final : public arrow::io::OutputStream
      27             : {
      28             :     VSILFILE *m_fp;
      29             : 
      30             :     OGRArrowWritableFile(const OGRArrowWritableFile &) = delete;
      31             :     OGRArrowWritableFile &operator=(const OGRArrowWritableFile &) = delete;
      32             : 
      33             :   public:
      34         413 :     explicit OGRArrowWritableFile(VSILFILE *fp) : m_fp(fp)
      35             :     {
      36         413 :     }
      37             : 
      38         413 :     ~OGRArrowWritableFile() override
      39         413 :     {
      40         413 :         if (m_fp)
      41         413 :             VSIFCloseL(m_fp);
      42         413 :     }
      43             : 
      44           0 :     arrow::Status Close() override
      45             :     {
      46           0 :         int ret = VSIFCloseL(m_fp);
      47           0 :         m_fp = nullptr;
      48             :         return ret == 0 ? arrow::Status::OK()
      49           0 :                         : arrow::Status::IOError("Error while closing");
      50             :     }
      51             : 
      52        5956 :     arrow::Result<int64_t> Tell() const override
      53             :     {
      54        5956 :         return static_cast<int64_t>(VSIFTellL(m_fp));
      55             :     }
      56             : 
      57           0 :     bool closed() const override
      58             :     {
      59           0 :         return m_fp == nullptr;
      60             :     }
      61             : 
      62       17270 :     arrow::Status Write(const void *data, int64_t nbytes) override
      63             :     {
      64             :         CPLAssert(static_cast<int64_t>(static_cast<size_t>(nbytes)) == nbytes);
      65       17270 :         if (VSIFWriteL(data, 1, static_cast<size_t>(nbytes), m_fp) ==
      66       17270 :             static_cast<size_t>(nbytes))
      67       17270 :             return arrow::Status::OK();
      68           0 :         return arrow::Status::IOError("Error while writing");
      69             :     }
      70             : 
      71        4928 :     arrow::Status Write(const std::shared_ptr<arrow::Buffer> &data) override
      72             :     {
      73        4928 :         return Write(data->data(), data->size());
      74             :     }
      75             : };
      76             : 
      77             : #endif  // OGR_ARROW_WRITABLE_FILE_H

Generated by: LCOV version 1.14