• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

polserver / polserver / 25918451630

15 May 2026 12:43PM UTC coverage: 60.929% (+2.1%) from 58.859%
25918451630

push

github

turleypol
added dynamic property which returns a pointer of the object instead of
a copy like the current imp.
needed to be able to eg store a vector

43 of 61 new or added lines in 2 files covered. (70.49%)

14455 existing lines in 345 files now uncovered.

44695 of 73356 relevant lines covered (60.93%)

449621.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

60.0
/pol-core/clib/binaryfile.cpp
1
/** @file
2
 *
3
 * @par History
4
 * - 2009/08/25 Shinigami: STLport-5.2.1 fix: Error message in BinaryFile::Seek stripped little bit.
5
 * - 2009/09/01 MuadDib:   STLPort-5.x fix: BinaryFile::Seek requires casting to long in decint
6
 * under Win32
7
 */
8

9

10
#include "binaryfile.h"
11

12
#include <stdexcept>
13

14
#include "passert.h"
15
#include "strutil.h"
16

17

18
namespace Pol::Clib
19
{
UNCOV
20
BinaryFile::BinaryFile() = default;
×
21

22
BinaryFile::BinaryFile( const std::string& filename, std::ios::openmode mode ) : _filename( "" )
42✔
23
{
24
  Open( filename, mode );
42✔
25
}
42✔
26

27
BinaryFile::~BinaryFile() = default;
42✔
28

29
void BinaryFile::Open( const std::string& filename, std::ios::openmode mode )
42✔
30
{
31
  passert( !_file.is_open() );
42✔
32

33
  _filename = filename;
42✔
34

35
  _file.open( _filename.c_str(), mode | std::ios::binary );
42✔
36
  if ( !_file.is_open() )
42✔
UNCOV
37
    throw std::runtime_error( "BinaryFile::Open('" + _filename + ", " + hexint( mode ) +
×
38
                              ") failed." );
×
39
}
42✔
40

UNCOV
41
void BinaryFile::Close()
×
42
{
UNCOV
43
  passert( _file.is_open() );
×
44

UNCOV
45
  _file.close();
×
46
  _filename = "";
×
47
}
×
48

49
void BinaryFile::Seek( std::fstream::pos_type abs_offset )
8✔
50
{
51
  passert( _file.is_open() );
8✔
52

53
  if ( !_file.seekg( abs_offset, std::ios::beg ) )
8✔
UNCOV
54
    throw std::runtime_error( "BinaryFile::Seek('" + _filename + "') failed." );
×
55
}
8✔
56

57
void BinaryFile::ReadBuffer( void* buffer, std::streamsize length )
121,766✔
58
{
59
  if ( !_file.read( reinterpret_cast<char*>( buffer ), length ) )
121,766✔
UNCOV
60
    throw std::runtime_error( "BinaryFile::Read('" + _filename + "') failed to read " +
×
61
                              tostring( static_cast<int>( length ) ) + " bytes." );
×
62
}
121,766✔
63

64
std::fstream::pos_type BinaryFile::FileSize()
24✔
65
{
66
  passert( _file.is_open() );
24✔
67

68
  std::fstream::pos_type save_pos = _file.tellg();
24✔
69
  if ( save_pos == std::fstream::pos_type( -1 ) )
24✔
UNCOV
70
    throw std::runtime_error( "BinaryFile::FileSize('" + _filename +
×
71
                              "' failed to determine current position." );
×
72

73
  if ( !_file.seekg( 0, std::ios::end ) )
24✔
UNCOV
74
    throw std::runtime_error( "BinaryFile::FileSize('" + _filename +
×
75
                              "') failed to seek to end of file." );
×
76
  std::fstream::pos_type size = _file.tellg();
24✔
77
  if ( size == std::fstream::pos_type( -1 ) )
24✔
UNCOV
78
    throw std::runtime_error( "BinaryFile::FileSize('" + _filename +
×
79
                              "') could not determine file size." );
×
80

81
  if ( !_file.seekg( save_pos ) )
24✔
UNCOV
82
    throw std::runtime_error( "BinaryFile::FileSize('" + _filename +
×
83
                              "') failed to seek to original position." );
×
84

85
  return size;
24✔
86
}
87

88
size_t BinaryFile::GetElementCount( size_t elemsize )
18✔
89
{
90
  std::fstream::pos_type filesize = FileSize();
18✔
91
  if ( ( filesize % elemsize ) != 0 )
18✔
92
  {
UNCOV
93
    throw std::runtime_error( _filename +
×
94
                              " does not contain an integral number of elements of size " +
×
95
                              tostring( elemsize ) );
×
96
  }
97
  return static_cast<unsigned int>( filesize / elemsize );
18✔
98
}
99

100
size_t BinaryFile::sizeEstimate() const
2✔
101
{
102
  size_t size = sizeof( *this ) + _filename.capacity();
2✔
103
  return size;
2✔
104
}
105
}  // namespace Pol::Clib
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc