You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rm...@apache.org on 2021/11/06 00:43:08 UTC
[logging-log4cxx] 03/20: More conversion to be ABI stable
This is an automated email from the ASF dual-hosted git repository.
rmiddleton pushed a commit to branch LOGCXX-510
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git
commit ad105501194409cae5a1c3ff8a19d620baca675a
Author: Robert Middleton <ro...@rm5248.com>
AuthorDate: Sat Sep 25 19:26:29 2021 -0400
More conversion to be ABI stable
---
src/main/cpp/bufferedwriter.cpp | 35 ++++---
src/main/cpp/bytearrayinputstream.cpp | 19 +++-
src/main/cpp/bytearrayoutputstream.cpp | 12 ++-
src/main/cpp/bytebuffer.cpp | 70 +++++++++++---
src/main/cpp/cacheddateformat.cpp | 99 ++++++++++++++------
src/main/cpp/cyclicbuffer.cpp | 76 +++++++++------
src/main/cpp/datagrampacket.cpp | 99 +++++++++++++++++++-
src/main/cpp/datagramsocket.cpp | 103 +++++++++++++++++----
src/main/include/log4cxx/helpers/bufferedwriter.h | 7 +-
.../include/log4cxx/helpers/bytearrayinputstream.h | 4 +-
.../log4cxx/helpers/bytearrayoutputstream.h | 3 +-
src/main/include/log4cxx/helpers/bytebuffer.h | 41 ++------
.../include/log4cxx/helpers/cacheddateformat.h | 37 +-------
src/main/include/log4cxx/helpers/cyclicbuffer.h | 19 ++--
src/main/include/log4cxx/helpers/datagrampacket.h | 72 +++-----------
src/main/include/log4cxx/helpers/datagramsocket.h | 54 ++---------
src/main/include/log4cxx/spi/configurator.h | 4 +-
17 files changed, 451 insertions(+), 303 deletions(-)
diff --git a/src/main/cpp/bufferedwriter.cpp b/src/main/cpp/bufferedwriter.cpp
index 5d21a9b..2175959 100644
--- a/src/main/cpp/bufferedwriter.cpp
+++ b/src/main/cpp/bufferedwriter.cpp
@@ -21,15 +21,26 @@
using namespace log4cxx;
using namespace log4cxx::helpers;
+struct BufferedWriter::BufferedWriterPriv {
+ BufferedWriterPriv(WriterPtr& out1, size_t sz1) :
+ out(out1),
+ sz(sz1)
+ {}
+
+ WriterPtr out;
+ size_t sz;
+ LogString buf;
+};
+
IMPLEMENT_LOG4CXX_OBJECT(BufferedWriter)
BufferedWriter::BufferedWriter(WriterPtr& out1)
- : out(out1), sz(1024)
+ : BufferedWriter(out1, 1024)
{
}
BufferedWriter::BufferedWriter(WriterPtr& out1, size_t sz1)
- : out(out1), sz(sz1)
+ : m_priv(std::make_unique<BufferedWriterPriv>(out1, sz1))
{
}
@@ -40,33 +51,33 @@ BufferedWriter::~BufferedWriter()
void BufferedWriter::close(Pool& p)
{
flush(p);
- out->close(p);
+ m_priv->out->close(p);
}
void BufferedWriter::flush(Pool& p)
{
- if (buf.length() > 0)
+ if (m_priv->buf.length() > 0)
{
- out->write(buf, p);
- buf.erase(buf.begin(), buf.end());
+ m_priv->out->write(m_priv->buf, p);
+ m_priv->buf.erase(m_priv->buf.begin(), m_priv->buf.end());
}
}
void BufferedWriter::write(const LogString& str, Pool& p)
{
- if (buf.length() + str.length() > sz)
+ if (m_priv->buf.length() + str.length() > m_priv->sz)
{
- out->write(buf, p);
- buf.erase(buf.begin(), buf.end());
+ m_priv->out->write(m_priv->buf, p);
+ m_priv->buf.erase(m_priv->buf.begin(), m_priv->buf.end());
}
- if (str.length() > sz)
+ if (str.length() > m_priv->sz)
{
- out->write(str, p);
+ m_priv->out->write(str, p);
}
else
{
- buf.append(str);
+ m_priv->buf.append(str);
}
}
diff --git a/src/main/cpp/bytearrayinputstream.cpp b/src/main/cpp/bytearrayinputstream.cpp
index 66f3a9b..cb2453e 100644
--- a/src/main/cpp/bytearrayinputstream.cpp
+++ b/src/main/cpp/bytearrayinputstream.cpp
@@ -26,10 +26,19 @@ using namespace log4cxx;
using namespace log4cxx::helpers;
using namespace std;
+struct ByteArrayInputStream::ByteArrayInputStreamPriv{
+ ByteArrayInputStreamPriv(const ByteList& bytes) :
+ buf(bytes),
+ pos(0){}
+
+ ByteList buf;
+ size_t pos;
+};
+
IMPLEMENT_LOG4CXX_OBJECT(ByteArrayInputStream)
ByteArrayInputStream::ByteArrayInputStream(const std::vector<unsigned char>& bytes) :
- buf(bytes), pos(0)
+ m_priv(std::make_unique<ByteArrayInputStreamPriv>(bytes))
{
}
@@ -47,15 +56,15 @@ void ByteArrayInputStream::close()
int ByteArrayInputStream::read(ByteBuffer& dst)
{
- if (pos >= buf.size())
+ if (m_priv->pos >= m_priv->buf.size())
{
return -1;
}
else
{
- size_t bytesCopied = min(dst.remaining(), buf.size() - pos);
- std::memcpy(dst.current(), &buf[pos], bytesCopied);
- pos += bytesCopied;
+ size_t bytesCopied = min(dst.remaining(), m_priv->buf.size() - m_priv->pos);
+ std::memcpy(dst.current(), &m_priv->buf[m_priv->pos], bytesCopied);
+ m_priv->pos += bytesCopied;
dst.position(dst.position() + bytesCopied);
return (int)bytesCopied;
}
diff --git a/src/main/cpp/bytearrayoutputstream.cpp b/src/main/cpp/bytearrayoutputstream.cpp
index 4918add..786581c 100644
--- a/src/main/cpp/bytearrayoutputstream.cpp
+++ b/src/main/cpp/bytearrayoutputstream.cpp
@@ -24,6 +24,10 @@
using namespace log4cxx;
using namespace log4cxx::helpers;
+struct ByteArrayOutputStream::ByteArrayOutputStreamPriv{
+ ByteList array;
+};
+
IMPLEMENT_LOG4CXX_OBJECT(ByteArrayOutputStream)
ByteArrayOutputStream::ByteArrayOutputStream()
@@ -44,15 +48,15 @@ void ByteArrayOutputStream::flush(Pool& /* p */)
void ByteArrayOutputStream::write(ByteBuffer& buf, Pool& /* p */ )
{
- size_t sz = array.size();
- array.resize(sz + buf.remaining());
- memcpy(&array[sz], buf.current(), buf.remaining());
+ size_t sz = m_priv->array.size();
+ m_priv->array.resize(sz + buf.remaining());
+ memcpy(&m_priv->array[sz], buf.current(), buf.remaining());
buf.position(buf.limit());
}
std::vector<unsigned char> ByteArrayOutputStream::toByteArray() const
{
- return array;
+ return m_priv->array;
}
diff --git a/src/main/cpp/bytebuffer.cpp b/src/main/cpp/bytebuffer.cpp
index c82e3fc..1347afb 100644
--- a/src/main/cpp/bytebuffer.cpp
+++ b/src/main/cpp/bytebuffer.cpp
@@ -22,8 +22,18 @@
using namespace log4cxx;
using namespace log4cxx::helpers;
+struct ByteBuffer::ByteBufferPriv{
+ ByteBufferPriv(char* data1, size_t capacity) :
+ base(data1), pos(0), lim(capacity), cap(capacity){}
+
+ char* base;
+ size_t pos;
+ size_t lim;
+ size_t cap;
+};
+
ByteBuffer::ByteBuffer(char* data1, size_t capacity)
- : base(data1), pos(0), lim(capacity), cap(capacity)
+ : m_priv(std::make_unique<ByteBufferPriv>(data1, capacity))
{
}
@@ -33,46 +43,82 @@ ByteBuffer::~ByteBuffer()
void ByteBuffer::clear()
{
- lim = cap;
- pos = 0;
+ m_priv->lim = m_priv->cap;
+ m_priv->pos = 0;
}
void ByteBuffer::flip()
{
- lim = pos;
- pos = 0;
+ m_priv->lim = m_priv->pos;
+ m_priv->pos = 0;
}
void ByteBuffer::position(size_t newPosition)
{
- if (newPosition < lim)
+ if (newPosition < m_priv->lim)
{
- pos = newPosition;
+ m_priv->pos = newPosition;
}
else
{
- pos = lim;
+ m_priv->pos = m_priv->lim;
}
}
void ByteBuffer::limit(size_t newLimit)
{
- if (newLimit > cap)
+ if (newLimit > m_priv->cap)
{
throw IllegalArgumentException(LOG4CXX_STR("newLimit"));
}
- lim = newLimit;
+ m_priv->lim = newLimit;
}
bool ByteBuffer::put(char byte)
{
- if (pos < lim)
+ if (m_priv->pos < m_priv->lim)
{
- base[pos++] = byte;
+ m_priv->base[m_priv->pos++] = byte;
return true;
}
return false;
}
+
+char* ByteBuffer::data()
+{
+ return m_priv->base;
+}
+
+const char* ByteBuffer::data() const
+{
+ return m_priv->base;
+}
+
+char* ByteBuffer::current()
+{
+ return m_priv->base + m_priv->pos;
+}
+
+const char* ByteBuffer::current() const
+{
+ return m_priv->base + m_priv->pos;
+}
+
+size_t ByteBuffer::limit() const
+{
+ return m_priv->lim;
+}
+
+size_t ByteBuffer::position() const
+{
+ return m_priv->pos;
+}
+
+size_t ByteBuffer::remaining() const
+{
+ return m_priv->lim - m_priv->pos;
+}
+
diff --git a/src/main/cpp/cacheddateformat.cpp b/src/main/cpp/cacheddateformat.cpp
index 37fa8ea..2b6df72 100644
--- a/src/main/cpp/cacheddateformat.cpp
+++ b/src/main/cpp/cacheddateformat.cpp
@@ -28,7 +28,51 @@ using namespace log4cxx;
using namespace log4cxx::helpers;
using namespace log4cxx::pattern;
+struct CachedDateFormat::CachedDateFormatPriv{
+ CachedDateFormatPriv(DateFormatPtr dateFormat, int expiration1) :
+ formatter(dateFormat),
+ millisecondStart(0),
+ slotBegin(std::numeric_limits<log4cxx_time_t>::min()),
+ cache(50, 0x20),
+ expiration(expiration1),
+ previousTime(std::numeric_limits<log4cxx_time_t>::min())
+ {}
+ /**
+ * Wrapped formatter.
+ */
+ log4cxx::helpers::DateFormatPtr formatter;
+
+ /**
+ * Index of initial digit of millisecond pattern or
+ * UNRECOGNIZED_MILLISECONDS or NO_MILLISECONDS.
+ */
+ mutable int millisecondStart;
+
+ /**
+ * Integral second preceding the previous convered Date.
+ */
+ mutable log4cxx_time_t slotBegin;
+
+
+ /**
+ * Cache of previous conversion.
+ */
+ mutable LogString cache;
+
+
+ /**
+ * Maximum validity period for the cache.
+ * Typically 1, use cache for duplicate requests only, or
+ * 1000000, use cache for requests within the same integral second.
+ */
+ const int expiration;
+
+ /**
+ * Date requested in previous conversion.
+ */
+ mutable log4cxx_time_t previousTime;
+};
/**
@@ -83,12 +127,7 @@ const logchar CachedDateFormat::zeroString[] = { 0x30, 0x30, 0x30, 0 };
*/
CachedDateFormat::CachedDateFormat(const DateFormatPtr& dateFormat,
int expiration1) :
- formatter(dateFormat),
- millisecondStart(0),
- slotBegin(std::numeric_limits<log4cxx_time_t>::min()),
- cache(50, 0x20),
- expiration(expiration1),
- previousTime(std::numeric_limits<log4cxx_time_t>::min())
+ m_priv(std::make_unique<CachedDateFormatPriv>(dateFormat, expiration1))
{
if (dateFormat == NULL)
{
@@ -101,6 +140,8 @@ CachedDateFormat::CachedDateFormat(const DateFormatPtr& dateFormat,
}
}
+CachedDateFormat::~CachedDateFormat(){}
+
/**
* Finds start of millisecond field in formatted time.
@@ -209,9 +250,9 @@ void CachedDateFormat::format(LogString& buf, log4cxx_time_t now, Pool& p) const
// If the current requested time is identical to the previously
// requested time, then append the cache contents.
//
- if (now == previousTime)
+ if (now == m_priv->previousTime)
{
- buf.append(cache);
+ buf.append(m_priv->cache);
return;
}
@@ -219,28 +260,28 @@ void CachedDateFormat::format(LogString& buf, log4cxx_time_t now, Pool& p) const
// If millisecond pattern was not unrecognized
// (that is if it was found or milliseconds did not appear)
//
- if (millisecondStart != UNRECOGNIZED_MILLISECONDS)
+ if (m_priv->millisecondStart != UNRECOGNIZED_MILLISECONDS)
{
// Check if the cache is still valid.
// If the requested time is within the same integral second
// as the last request and a shorter expiration was not requested.
- if (now < slotBegin + expiration
- && now >= slotBegin
- && now < slotBegin + 1000000L)
+ if (now < m_priv->slotBegin + m_priv->expiration
+ && now >= m_priv->slotBegin
+ && now < m_priv->slotBegin + 1000000L)
{
//
// if there was a millisecond field then update it
//
- if (millisecondStart >= 0)
+ if (m_priv->millisecondStart >= 0)
{
- millisecondFormat((int) ((now - slotBegin) / 1000), cache, millisecondStart);
+ millisecondFormat((int) ((now - m_priv->slotBegin) / 1000), m_priv->cache, m_priv->millisecondStart);
}
//
// update the previously requested time
// (the slot begin should be unchanged)
- previousTime = now;
- buf.append(cache);
+ m_priv->previousTime = now;
+ buf.append(m_priv->cache);
return;
}
@@ -249,24 +290,24 @@ void CachedDateFormat::format(LogString& buf, log4cxx_time_t now, Pool& p) const
//
// could not use previous value.
// Call underlying formatter to format date.
- cache.erase(cache.begin(), cache.end());
- formatter->format(cache, now, p);
- buf.append(cache);
- previousTime = now;
- slotBegin = (previousTime / 1000000) * 1000000;
+ m_priv->cache.erase(m_priv->cache.begin(), m_priv->cache.end());
+ m_priv->formatter->format(m_priv->cache, now, p);
+ buf.append(m_priv->cache);
+ m_priv->previousTime = now;
+ m_priv->slotBegin = (m_priv->previousTime / 1000000) * 1000000;
- if (slotBegin > previousTime)
+ if (m_priv->slotBegin > m_priv->previousTime)
{
- slotBegin -= 1000000;
+ m_priv->slotBegin -= 1000000;
}
//
// if the milliseconds field was previous found
// then reevaluate in case it moved.
//
- if (millisecondStart >= 0)
+ if (m_priv->millisecondStart >= 0)
{
- millisecondStart = findMillisecondStart(now, cache, formatter, p);
+ m_priv->millisecondStart = findMillisecondStart(now, m_priv->cache, m_priv->formatter, p);
}
}
@@ -295,16 +336,16 @@ void CachedDateFormat::millisecondFormat(int millis,
*/
void CachedDateFormat::setTimeZone(const TimeZonePtr& timeZone)
{
- formatter->setTimeZone(timeZone);
- previousTime = std::numeric_limits<log4cxx_time_t>::min();
- slotBegin = std::numeric_limits<log4cxx_time_t>::min();
+ m_priv->formatter->setTimeZone(timeZone);
+ m_priv->previousTime = std::numeric_limits<log4cxx_time_t>::min();
+ m_priv->slotBegin = std::numeric_limits<log4cxx_time_t>::min();
}
void CachedDateFormat::numberFormat(LogString& s, int n, Pool& p) const
{
- formatter->numberFormat(s, n, p);
+ m_priv->formatter->numberFormat(s, n, p);
}
diff --git a/src/main/cpp/cyclicbuffer.cpp b/src/main/cpp/cyclicbuffer.cpp
index 9f4a9a0..fe1d012 100644
--- a/src/main/cpp/cyclicbuffer.cpp
+++ b/src/main/cpp/cyclicbuffer.cpp
@@ -25,6 +25,16 @@ using namespace log4cxx;
using namespace log4cxx::helpers;
using namespace log4cxx::spi;
+struct CyclicBuffer::CyclicBufferPriv{
+ CyclicBufferPriv(int maxSize1) :
+ ea(maxSize1), first(0), last(0), numElems(0), maxSize(maxSize1){}
+
+ log4cxx::spi::LoggingEventList ea;
+ int first;
+ int last;
+ int numElems;
+ int maxSize;
+};
/**
Instantiate a new CyclicBuffer of at most <code>maxSize</code> events.
@@ -32,7 +42,7 @@ The <code>maxSize</code> argument must a positive integer.
@param maxSize The maximum number of elements in the buffer.
*/
CyclicBuffer::CyclicBuffer(int maxSize1)
- : ea(maxSize1), first(0), last(0), numElems(0), maxSize(maxSize1)
+ : m_priv(std::make_unique<CyclicBufferPriv>(maxSize1))
{
if (maxSize1 < 1)
{
@@ -53,20 +63,20 @@ Add an <code>event</code> as the last event in the buffer.
*/
void CyclicBuffer::add(const spi::LoggingEventPtr& event)
{
- ea[last] = event;
+ m_priv->ea[m_priv->last] = event;
- if (++last == maxSize)
+ if (++m_priv->last == m_priv->maxSize)
{
- last = 0;
+ m_priv->last = 0;
}
- if (numElems < maxSize)
+ if (m_priv->numElems < m_priv->maxSize)
{
- numElems++;
+ m_priv->numElems++;
}
- else if (++first == maxSize)
+ else if (++m_priv->first == m_priv->maxSize)
{
- first = 0;
+ m_priv->first = 0;
}
}
@@ -78,12 +88,12 @@ currently in the buffer, then <code>null</code> is returned.
*/
spi::LoggingEventPtr CyclicBuffer::get(int i)
{
- if (i < 0 || i >= numElems)
+ if (i < 0 || i >= m_priv->numElems)
{
return 0;
}
- return ea[(first + i) % maxSize];
+ return m_priv->ea[(m_priv->first + i) % m_priv->maxSize];
}
/**
@@ -94,15 +104,15 @@ spi::LoggingEventPtr CyclicBuffer::get()
{
LoggingEventPtr r;
- if (numElems > 0)
+ if (m_priv->numElems > 0)
{
- numElems--;
- r = ea[first];
- ea[first] = 0;
+ m_priv->numElems--;
+ r = m_priv->ea[m_priv->first];
+ m_priv->ea[m_priv->first] = 0;
- if (++first == maxSize)
+ if (++m_priv->first == m_priv->maxSize)
{
- first = 0;
+ m_priv->first = 0;
}
}
@@ -124,38 +134,48 @@ void CyclicBuffer::resize(int newSize)
throw IllegalArgumentException(msg);
}
- if (newSize == numElems)
+ if (newSize == m_priv->numElems)
{
return; // nothing to do
}
LoggingEventList temp(newSize);
- int loopLen = newSize < numElems ? newSize : numElems;
+ int loopLen = newSize < m_priv->numElems ? newSize : m_priv->numElems;
int i;
for (i = 0; i < loopLen; i++)
{
- temp[i] = ea[first];
- ea[first] = 0;
+ temp[i] = m_priv->ea[m_priv->first];
+ m_priv->ea[m_priv->first] = 0;
- if (++first == numElems)
+ if (++m_priv->first == m_priv->numElems)
{
- first = 0;
+ m_priv->first = 0;
}
}
- ea = temp;
- first = 0;
- numElems = loopLen;
- maxSize = newSize;
+ m_priv->ea = temp;
+ m_priv->first = 0;
+ m_priv->numElems = loopLen;
+ m_priv->maxSize = newSize;
if (loopLen == newSize)
{
- last = 0;
+ m_priv->last = 0;
}
else
{
- last = loopLen;
+ m_priv->last = loopLen;
}
}
+
+int CyclicBuffer::getMaxSize() const
+{
+ return m_priv->maxSize;
+}
+
+int CyclicBuffer::length() const
+{
+ return m_priv->numElems;
+}
diff --git a/src/main/cpp/datagrampacket.cpp b/src/main/cpp/datagrampacket.cpp
index a9577ec..73b9f28 100644
--- a/src/main/cpp/datagrampacket.cpp
+++ b/src/main/cpp/datagrampacket.cpp
@@ -20,12 +20,51 @@
using namespace log4cxx::helpers;
+struct DatagramPacket::DatagramPacketPriv{
+ DatagramPacketPriv(void* buf1, int length1)
+ : buf(buf1), offset(0), length(length1), address(), port(0)
+ {
+ }
+
+ DatagramPacketPriv(void* buf1, int length1, InetAddressPtr address1,
+ int port1)
+ : buf(buf1), offset(0), length(length1), address(address1), port(port1)
+ {
+ }
+
+ DatagramPacketPriv(void* buf1, int offset1, int length1)
+ : buf(buf1), offset(offset1), length(length1), address(), port(0)
+ {
+ }
+
+ DatagramPacketPriv(void* buf1, int offset1, int length1,
+ InetAddressPtr address1, int port1)
+ : buf(buf1), offset(offset1), length(length1), address(address1), port(port1)
+ {
+ }
+
+ /** the data for this packet. */
+ void* buf;
+
+ /** The offset of the data for this packet. */
+ int offset;
+
+ /** The length of the data for this packet. */
+ int length;
+
+ /** The IP address for this packet. */
+ InetAddressPtr address;
+
+ /** The UDP port number of the remote host. */
+ int port;
+};
+
IMPLEMENT_LOG4CXX_OBJECT(DatagramPacket)
/** Constructs a DatagramPacket for receiving packets of length
<code>length</code>. */
DatagramPacket::DatagramPacket(void* buf1, int length1)
- : buf(buf1), offset(0), length(length1), address(), port(0)
+ : m_priv(std::make_unique<DatagramPacketPriv>(buf1, length1))
{
}
@@ -34,14 +73,14 @@ DatagramPacket::DatagramPacket(void* buf1, int length1)
host. */
DatagramPacket::DatagramPacket(void* buf1, int length1, InetAddressPtr address1,
int port1)
- : buf(buf1), offset(0), length(length1), address(address1), port(port1)
+ : m_priv(std::make_unique<DatagramPacketPriv>(buf1, length1, address1, port1))
{
}
/** Constructs a DatagramPacket for receiving packets of length
<code>length</code>, specifying an offset into the buffer. */
DatagramPacket::DatagramPacket(void* buf1, int offset1, int length1)
- : buf(buf1), offset(offset1), length(length1), address(), port(0)
+ : m_priv(std::make_unique<DatagramPacketPriv>(buf1, offset1, length1))
{
}
/** Constructs a datagram packet for sending packets of length
@@ -49,10 +88,62 @@ DatagramPacket::DatagramPacket(void* buf1, int offset1, int length1)
specified port number on the specified host. */
DatagramPacket::DatagramPacket(void* buf1, int offset1, int length1,
InetAddressPtr address1, int port1)
- : buf(buf1), offset(offset1), length(length1), address(address1), port(port1)
+ : m_priv(std::make_unique<DatagramPacketPriv>(buf1, offset1, length1, address1, port1))
{
}
DatagramPacket::~DatagramPacket()
{
}
+
+InetAddressPtr DatagramPacket::getAddress() const
+{
+ return m_priv->address;
+}
+
+void* DatagramPacket::getData() const
+{
+ return m_priv->buf;
+}
+
+int DatagramPacket::getLength() const
+{
+ return m_priv->length;
+}
+
+int DatagramPacket::getOffset() const
+{
+ return m_priv->offset;
+}
+
+int DatagramPacket::getPort() const
+{
+ return m_priv->port;
+}
+
+void DatagramPacket::setAddress(InetAddressPtr address1)
+{
+ m_priv->address = address1;
+}
+
+void DatagramPacket::setData(void* buf1)
+{
+ m_priv->buf = buf1;
+}
+
+void DatagramPacket::setData(void* buf1, int offset1, int length1)
+{
+ m_priv->buf = buf1;
+ m_priv->offset = offset1;
+ m_priv->length = length1;
+}
+
+void DatagramPacket::setLength(int length1)
+{
+ m_priv->length = length1;
+}
+
+void DatagramPacket::setPort(int port1)
+{
+ m_priv->port = port1;
+}
diff --git a/src/main/cpp/datagramsocket.cpp b/src/main/cpp/datagramsocket.cpp
index 4b2a1f8..b5ee30f 100644
--- a/src/main/cpp/datagramsocket.cpp
+++ b/src/main/cpp/datagramsocket.cpp
@@ -25,16 +25,48 @@
using namespace log4cxx::helpers;
+struct DatagramSocket::DatagramSocketPriv{
+ DatagramSocketPriv()
+ : socket(0), address(), localAddress(), port(0), localPort(0)
+ {
+ }
+
+ DatagramSocketPriv(int localPort1)
+ : socket(0), address(), localAddress(), port(0), localPort(0)
+ {
+ }
+
+ DatagramSocketPriv(int localPort1, InetAddressPtr localAddress1)
+ : socket(0), address(), localAddress(), port(0), localPort(0)
+ {
+ }
+
+ /** The APR socket */
+ apr_socket_t* socket;
+
+ /** The memory pool for the socket */
+ Pool socketPool;
+
+ InetAddressPtr address;
+
+ InetAddressPtr localAddress;
+
+ int port;
+
+ /** The local port number to which this socket is connected. */
+ int localPort;
+};
+
IMPLEMENT_LOG4CXX_OBJECT(DatagramSocket)
DatagramSocket::DatagramSocket()
- : socket(0), address(), localAddress(), port(0), localPort(0)
+ : m_priv(std::make_unique<DatagramSocketPriv>())
{
create();
}
DatagramSocket::DatagramSocket(int localPort1)
- : socket(0), address(), localAddress(), port(0), localPort(0)
+ : m_priv(std::make_unique<DatagramSocketPriv>(localPort1))
{
InetAddressPtr bindAddr = InetAddress::anyAddress();
@@ -43,7 +75,7 @@ DatagramSocket::DatagramSocket(int localPort1)
}
DatagramSocket::DatagramSocket(int localPort1, InetAddressPtr localAddress1)
- : socket(0), address(), localAddress(), port(0), localPort(0)
+ : m_priv(std::make_unique<DatagramSocketPriv>(localPort1, localAddress1))
{
create();
bind(localPort1, localAddress1);
@@ -78,39 +110,39 @@ void DatagramSocket::bind(int localPort1, InetAddressPtr localAddress1)
}
// bind the socket to the address
- status = apr_socket_bind(socket, server_addr);
+ status = apr_socket_bind(m_priv->socket, server_addr);
if (status != APR_SUCCESS)
{
throw BindException(status);
}
- this->localPort = localPort1;
- this->localAddress = localAddress1;
+ m_priv->localPort = localPort1;
+ m_priv->localAddress = localAddress1;
}
/** Close the socket.*/
void DatagramSocket::close()
{
- if (socket != 0)
+ if (m_priv->socket != 0)
{
- apr_status_t status = apr_socket_close(socket);
+ apr_status_t status = apr_socket_close(m_priv->socket);
if (status != APR_SUCCESS)
{
throw SocketException(status);
}
- socket = 0;
- localPort = 0;
+ m_priv->socket = 0;
+ m_priv->localPort = 0;
}
}
void DatagramSocket::connect(InetAddressPtr address1, int port1)
{
- this->address = address1;
- this->port = port1;
+ m_priv->address = address1;
+ m_priv->port = port1;
Pool addrPool;
@@ -119,7 +151,7 @@ void DatagramSocket::connect(InetAddressPtr address1, int port1)
apr_sockaddr_t* client_addr;
apr_status_t status =
apr_sockaddr_info_get(&client_addr, hostAddr.c_str(), APR_INET,
- port, 0, addrPool.getAPRPool());
+ m_priv->port, 0, addrPool.getAPRPool());
if (status != APR_SUCCESS)
{
@@ -127,7 +159,7 @@ void DatagramSocket::connect(InetAddressPtr address1, int port1)
}
// connect the socket
- status = apr_socket_connect(socket, client_addr);
+ status = apr_socket_connect(m_priv->socket, client_addr);
if (status != APR_SUCCESS)
{
@@ -141,8 +173,8 @@ void DatagramSocket::create()
apr_socket_t* newSocket;
apr_status_t status =
apr_socket_create(&newSocket, APR_INET, SOCK_DGRAM,
- APR_PROTO_UDP, socketPool.getAPRPool());
- socket = newSocket;
+ APR_PROTO_UDP, m_priv->socketPool.getAPRPool());
+ m_priv->socket = newSocket;
if (status != APR_SUCCESS)
{
@@ -169,7 +201,7 @@ void DatagramSocket::receive(DatagramPacketPtr& p)
// receive the datagram packet
apr_size_t len = p->getLength();
- status = apr_socket_recvfrom(addr, socket, 0,
+ status = apr_socket_recvfrom(addr, m_priv->socket, 0,
(char*)p->getData(), &len);
if (status != APR_SUCCESS)
@@ -197,7 +229,7 @@ void DatagramSocket::send(DatagramPacketPtr& p)
// send the datagram packet
apr_size_t len = p->getLength();
- status = apr_socket_sendto(socket, addr, 0,
+ status = apr_socket_sendto(m_priv->socket, addr, 0,
(char*)p->getData(), &len);
if (status != APR_SUCCESS)
@@ -205,3 +237,38 @@ void DatagramSocket::send(DatagramPacketPtr& p)
throw IOException(status);
}
}
+
+InetAddressPtr DatagramSocket::getInetAddress() const
+{
+ return m_priv->address;
+}
+
+InetAddressPtr DatagramSocket::getLocalAddress() const
+{
+ return m_priv->localAddress;
+}
+
+int DatagramSocket::getLocalPort() const
+{
+ return m_priv->localPort;
+}
+
+int DatagramSocket::getPort() const
+{
+ return m_priv->port;
+}
+
+bool DatagramSocket::isBound() const
+{
+ return m_priv->localPort != 0;
+}
+
+bool DatagramSocket::isClosed() const
+{
+ return m_priv->socket != 0;
+}
+
+bool DatagramSocket::isConnected() const
+{
+ return m_priv->port != 0;
+}
diff --git a/src/main/include/log4cxx/helpers/bufferedwriter.h b/src/main/include/log4cxx/helpers/bufferedwriter.h
index 0b38a5d..6bc7a12 100644
--- a/src/main/include/log4cxx/helpers/bufferedwriter.h
+++ b/src/main/include/log4cxx/helpers/bufferedwriter.h
@@ -37,10 +37,9 @@ namespace helpers
*/
class LOG4CXX_EXPORT BufferedWriter : public Writer
{
- private:
- WriterPtr out;
- size_t sz;
- LogString buf;
+private:
+ struct BufferedWriterPriv;
+ std::unique_ptr<BufferedWriterPriv> m_priv;
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(BufferedWriter)
diff --git a/src/main/include/log4cxx/helpers/bytearrayinputstream.h b/src/main/include/log4cxx/helpers/bytearrayinputstream.h
index b484469..a5df60a 100644
--- a/src/main/include/log4cxx/helpers/bytearrayinputstream.h
+++ b/src/main/include/log4cxx/helpers/bytearrayinputstream.h
@@ -41,8 +41,8 @@ LOG4CXX_LIST_DEF(ByteList, unsigned char);
class LOG4CXX_EXPORT ByteArrayInputStream : public InputStream
{
private:
- ByteList buf;
- size_t pos;
+ struct ByteArrayInputStreamPriv;
+ std::unique_ptr<ByteArrayInputStreamPriv> m_priv;
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(ByteArrayInputStream)
diff --git a/src/main/include/log4cxx/helpers/bytearrayoutputstream.h b/src/main/include/log4cxx/helpers/bytearrayoutputstream.h
index 90e397c..f4f96c2 100644
--- a/src/main/include/log4cxx/helpers/bytearrayoutputstream.h
+++ b/src/main/include/log4cxx/helpers/bytearrayoutputstream.h
@@ -44,7 +44,8 @@ LOG4CXX_LIST_DEF(ByteList, unsigned char);
class LOG4CXX_EXPORT ByteArrayOutputStream : public OutputStream
{
private:
- ByteList array;
+ struct ByteArrayOutputStreamPriv;
+ std::unique_ptr<ByteArrayOutputStreamPriv> m_priv;
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(ByteArrayOutputStream)
diff --git a/src/main/include/log4cxx/helpers/bytebuffer.h b/src/main/include/log4cxx/helpers/bytebuffer.h
index 3c68568..21f8916 100644
--- a/src/main/include/log4cxx/helpers/bytebuffer.h
+++ b/src/main/include/log4cxx/helpers/bytebuffer.h
@@ -33,10 +33,8 @@ namespace helpers
class LOG4CXX_EXPORT ByteBuffer
{
private:
- char* base;
- size_t pos;
- size_t lim;
- size_t cap;
+ struct ByteBufferPriv;
+ std::unique_ptr<ByteBufferPriv> m_priv;
public:
ByteBuffer(char* data, size_t capacity);
@@ -45,35 +43,14 @@ class LOG4CXX_EXPORT ByteBuffer
void clear();
void flip();
- inline char* data()
- {
- return base;
- }
- inline const char* data() const
- {
- return base;
- }
- inline char* current()
- {
- return base + pos;
- }
- inline const char* current() const
- {
- return base + pos;
- }
- inline size_t limit() const
- {
- return lim;
- }
+ char* data();
+ const char* data() const;
+ char* current();
+ const char* current() const;
+ size_t limit() const;
void limit(size_t newLimit);
- inline size_t position() const
- {
- return pos;
- }
- inline size_t remaining() const
- {
- return lim - pos;
- }
+ size_t position() const;
+ size_t remaining() const;
void position(size_t newPosition);
bool put(char byte);
diff --git a/src/main/include/log4cxx/helpers/cacheddateformat.h b/src/main/include/log4cxx/helpers/cacheddateformat.h
index fcfcedc..94c543d 100644
--- a/src/main/include/log4cxx/helpers/cacheddateformat.h
+++ b/src/main/include/log4cxx/helpers/cacheddateformat.h
@@ -87,40 +87,8 @@ class LOG4CXX_EXPORT CachedDateFormat : public log4cxx::helpers::DateFormat
*/
static const logchar zeroString[];
- /**
- * Wrapped formatter.
- */
- log4cxx::helpers::DateFormatPtr formatter;
-
- /**
- * Index of initial digit of millisecond pattern or
- * UNRECOGNIZED_MILLISECONDS or NO_MILLISECONDS.
- */
- mutable int millisecondStart;
-
- /**
- * Integral second preceding the previous convered Date.
- */
- mutable log4cxx_time_t slotBegin;
-
-
- /**
- * Cache of previous conversion.
- */
- mutable LogString cache;
-
-
- /**
- * Maximum validity period for the cache.
- * Typically 1, use cache for duplicate requests only, or
- * 1000000, use cache for requests within the same integral second.
- */
- const int expiration;
-
- /**
- * Date requested in previous conversion.
- */
- mutable log4cxx_time_t previousTime;
+ struct CachedDateFormatPriv;
+ std::unique_ptr<CachedDateFormatPriv> m_priv;
public:
/**
@@ -132,6 +100,7 @@ class LOG4CXX_EXPORT CachedDateFormat : public log4cxx::helpers::DateFormat
* caching or 1 to only use cache for duplicate requests.
*/
CachedDateFormat(const log4cxx::helpers::DateFormatPtr& dateFormat, int expiration);
+ ~CachedDateFormat();
/**
* Finds start of millisecond field in formatted time.
diff --git a/src/main/include/log4cxx/helpers/cyclicbuffer.h b/src/main/include/log4cxx/helpers/cyclicbuffer.h
index 0456dcd..f05a9e9 100644
--- a/src/main/include/log4cxx/helpers/cyclicbuffer.h
+++ b/src/main/include/log4cxx/helpers/cyclicbuffer.h
@@ -19,6 +19,7 @@
#define _LOG4CXX_HELPERS_CYCLICBUFFER_H
#include <log4cxx/spi/loggingevent.h>
+#include <memory>
namespace log4cxx
{
@@ -33,11 +34,9 @@ just the first or last element.
*/
class LOG4CXX_EXPORT CyclicBuffer
{
- log4cxx::spi::LoggingEventList ea;
- int first;
- int last;
- int numElems;
- int maxSize;
+ private:
+ struct CyclicBufferPriv;
+ std::unique_ptr<CyclicBufferPriv> m_priv;
public:
/**
@@ -63,10 +62,7 @@ class LOG4CXX_EXPORT CyclicBuffer
*/
spi::LoggingEventPtr get(int i);
- int getMaxSize() const
- {
- return maxSize;
- }
+ int getMaxSize() const;
/**
Get the oldest (first) element in the buffer. The oldest element
@@ -79,10 +75,7 @@ class LOG4CXX_EXPORT CyclicBuffer
guaranteed to be in the range 0 to <code>maxSize</code>
(inclusive).
*/
- int length() const
- {
- return numElems;
- }
+ int length() const;
/**
Resize the cyclic buffer to <code>newSize</code>.
diff --git a/src/main/include/log4cxx/helpers/datagrampacket.h b/src/main/include/log4cxx/helpers/datagrampacket.h
index 1ac1f6b..f4e9e60 100644
--- a/src/main/include/log4cxx/helpers/datagrampacket.h
+++ b/src/main/include/log4cxx/helpers/datagrampacket.h
@@ -35,21 +35,9 @@ and might arrive in any order.
*/
class LOG4CXX_EXPORT DatagramPacket : public helpers::Object
{
- protected:
- /** the data for this packet. */
- void* buf;
-
- /** The offset of the data for this packet. */
- int offset;
-
- /** The length of the data for this packet. */
- int length;
-
- /** The IP address for this packet. */
- InetAddressPtr address;
-
- /** The UDP port number of the remote host. */
- int port;
+ private:
+ struct DatagramPacketPriv;
+ std::unique_ptr<DatagramPacketPriv> m_priv;
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(DatagramPacket)
@@ -80,67 +68,35 @@ class LOG4CXX_EXPORT DatagramPacket : public helpers::Object
/** Returns the IP address of the machine to which this datagram
is being sent or from which the datagram was received. */
- inline InetAddressPtr getAddress() const
- {
- return address;
- }
+ InetAddressPtr getAddress() const;
/** Returns the data received or the data to be sent. */
- inline void* getData() const
- {
- return buf;
- }
+ void* getData() const;
/** Returns the length of the data to be sent or the length of the
data received. */
- inline int getLength() const
- {
- return length;
- }
+ int getLength() const;
/** Returns the offset of the data to be sent or the offset of the
data received. */
- inline int getOffset() const
- {
- return offset;
- }
+ int getOffset() const;
/** Returns the port number on the remote host to which this
datagram is being sent or from which the datagram was received. */
- inline int getPort() const
- {
- return port;
- }
+ int getPort() const;
- inline void setAddress(InetAddressPtr address1)
- {
- this->address = address1;
- }
+ void setAddress(InetAddressPtr address1);
/** Set the data buffer for this packet. */
- inline void setData(void* buf1)
- {
- this->buf = buf1;
- }
+ void setData(void* buf1);
/** Set the data buffer for this packet. */
- inline void setData(void* buf1, int offset1, int length1)
- {
- this->buf = buf1;
- this->offset = offset1;
- this->length = length1;
- }
+ void setData(void* buf1, int offset1, int length1);
/** Set the length for this packet. */
- inline void setLength(int length1)
- {
- this->length = length1;
- }
-
- inline void setPort(int port1)
- {
- this->port = port1;
- }
+ void setLength(int length1);
+
+ void setPort(int port1);
private:
//
diff --git a/src/main/include/log4cxx/helpers/datagramsocket.h b/src/main/include/log4cxx/helpers/datagramsocket.h
index 2f8924e..04df8ed 100644
--- a/src/main/include/log4cxx/helpers/datagramsocket.h
+++ b/src/main/include/log4cxx/helpers/datagramsocket.h
@@ -23,10 +23,6 @@
#include <log4cxx/helpers/pool.h>
#include <log4cxx/helpers/datagrampacket.h>
-extern "C" {
- struct apr_socket_t;
-}
-
namespace log4cxx
{
namespace helpers
@@ -69,47 +65,26 @@ class LOG4CXX_EXPORT DatagramSocket : public helpers::Object
void connect(InetAddressPtr address, int port);
/** Returns the address to which this socket is connected. */
- inline InetAddressPtr getInetAddress() const
- {
- return address;
- }
+ InetAddressPtr getInetAddress() const;
/** Gets the local address to which the socket is bound. */
- inline InetAddressPtr getLocalAddress() const
- {
- return localAddress;
- }
+ InetAddressPtr getLocalAddress() const;
/** Returns the port number on the local host to which this
socket is bound. */
- inline int getLocalPort() const
- {
- return localPort;
- }
+ int getLocalPort() const;
/** Returns the port for this socket */
- inline int getPort() const
- {
- return port;
- }
+ int getPort() const;
/** Returns the binding state of the socket. **/
- inline bool isBound() const
- {
- return localPort != 0;
- }
+ bool isBound() const;
/** Returns wether the socket is closed or not. */
- inline bool isClosed() const
- {
- return socket != 0;
- }
+ bool isClosed() const;
/** Returns the connection state of the socket. */
- inline bool isConnected() const
- {
- return port != 0;
- }
+ bool isConnected() const;
/** Receives a datagram packet from this socket. */
void receive(DatagramPacketPtr& p);
@@ -120,20 +95,9 @@ class LOG4CXX_EXPORT DatagramSocket : public helpers::Object
private:
DatagramSocket(const DatagramSocket&);
DatagramSocket& operator=(const DatagramSocket&);
- /** The APR socket */
- apr_socket_t* socket;
-
- /** The memory pool for the socket */
- Pool socketPool;
-
- InetAddressPtr address;
-
- InetAddressPtr localAddress;
-
- int port;
- /** The local port number to which this socket is connected. */
- int localPort;
+ struct DatagramSocketPriv;
+ std::unique_ptr<DatagramSocketPriv> m_priv;
};
LOG4CXX_PTR_DEF(DatagramSocket);
diff --git a/src/main/include/log4cxx/spi/configurator.h b/src/main/include/log4cxx/spi/configurator.h
index 89cf853..3108618 100644
--- a/src/main/include/log4cxx/spi/configurator.h
+++ b/src/main/include/log4cxx/spi/configurator.h
@@ -33,7 +33,6 @@ class LOG4CXX_EXPORT Configurator : virtual public helpers::Object
{
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(Configurator)
- Configurator();
/**
Interpret a resource pointed by a URL and set up log4j accordingly.
@@ -47,11 +46,12 @@ class LOG4CXX_EXPORT Configurator : virtual public helpers::Object
virtual void doConfigure(const File& configFileName,
spi::LoggerRepositoryPtr repository) = 0;
+protected:
+ Configurator();
private:
Configurator(const Configurator&);
Configurator& operator=(const Configurator&);
- bool initialized;
};
LOG4CXX_PTR_DEF(Configurator);