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:11 UTC

[logging-log4cxx] 06/20: Converted patternconverter hierarchy 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 7bd9e15951d09d0182bc3192db85076fceb0e003
Author: Robert Middleton <ro...@rm5248.com>
AuthorDate: Wed Nov 3 22:07:05 2021 -0400

    Converted patternconverter hierarchy to be ABI stable
---
 src/main/cpp/datepatternconverter.cpp              | 23 +++++++--
 src/main/cpp/literalpatternconverter.cpp           | 23 +++++++--
 src/main/cpp/loggingeventpatternconverter.cpp      |  6 +++
 src/main/cpp/namepatternconverter.cpp              | 20 ++++++--
 src/main/cpp/patternconverter.cpp                  | 15 ++++--
 src/main/cpp/propertiespatternconverter.cpp        | 22 +++++++--
 .../cpp/throwableinformationpatternconverter.cpp   | 21 +++++++--
 .../include/log4cxx/pattern/datepatternconverter.h |  6 +--
 .../log4cxx/pattern/integerpatternconverter.h      |  1 -
 .../log4cxx/pattern/literalpatternconverter.h      |  5 +-
 .../log4cxx/pattern/loggingeventpatternconverter.h |  2 +
 .../include/log4cxx/pattern/namepatternconverter.h |  5 +-
 .../include/log4cxx/pattern/patternconverter.h     | 20 ++++----
 .../log4cxx/pattern/propertiespatternconverter.h   |  5 +-
 .../pattern/throwableinformationpatternconverter.h |  5 +-
 .../log4cxx/private/patternconverter_priv.h}       | 54 ++++++++++------------
 16 files changed, 148 insertions(+), 85 deletions(-)

diff --git a/src/main/cpp/datepatternconverter.cpp b/src/main/cpp/datepatternconverter.cpp
index a0c7fb7..282db76 100644
--- a/src/main/cpp/datepatternconverter.cpp
+++ b/src/main/cpp/datepatternconverter.cpp
@@ -31,21 +31,36 @@
 #include <log4cxx/helpers/exception.h>
 #include <log4cxx/helpers/loglog.h>
 #include <log4cxx/helpers/date.h>
+#include <log4cxx/private/patternconverter_priv.h>
 
 using namespace log4cxx;
 using namespace log4cxx::pattern;
 using namespace log4cxx::spi;
 using namespace log4cxx::helpers;
 
+struct DatePatternConverter::DatePatternConverterPrivate : public PatternConverterPrivate{
+	DatePatternConverterPrivate( const LogString& name, const LogString& style, DateFormatPtr _df ):
+		PatternConverterPrivate(name,style),
+		df(_df){}
+	/**
+	 * Date format.
+	 */
+	log4cxx::helpers::DateFormatPtr df;
+};
+
+#define priv static_cast<DatePatternConverterPrivate*>(m_priv.get())
+
 IMPLEMENT_LOG4CXX_OBJECT(DatePatternConverter)
 
 DatePatternConverter::DatePatternConverter(
 	const std::vector<LogString>& options) :
-	LoggingEventPatternConverter(LOG4CXX_STR("Class Name"),
-		LOG4CXX_STR("class name")), df(getDateFormat(options))
+	LoggingEventPatternConverter (std::make_unique<DatePatternConverterPrivate>(LOG4CXX_STR("Class Name"),
+		LOG4CXX_STR("class name"), getDateFormat(options)))
 {
 }
 
+DatePatternConverter::~DatePatternConverter(){}
+
 DateFormatPtr DatePatternConverter::getDateFormat(const OptionsList& options)
 {
 	DateFormatPtr df;
@@ -129,7 +144,7 @@ void DatePatternConverter::format(
 	LogString& toAppendTo,
 	Pool& p) const
 {
-	df->format(toAppendTo, event->getTimeStamp(), p);
+	priv->df->format(toAppendTo, event->getTimeStamp(), p);
 }
 
 /**
@@ -167,5 +182,5 @@ void DatePatternConverter::format(
 	LogString& toAppendTo,
 	Pool& p) const
 {
-	df->format(toAppendTo, date->getTime(), p);
+	priv->df->format(toAppendTo, date->getTime(), p);
 }
diff --git a/src/main/cpp/literalpatternconverter.cpp b/src/main/cpp/literalpatternconverter.cpp
index c526b72..afb7ff5 100644
--- a/src/main/cpp/literalpatternconverter.cpp
+++ b/src/main/cpp/literalpatternconverter.cpp
@@ -22,18 +22,31 @@
 #include <log4cxx/pattern/literalpatternconverter.h>
 #include <log4cxx/spi/loggingevent.h>
 #include <log4cxx/spi/location/locationinfo.h>
-
+#include <log4cxx/private/patternconverter_priv.h>
 
 using namespace log4cxx;
 using namespace log4cxx::pattern;
 using namespace log4cxx::spi;
 using namespace log4cxx::helpers;
 
+#define priv static_cast<LiteralPatternConverterPrivate*>(m_priv.get())
+
+struct LiteralPatternConverter::LiteralPatternConverterPrivate : public PatternConverterPrivate {
+	LiteralPatternConverterPrivate( const LogString& name, const LogString& style, const LogString& literal1 ) :
+		PatternConverterPrivate( name, style ),
+		literal(literal1){}
+
+	/**
+	 * String literal.
+	 */
+	const LogString literal;
+};
+
 IMPLEMENT_LOG4CXX_OBJECT(LiteralPatternConverter)
 
 LiteralPatternConverter::LiteralPatternConverter(const LogString& literal1) :
-	LoggingEventPatternConverter(LOG4CXX_STR("Literal"), LOG4CXX_STR("literal")),
-	literal(literal1)
+	LoggingEventPatternConverter(std::make_unique<LiteralPatternConverterPrivate>
+								 (LOG4CXX_STR("Literal"), LOG4CXX_STR("literal"),literal1))
 {
 }
 
@@ -55,7 +68,7 @@ void LiteralPatternConverter::format(
 	LogString& toAppendTo,
 	Pool& /* p */) const
 {
-	toAppendTo.append(literal);
+	toAppendTo.append(priv->literal);
 }
 
 void LiteralPatternConverter::format(
@@ -63,6 +76,6 @@ void LiteralPatternConverter::format(
 	LogString& toAppendTo,
 	Pool& /* p */)  const
 {
-	toAppendTo.append(literal);
+	toAppendTo.append(priv->literal);
 }
 
diff --git a/src/main/cpp/loggingeventpatternconverter.cpp b/src/main/cpp/loggingeventpatternconverter.cpp
index 512fa43..dd23340 100644
--- a/src/main/cpp/loggingeventpatternconverter.cpp
+++ b/src/main/cpp/loggingeventpatternconverter.cpp
@@ -21,6 +21,7 @@
 #include <log4cxx/logstring.h>
 #include <log4cxx/pattern/loggingeventpatternconverter.h>
 #include <log4cxx/spi/loggingevent.h>
+#include <log4cxx/private/patternconverter_priv.h>
 
 using namespace log4cxx;
 using namespace log4cxx::pattern;
@@ -36,6 +37,11 @@ LoggingEventPatternConverter::LoggingEventPatternConverter(
 {
 }
 
+LoggingEventPatternConverter::LoggingEventPatternConverter(std::unique_ptr<PatternConverterPrivate> priv) :
+	PatternConverter (std::move(priv)){
+
+}
+
 void LoggingEventPatternConverter::format(const ObjectPtr& obj,
 	LogString& output,
 	log4cxx::helpers::Pool& p) const
diff --git a/src/main/cpp/namepatternconverter.cpp b/src/main/cpp/namepatternconverter.cpp
index 08ef1f2..f5c6d0e 100644
--- a/src/main/cpp/namepatternconverter.cpp
+++ b/src/main/cpp/namepatternconverter.cpp
@@ -23,19 +23,33 @@
 #include <log4cxx/pattern/namepatternconverter.h>
 #include <log4cxx/pattern/nameabbreviator.h>
 #include <log4cxx/spi/loggingevent.h>
+#include <log4cxx/private/patternconverter_priv.h>
 
 using namespace log4cxx;
 using namespace log4cxx::pattern;
 using namespace log4cxx::spi;
 
+#define priv static_cast<NamePatternConverterPrivate*>(m_priv.get())
+
+struct NamePatternConverter::NamePatternConverterPrivate : public PatternConverterPrivate {
+	NamePatternConverterPrivate( const LogString& name, const LogString& style, const NameAbbreviatorPtr abbrev ) :
+		PatternConverterPrivate( name, style ),
+	  abbreviator(abbrev){}
+
+	/**
+	 * Abbreviator.
+	 */
+	const NameAbbreviatorPtr abbreviator;
+};
+
 IMPLEMENT_LOG4CXX_OBJECT(NamePatternConverter)
 
 NamePatternConverter::NamePatternConverter(
 	const LogString& name1,
 	const LogString& style1,
 	const std::vector<LogString>& options) :
-	LoggingEventPatternConverter(name1, style1),
-	abbreviator(getAbbreviator(options))
+	LoggingEventPatternConverter(std::make_unique<NamePatternConverterPrivate>(name1, style1,
+	getAbbreviator(options)))
 {
 }
 
@@ -57,5 +71,5 @@ NameAbbreviatorPtr NamePatternConverter::getAbbreviator(
  */
 void NamePatternConverter::abbreviate(int nameStart, LogString& buf) const
 {
-	abbreviator->abbreviate(nameStart, buf);
+	priv->abbreviator->abbreviate(nameStart, buf);
 }
diff --git a/src/main/cpp/patternconverter.cpp b/src/main/cpp/patternconverter.cpp
index d0add75..304ef85 100644
--- a/src/main/cpp/patternconverter.cpp
+++ b/src/main/cpp/patternconverter.cpp
@@ -21,6 +21,7 @@
 #include <log4cxx/logstring.h>
 #include <log4cxx/pattern/patternconverter.h>
 #include <log4cxx/helpers/transcoder.h>
+#include <log4cxx/private/patternconverter_priv.h>
 
 using namespace log4cxx;
 using namespace log4cxx::pattern;
@@ -28,23 +29,29 @@ using namespace log4cxx::pattern;
 IMPLEMENT_LOG4CXX_OBJECT(PatternConverter)
 
 PatternConverter::PatternConverter(
-	const LogString& name1, const LogString& style1) :
-	name(name1), style(style1)
+	std::unique_ptr<PatternConverterPrivate> priv) :
+	m_priv(std::move(priv))
 {
 }
 
+PatternConverter::PatternConverter(const LogString& name,
+				 const LogString& style) :
+	m_priv(std::make_unique<PatternConverterPrivate>(name,style)){
+
+}
+
 PatternConverter::~PatternConverter()
 {
 }
 
 LogString PatternConverter::getName() const
 {
-	return name;
+	return m_priv->name;
 }
 
 LogString PatternConverter::getStyleClass(const log4cxx::helpers::ObjectPtr& /* e */) const
 {
-	return style;
+	return m_priv->style;
 }
 
 void PatternConverter::append(LogString& toAppendTo, const std::string& src)
diff --git a/src/main/cpp/propertiespatternconverter.cpp b/src/main/cpp/propertiespatternconverter.cpp
index b307bc7..412548b 100644
--- a/src/main/cpp/propertiespatternconverter.cpp
+++ b/src/main/cpp/propertiespatternconverter.cpp
@@ -23,6 +23,7 @@
 #include <log4cxx/pattern/propertiespatternconverter.h>
 #include <log4cxx/spi/loggingevent.h>
 #include <log4cxx/spi/location/locationinfo.h>
+#include <log4cxx/private/patternconverter_priv.h>
 
 #include <iterator>
 
@@ -31,12 +32,25 @@ using namespace log4cxx::pattern;
 using namespace log4cxx::spi;
 using namespace log4cxx::helpers;
 
+#define priv static_cast<PropertiesPatternConverterPrivate*>(m_priv.get())
+
+struct PropertiesPatternConverter::PropertiesPatternConverterPrivate : public PatternConverterPrivate {
+	PropertiesPatternConverterPrivate( const LogString& name, const LogString& style, const LogString& propertyName ) :
+		PatternConverterPrivate( name, style ),
+		option(propertyName){}
+
+	/**
+	 * Name of property to output.
+	 */
+	const LogString option;
+};
+
 IMPLEMENT_LOG4CXX_OBJECT(PropertiesPatternConverter)
 
 PropertiesPatternConverter::PropertiesPatternConverter(const LogString& name1,
 	const LogString& propertyName) :
-	LoggingEventPatternConverter(name1, LOG4CXX_STR("property")),
-	option(propertyName)
+	LoggingEventPatternConverter(
+		std::make_unique<PropertiesPatternConverterPrivate>(name1, LOG4CXX_STR("property"),propertyName))
 {
 }
 
@@ -63,7 +77,7 @@ void PropertiesPatternConverter::format(
 	LogString& toAppendTo,
 	Pool& /* p */) const
 {
-	if (option.length() == 0)
+	if (priv->option.length() == 0)
 	{
 		toAppendTo.append(1, (logchar) 0x7B /* '{' */);
 
@@ -85,7 +99,7 @@ void PropertiesPatternConverter::format(
 	}
 	else
 	{
-		event->getMDC(option, toAppendTo);
+		event->getMDC(priv->option, toAppendTo);
 	}
 }
 
diff --git a/src/main/cpp/throwableinformationpatternconverter.cpp b/src/main/cpp/throwableinformationpatternconverter.cpp
index 5f1f68f..4b80bb7 100644
--- a/src/main/cpp/throwableinformationpatternconverter.cpp
+++ b/src/main/cpp/throwableinformationpatternconverter.cpp
@@ -25,18 +25,33 @@
 #include <log4cxx/spi/loggingevent.h>
 #include <log4cxx/spi/location/locationinfo.h>
 #include <log4cxx/helpers/stringhelper.h>
+#include <log4cxx/private/patternconverter_priv.h>
 
 using namespace log4cxx;
 using namespace log4cxx::pattern;
 using namespace log4cxx::spi;
 using namespace log4cxx::helpers;
 
+struct ThrowableInformationPatternConverter::ThrowableInformationPatternConverterPrivate :
+		public PatternConverterPrivate {
+	ThrowableInformationPatternConverterPrivate( const LogString& name, const LogString& style, bool shortReport ) :
+		PatternConverterPrivate( name, style ),
+		shortReport(shortReport){}
+
+	/**
+	 * If "short", only first line of throwable report will be formatted.
+	 */
+	const bool shortReport;
+};
+
 IMPLEMENT_LOG4CXX_OBJECT(ThrowableInformationPatternConverter)
 
 ThrowableInformationPatternConverter::ThrowableInformationPatternConverter(bool shortReport1) :
-	LoggingEventPatternConverter(LOG4CXX_STR("Throwable"),
-		LOG4CXX_STR("throwable")),
-	shortReport(shortReport1)
+	LoggingEventPatternConverter(
+		std::make_unique<ThrowableInformationPatternConverterPrivate>(
+			LOG4CXX_STR("Throwable"),
+		LOG4CXX_STR("throwable"),
+	shortReport1))
 {
 }
 
diff --git a/src/main/include/log4cxx/pattern/datepatternconverter.h b/src/main/include/log4cxx/pattern/datepatternconverter.h
index cffc698..3e123ce 100644
--- a/src/main/include/log4cxx/pattern/datepatternconverter.h
+++ b/src/main/include/log4cxx/pattern/datepatternconverter.h
@@ -37,10 +37,7 @@ namespace pattern
  */
 class LOG4CXX_EXPORT DatePatternConverter : public LoggingEventPatternConverter
 {
-		/**
-		 * Date format.
-		 */
-		log4cxx::helpers::DateFormatPtr df;
+		struct DatePatternConverterPrivate;
 
 		/**
 		 * Private constructor.
@@ -62,6 +59,7 @@ class LOG4CXX_EXPORT DatePatternConverter : public LoggingEventPatternConverter
 		LOG4CXX_CAST_ENTRY_CHAIN(LoggingEventPatternConverter)
 		END_LOG4CXX_CAST_MAP()
 
+		~DatePatternConverter();
 
 		static PatternConverterPtr newInstance(
 			const std::vector<LogString>& options);
diff --git a/src/main/include/log4cxx/pattern/integerpatternconverter.h b/src/main/include/log4cxx/pattern/integerpatternconverter.h
index e86fcc5..8149bcf 100644
--- a/src/main/include/log4cxx/pattern/integerpatternconverter.h
+++ b/src/main/include/log4cxx/pattern/integerpatternconverter.h
@@ -34,7 +34,6 @@ namespace pattern
  */
 class LOG4CXX_EXPORT IntegerPatternConverter : public PatternConverter
 {
-
 		/**
 		 * Private constructor.
 		 */
diff --git a/src/main/include/log4cxx/pattern/literalpatternconverter.h b/src/main/include/log4cxx/pattern/literalpatternconverter.h
index 4c5e435..aa2f35c 100644
--- a/src/main/include/log4cxx/pattern/literalpatternconverter.h
+++ b/src/main/include/log4cxx/pattern/literalpatternconverter.h
@@ -39,10 +39,7 @@ namespace pattern
  */
 class LOG4CXX_EXPORT LiteralPatternConverter : public LoggingEventPatternConverter
 {
-		/**
-		 * String literal.
-		 */
-		const LogString literal;
+	struct LiteralPatternConverterPrivate;
 
 		/**
 		 * Create a new instance.
diff --git a/src/main/include/log4cxx/pattern/loggingeventpatternconverter.h b/src/main/include/log4cxx/pattern/loggingeventpatternconverter.h
index ace6542..667c78d 100644
--- a/src/main/include/log4cxx/pattern/loggingeventpatternconverter.h
+++ b/src/main/include/log4cxx/pattern/loggingeventpatternconverter.h
@@ -45,6 +45,8 @@ class LOG4CXX_EXPORT LoggingEventPatternConverter : public PatternConverter
 		LoggingEventPatternConverter(
 			const LogString& name, const LogString& style);
 
+		LoggingEventPatternConverter(std::unique_ptr<PatternConverterPrivate> priv);
+
 	public:
 		DECLARE_LOG4CXX_PATTERN(LoggingEventPatternConverter)
 		BEGIN_LOG4CXX_CAST_MAP()
diff --git a/src/main/include/log4cxx/pattern/namepatternconverter.h b/src/main/include/log4cxx/pattern/namepatternconverter.h
index fbc49fc..b38381e 100644
--- a/src/main/include/log4cxx/pattern/namepatternconverter.h
+++ b/src/main/include/log4cxx/pattern/namepatternconverter.h
@@ -35,10 +35,7 @@ namespace pattern
  */
 class LOG4CXX_EXPORT NamePatternConverter : public LoggingEventPatternConverter
 {
-		/**
-		 * Abbreviator.
-		 */
-		const NameAbbreviatorPtr abbreviator;
+	struct NamePatternConverterPrivate;
 
 	public:
 		DECLARE_LOG4CXX_PATTERN(NamePatternConverter)
diff --git a/src/main/include/log4cxx/pattern/patternconverter.h b/src/main/include/log4cxx/pattern/patternconverter.h
index bebca41..a5e17b7 100644
--- a/src/main/include/log4cxx/pattern/patternconverter.h
+++ b/src/main/include/log4cxx/pattern/patternconverter.h
@@ -49,26 +49,24 @@ typedef std::vector<LogString> OptionsList;
  */
 class LOG4CXX_EXPORT PatternConverter : public virtual log4cxx::helpers::Object
 {
+	protected:
+		struct PatternConverterPrivate;
+		std::unique_ptr<PatternConverterPrivate> m_priv;
 
 		/**
-		 * Converter name.
-		 */
-		const LogString name;
-
-		/**
-		 * Converter style name.
+		 * Use this constructor when you have a subclass that has its own private data
+		 * @param priv
 		 */
-		const LogString style;
-
+		PatternConverter(std::unique_ptr<PatternConverterPrivate> priv);
 
-	protected:
 		/**
-		 * Create a new pattern converter.
+		 * Create a new pattern converter.  Use this constructor when you have a subclass
+		 * that does not have any private data.
 		 * @param name name for pattern converter.
 		 * @param style CSS style for formatted output.
 		 */
 		PatternConverter(const LogString& name,
-			const LogString& style);
+						 const LogString& style);
 
 		virtual ~PatternConverter();
 
diff --git a/src/main/include/log4cxx/pattern/propertiespatternconverter.h b/src/main/include/log4cxx/pattern/propertiespatternconverter.h
index 26bf915..2416f28 100644
--- a/src/main/include/log4cxx/pattern/propertiespatternconverter.h
+++ b/src/main/include/log4cxx/pattern/propertiespatternconverter.h
@@ -39,10 +39,7 @@ namespace pattern
 class LOG4CXX_EXPORT PropertiesPatternConverter
 	: public LoggingEventPatternConverter
 {
-		/**
-		 * Name of property to output.
-		 */
-		const LogString option;
+	struct PropertiesPatternConverterPrivate;
 
 		/**
 		 * Private constructor.
diff --git a/src/main/include/log4cxx/pattern/throwableinformationpatternconverter.h b/src/main/include/log4cxx/pattern/throwableinformationpatternconverter.h
index 8599382..f8ad5ad 100644
--- a/src/main/include/log4cxx/pattern/throwableinformationpatternconverter.h
+++ b/src/main/include/log4cxx/pattern/throwableinformationpatternconverter.h
@@ -37,10 +37,7 @@ namespace pattern
 class LOG4CXX_EXPORT ThrowableInformationPatternConverter
 	: public LoggingEventPatternConverter
 {
-		/**
-		 * If "short", only first line of throwable report will be formatted.
-		 */
-		const bool shortReport;
+	struct ThrowableInformationPatternConverterPrivate;
 
 		/**
 		 * Private constructor.
diff --git a/src/main/cpp/patternconverter.cpp b/src/main/include/log4cxx/private/patternconverter_priv.h
similarity index 54%
copy from src/main/cpp/patternconverter.cpp
copy to src/main/include/log4cxx/private/patternconverter_priv.h
index d0add75..b01197b 100644
--- a/src/main/cpp/patternconverter.cpp
+++ b/src/main/include/log4cxx/private/patternconverter_priv.h
@@ -14,42 +14,36 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#if defined(_MSC_VER)
-	#pragma warning ( disable: 4231 4251 4275 4786 )
-#endif
-
-#include <log4cxx/logstring.h>
+#ifndef LOG4CXX_PATTERNCONVERTER_PRIVATE_H
+#define LOG4CXX_PATTERNCONVERTER_PRIVATE_H
 #include <log4cxx/pattern/patternconverter.h>
-#include <log4cxx/helpers/transcoder.h>
-
-using namespace log4cxx;
-using namespace log4cxx::pattern;
-
-IMPLEMENT_LOG4CXX_OBJECT(PatternConverter)
 
-PatternConverter::PatternConverter(
-	const LogString& name1, const LogString& style1) :
-	name(name1), style(style1)
+namespace log4cxx
 {
-}
-
-PatternConverter::~PatternConverter()
+namespace pattern
 {
-}
 
-LogString PatternConverter::getName() const
-{
-	return name;
-}
+/**
+ * Create a new pattern converter.
+ * @param name name for pattern converter.
+ * @param style CSS style for formatted output.
+ */
+struct PatternConverter::PatternConverterPrivate {
+    PatternConverterPrivate( const LogString& _name, const LogString& _style ) :
+        name(_name),
+        style(_style){}
+
+    /**
+     * Converter name.
+     */
+    const LogString name;
+    /**
+     * Converter style name.
+     */
+    const LogString style;
+};
 
-LogString PatternConverter::getStyleClass(const log4cxx::helpers::ObjectPtr& /* e */) const
-{
-	return style;
 }
-
-void PatternConverter::append(LogString& toAppendTo, const std::string& src)
-{
-	LOG4CXX_DECODE_CHAR(decoded, src);
-	toAppendTo.append(decoded);
 }
 
+#endif /* LOG4CXX_PATTERNCONVERTER_PRIVATE_H */