Coverage Report

Created: 2026-02-14 09:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gdal/ogr/ogrsf_frmts/cad/libopencad/cadfilestreamio.cpp
Line
Count
Source
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
  * SPDX-License-Identifier: MIT
14
*******************************************************************************/
15
#include "cadfilestreamio.h"
16
17
0
CADFileStreamIO::CADFileStreamIO( const char * pszFilePath ) : CADFileIO( pszFilePath )
18
0
{
19
0
}
20
21
CADFileStreamIO::~CADFileStreamIO()
22
0
{
23
0
    if( CADFileStreamIO::IsOpened() )
24
0
        CADFileStreamIO::Close();
25
0
}
26
27
const char * CADFileStreamIO::ReadLine()
28
0
{
29
    // TODO: getline
30
0
    return nullptr;
31
0
}
32
33
bool CADFileStreamIO::Eof() const
34
0
{
35
0
    return m_oFileStream.eof();
36
0
}
37
38
bool CADFileStreamIO::Open( int mode )
39
0
{
40
0
    auto io_mode = std::ifstream::in; // As we use ifstream
41
0
    if( mode & OpenMode::binary )
42
0
        io_mode = std::ifstream::binary; // In set by default
43
44
0
    if( mode & OpenMode::out )
45
        //io_mode |= std::ifstream::out;
46
0
        return false;
47
48
0
    m_oFileStream.open( m_soFilePath, io_mode );
49
50
0
    if( m_oFileStream.is_open() )
51
0
        m_bIsOpened = true;
52
53
0
    return m_bIsOpened;
54
0
}
55
56
bool CADFileStreamIO::Close()
57
0
{
58
0
    m_oFileStream.close();
59
0
    return CADFileIO::Close();
60
0
}
61
62
int CADFileStreamIO::Seek( long offset, CADFileIO::SeekOrigin origin )
63
0
{
64
0
    std::ios_base::seekdir direction;
65
0
    switch( origin )
66
0
    {
67
0
        case SeekOrigin::CUR:
68
0
            direction = std::ios_base::cur;
69
0
            break;
70
0
        case SeekOrigin::END:
71
0
            direction = std::ios_base::end;
72
0
            break;
73
0
        default:
74
0
        case SeekOrigin::BEG:
75
0
            direction = std::ios_base::beg;
76
0
            break;
77
0
    }
78
79
0
    return m_oFileStream.seekg( offset, direction ).good() ? 0 : 1;
80
0
}
81
82
long int CADFileStreamIO::Tell()
83
0
{
84
    // FIXME? cast may cause potential issue on 32bit / Windows for large files
85
0
    return static_cast<long>(m_oFileStream.tellg());
86
0
}
87
88
size_t CADFileStreamIO::Read( void * ptr, size_t size )
89
0
{
90
0
    return static_cast<size_t>(m_oFileStream.read( static_cast<char *>(ptr), static_cast<long>(size) ).gcount());
91
0
}
92
93
size_t CADFileStreamIO::Write( void * /*ptr*/, size_t /*size*/ )
94
0
{
95
    // unsupported
96
0
    return 0;
97
0
}
98
99
void CADFileStreamIO::Rewind()
100
0
{
101
0
    m_oFileStream.seekg( 0, std::ios_base::beg );
102
0
}