Coverage Report

Created: 2026-04-29 07:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libqxp/src/lib/QXPMemoryStream.cpp
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/*
3
 * This file is part of the libqxp project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 */
9
10
#include "QXPMemoryStream.h"
11
12
#include <algorithm>
13
14
namespace libqxp
15
{
16
17
QXPMemoryStream::QXPMemoryStream(const unsigned char *data, unsigned length)
18
48.2k
  : m_data()
19
48.2k
  , m_length((long) length)
20
48.2k
  , m_pos(0)
21
48.2k
{
22
48.2k
  if (length > 0)
23
31.8k
  {
24
31.8k
    m_data.reset(new unsigned char[length]);
25
31.8k
    std::copy(data, data + length, m_data.get());
26
31.8k
  }
27
48.2k
}
28
29
QXPMemoryStream::~QXPMemoryStream()
30
48.2k
{
31
48.2k
}
32
33
bool QXPMemoryStream::isStructured()
34
0
{
35
0
  return false;
36
0
}
37
38
unsigned QXPMemoryStream::subStreamCount()
39
0
{
40
0
  return 0;
41
0
}
42
43
const char *QXPMemoryStream::subStreamName(unsigned)
44
0
{
45
0
  return 0;
46
0
}
47
48
bool QXPMemoryStream::existsSubStream(const char *)
49
0
{
50
0
  return false;
51
0
}
52
53
librevenge::RVNGInputStream *QXPMemoryStream::getSubStreamByName(const char *)
54
0
{
55
0
  return 0;
56
0
}
57
58
librevenge::RVNGInputStream *QXPMemoryStream::getSubStreamById(unsigned)
59
0
{
60
0
  return 0;
61
0
}
62
63
37.6M
const unsigned char *QXPMemoryStream::read(unsigned long numBytes, unsigned long &numBytesRead) try
64
37.6M
{
65
37.6M
  numBytesRead = 0;
66
67
37.6M
  if ((0 == numBytes) || (0 == m_length))
68
489
    return 0;
69
70
37.6M
  if ((static_cast<unsigned long>(m_pos) + numBytes) >= static_cast<unsigned long>(m_length))
71
6.78k
    numBytes = static_cast<unsigned long>(m_length - m_pos);
72
73
37.6M
  const long oldPos = m_pos;
74
37.6M
  m_pos += numBytes;
75
76
37.6M
  numBytesRead = numBytes;
77
37.6M
  return m_data.get() + oldPos;
78
37.6M
}
79
37.6M
catch (...)
80
37.6M
{
81
0
  return 0;
82
0
}
83
84
3.91M
int QXPMemoryStream::seek(const long offset, librevenge::RVNG_SEEK_TYPE seekType) try
85
3.91M
{
86
3.91M
  long pos = 0;
87
3.91M
  switch (seekType)
88
3.91M
  {
89
361k
  case librevenge::RVNG_SEEK_SET :
90
361k
    pos = offset;
91
361k
    break;
92
3.28M
  case librevenge::RVNG_SEEK_CUR :
93
3.28M
    pos = offset + m_pos;
94
3.28M
    break;
95
271k
  case librevenge::RVNG_SEEK_END :
96
271k
    pos = offset + m_length;
97
271k
    break;
98
0
  default :
99
0
    return -1;
100
3.91M
  }
101
102
3.91M
  if ((pos < 0) || (pos > m_length))
103
3.91k
    return 1;
104
105
3.91M
  m_pos = pos;
106
3.91M
  return 0;
107
3.91M
}
108
3.91M
catch (...)
109
3.91M
{
110
0
  return -1;
111
0
}
112
113
long QXPMemoryStream::tell()
114
6.59M
{
115
6.59M
  return m_pos;
116
6.59M
}
117
118
bool QXPMemoryStream::isEnd()
119
43.7M
{
120
43.7M
  return m_length == m_pos;
121
43.7M
}
122
123
}
124
125
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */