Coverage Report

Created: 2025-07-01 06:08

/src/logging-log4cxx/src/main/cpp/bytebuffer.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
#include <log4cxx/logstring.h>
18
#include <log4cxx/helpers/bytebuffer.h>
19
#include <log4cxx/helpers/exception.h>
20
#include <log4cxx/helpers/pool.h>
21
22
using namespace LOG4CXX_NS;
23
using namespace LOG4CXX_NS::helpers;
24
25
struct ByteBuffer::ByteBufferPriv
26
{
27
  ByteBufferPriv(char* data1, size_t capacity) :
28
1
    base(data1), pos(0), lim(capacity), cap(capacity) {}
29
30
  char* base;
31
  size_t pos;
32
  size_t lim;
33
  size_t cap;
34
};
35
36
ByteBuffer::ByteBuffer(char* data1, size_t capacity)
37
1
  : m_priv(std::make_unique<ByteBufferPriv>(data1, capacity))
38
1
{
39
1
}
40
41
ByteBuffer::~ByteBuffer()
42
1
{
43
1
}
44
45
void ByteBuffer::clear()
46
1
{
47
1
  m_priv->lim = m_priv->cap;
48
1
  m_priv->pos = 0;
49
1
}
50
51
void ByteBuffer::flip()
52
1
{
53
1
  m_priv->lim = m_priv->pos;
54
1
  m_priv->pos = 0;
55
1
}
56
57
void ByteBuffer::position(size_t newPosition)
58
2
{
59
2
  if (newPosition < m_priv->lim)
60
1
  {
61
1
    m_priv->pos = newPosition;
62
1
  }
63
1
  else
64
1
  {
65
1
    m_priv->pos = m_priv->lim;
66
1
  }
67
2
}
68
69
void ByteBuffer::limit(size_t newLimit)
70
0
{
71
0
  if (newLimit > m_priv->cap)
72
0
  {
73
0
    throw IllegalArgumentException(LOG4CXX_STR("newLimit"));
74
0
  }
75
76
0
  m_priv->lim = newLimit;
77
0
}
78
79
80
bool ByteBuffer::put(char byte)
81
0
{
82
0
  if (m_priv->pos < m_priv->lim)
83
0
  {
84
0
    m_priv->base[m_priv->pos++] = byte;
85
0
    return true;
86
0
  }
87
88
0
  return false;
89
0
}
90
91
char* ByteBuffer::data()
92
0
{
93
0
  return m_priv->base;
94
0
}
95
96
const char* ByteBuffer::data() const
97
0
{
98
0
  return m_priv->base;
99
0
}
100
101
char* ByteBuffer::current()
102
3
{
103
3
  return m_priv->base + m_priv->pos;
104
3
}
105
106
const char* ByteBuffer::current() const
107
0
{
108
0
  return m_priv->base + m_priv->pos;
109
0
}
110
111
size_t ByteBuffer::limit() const
112
1
{
113
1
  return m_priv->lim;
114
1
}
115
116
size_t ByteBuffer::position() const
117
1
{
118
1
  return m_priv->pos;
119
1
}
120
121
size_t ByteBuffer::remaining() const
122
5
{
123
5
  return m_priv->lim - m_priv->pos;
124
5
}
125