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 2022/10/18 02:11:32 UTC
[logging-log4cxx] 02/03: Made OutputStreamWriter ABI stable
This is an automated email from the ASF dual-hosted git repository.
rmiddleton pushed a commit to branch LOGCXX-518
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git
commit 6f07ca3328d48a8b0663dc532cdb9d312509e041
Author: Robert Middleton <ro...@rm5248.com>
AuthorDate: Sun Oct 16 11:03:15 2022 -0400
Made OutputStreamWriter ABI stable
---
src/main/cpp/outputstreamwriter.cpp | 36 ++++++++++++++++------
.../include/log4cxx/helpers/outputstreamwriter.h | 10 ++----
2 files changed, 28 insertions(+), 18 deletions(-)
diff --git a/src/main/cpp/outputstreamwriter.cpp b/src/main/cpp/outputstreamwriter.cpp
index 35d7f383..703f31f8 100644
--- a/src/main/cpp/outputstreamwriter.cpp
+++ b/src/main/cpp/outputstreamwriter.cpp
@@ -27,8 +27,19 @@ using namespace log4cxx::helpers;
IMPLEMENT_LOG4CXX_OBJECT(OutputStreamWriter)
+struct OutputStreamWriter::OutputStreamWriterPrivate{
+ OutputStreamWriterPrivate(OutputStreamPtr& out1) : out(out1), enc(CharsetEncoder::getDefaultEncoder()){}
+
+ OutputStreamWriterPrivate(OutputStreamPtr& out1,
+ CharsetEncoderPtr& enc1)
+ : out(out1), enc(enc1){}
+
+ OutputStreamPtr out;
+ CharsetEncoderPtr enc;
+};
+
OutputStreamWriter::OutputStreamWriter(OutputStreamPtr& out1)
- : out(out1), enc(CharsetEncoder::getDefaultEncoder())
+ : m_priv(std::make_unique<OutputStreamWriterPrivate>(out1))
{
if (out1 == 0)
{
@@ -38,7 +49,7 @@ OutputStreamWriter::OutputStreamWriter(OutputStreamPtr& out1)
OutputStreamWriter::OutputStreamWriter(OutputStreamPtr& out1,
CharsetEncoderPtr& enc1)
- : out(out1), enc(enc1)
+ : m_priv(std::make_unique<OutputStreamWriterPrivate>(out1, enc1))
{
if (out1 == 0)
{
@@ -57,12 +68,12 @@ OutputStreamWriter::~OutputStreamWriter()
void OutputStreamWriter::close(Pool& p)
{
- out->close(p);
+ m_priv->out->close(p);
}
void OutputStreamWriter::flush(Pool& p)
{
- out->flush(p);
+ m_priv->out->flush(p);
}
void OutputStreamWriter::write(const LogString& str, Pool& p)
@@ -78,24 +89,29 @@ void OutputStreamWriter::write(const LogString& str, Pool& p)
char rawbuf[BUFSIZE];
ByteBuffer buf(rawbuf, (size_t) BUFSIZE);
#endif
- enc->reset();
+ m_priv->enc->reset();
LogString::const_iterator iter = str.begin();
while (iter != str.end())
{
- CharsetEncoder::encode(enc, str, iter, buf);
+ CharsetEncoder::encode(m_priv->enc, str, iter, buf);
buf.flip();
- out->write(buf, p);
+ m_priv->out->write(buf, p);
buf.clear();
}
- CharsetEncoder::encode(enc, str, iter, buf);
- enc->flush(buf);
+ CharsetEncoder::encode(m_priv->enc, str, iter, buf);
+ m_priv->enc->flush(buf);
buf.flip();
- out->write(buf, p);
+ m_priv->out->write(buf, p);
#ifdef LOG4CXX_MULTI_PROCESS
delete []rawbuf;
#endif
}
}
+OutputStreamPtr OutputStreamWriter::getOutPutStreamPtr() const
+{
+ return m_priv->out;
+}
+
diff --git a/src/main/include/log4cxx/helpers/outputstreamwriter.h b/src/main/include/log4cxx/helpers/outputstreamwriter.h
index ee153b16..b3086f5f 100644
--- a/src/main/include/log4cxx/helpers/outputstreamwriter.h
+++ b/src/main/include/log4cxx/helpers/outputstreamwriter.h
@@ -34,8 +34,7 @@ namespace helpers
class LOG4CXX_EXPORT OutputStreamWriter : public Writer
{
private:
- OutputStreamPtr out;
- CharsetEncoderPtr enc;
+ LOG4CXX_DECLARE_PRIVATE_MEMBER_PTR(OutputStreamWriterPrivate, m_priv)
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(OutputStreamWriter)
@@ -53,12 +52,7 @@ class LOG4CXX_EXPORT OutputStreamWriter : public Writer
virtual void write(const LogString& str, Pool& p);
LogString getEncoding() const;
-#ifdef LOG4CXX_MULTI_PROCESS
- OutputStreamPtr getOutPutStreamPtr()
- {
- return out;
- }
-#endif
+ OutputStreamPtr getOutPutStreamPtr() const;
private:
OutputStreamWriter(const OutputStreamWriter&);