LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/cad/libopencad - cadfilestreamio.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 0 44 0.0 %
Date: 2024-05-03 15:49:35 Functions: 0 12 0.0 %

          Line data    Source code
       1             : /*******************************************************************************
       2             :  *  Project: libopencad
       3             :  *  Purpose: OpenSource CAD formats support library
       4             :  *  Author: Alexandr Borzykh, mush3d at gmail.com
       5             :  *  Author: Dmitry Baryshnikov, bishop.dev@gmail.com
       6             :  *  Language: C++
       7             :  *******************************************************************************
       8             :  *  The MIT License (MIT)
       9             :  *
      10             :  *  Copyright (c) 2016 Alexandr Borzykh
      11             :  *  Copyright (c) 2016-2019 NextGIS, <info@nextgis.com>
      12             :  *
      13             :  *  Permission is hereby granted, free of charge, to any person obtaining a copy
      14             :  *  of this software and associated documentation files (the "Software"), to deal
      15             :  *  in the Software without restriction, including without limitation the rights
      16             :  *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      17             :  *  copies of the Software, and to permit persons to whom the Software is
      18             :  *  furnished to do so, subject to the following conditions:
      19             :  *
      20             :  *  The above copyright notice and this permission notice shall be included in all
      21             :  *  copies or substantial portions of the Software.
      22             :  *
      23             :  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      24             :  *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      25             :  *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      26             :  *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      27             :  *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      28             :  *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
      29             :  *  SOFTWARE.
      30             : *******************************************************************************/
      31             : #include "cadfilestreamio.h"
      32             : 
      33           0 : CADFileStreamIO::CADFileStreamIO( const char * pszFilePath ) : CADFileIO( pszFilePath )
      34             : {
      35           0 : }
      36             : 
      37           0 : CADFileStreamIO::~CADFileStreamIO()
      38             : {
      39           0 :     if( CADFileStreamIO::IsOpened() )
      40           0 :         CADFileStreamIO::Close();
      41           0 : }
      42             : 
      43           0 : const char * CADFileStreamIO::ReadLine()
      44             : {
      45             :     // TODO: getline
      46           0 :     return nullptr;
      47             : }
      48             : 
      49           0 : bool CADFileStreamIO::Eof() const
      50             : {
      51           0 :     return m_oFileStream.eof();
      52             : }
      53             : 
      54           0 : bool CADFileStreamIO::Open( int mode )
      55             : {
      56           0 :     auto io_mode = std::ifstream::in; // As we use ifstream
      57           0 :     if( mode & OpenMode::binary )
      58           0 :         io_mode = std::ifstream::binary; // In set by default
      59             : 
      60           0 :     if( mode & OpenMode::out )
      61             :         //io_mode |= std::ifstream::out;
      62           0 :         return false;
      63             : 
      64           0 :     m_oFileStream.open( m_soFilePath, io_mode );
      65             : 
      66           0 :     if( m_oFileStream.is_open() )
      67           0 :         m_bIsOpened = true;
      68             : 
      69           0 :     return m_bIsOpened;
      70             : }
      71             : 
      72           0 : bool CADFileStreamIO::Close()
      73             : {
      74           0 :     m_oFileStream.close();
      75           0 :     return CADFileIO::Close();
      76             : }
      77             : 
      78           0 : int CADFileStreamIO::Seek( long offset, CADFileIO::SeekOrigin origin )
      79             : {
      80             :     std::ios_base::seekdir direction;
      81           0 :     switch( origin )
      82             :     {
      83           0 :         case SeekOrigin::CUR:
      84           0 :             direction = std::ios_base::cur;
      85           0 :             break;
      86           0 :         case SeekOrigin::END:
      87           0 :             direction = std::ios_base::end;
      88           0 :             break;
      89           0 :         default:
      90             :         case SeekOrigin::BEG:
      91           0 :             direction = std::ios_base::beg;
      92           0 :             break;
      93             :     }
      94             : 
      95           0 :     return m_oFileStream.seekg( offset, direction ).good() ? 0 : 1;
      96             : }
      97             : 
      98           0 : long int CADFileStreamIO::Tell()
      99             : {
     100             :     // FIXME? cast may cause potential issue on 32bit / Windows for large files
     101           0 :     return static_cast<long>(m_oFileStream.tellg());
     102             : }
     103             : 
     104           0 : size_t CADFileStreamIO::Read( void * ptr, size_t size )
     105             : {
     106           0 :     return static_cast<size_t>(m_oFileStream.read( static_cast<char *>(ptr), static_cast<long>(size) ).gcount());
     107             : }
     108             : 
     109           0 : size_t CADFileStreamIO::Write( void * /*ptr*/, size_t /*size*/ )
     110             : {
     111             :     // unsupported
     112           0 :     return 0;
     113             : }
     114             : 
     115           0 : void CADFileStreamIO::Rewind()
     116             : {
     117           0 :     m_oFileStream.seekg( 0, std::ios_base::beg );
     118           0 : }

Generated by: LCOV version 1.14