You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ts...@apache.org on 2020/06/06 12:43:57 UTC

[logging-log4cxx] 02/05: Update to apply astyle Remove C++11 initializer and emplace.

This is an automated email from the ASF dual-hosted git repository.

tschoening pushed a commit to branch ghpr_24_mapfilter
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git

commit 147c94ce330040d42906c47b4859f0f4f1064045
Author: Patrick Mills <pa...@cerberusftp.com>
AuthorDate: Wed Jun 3 10:59:35 2020 -0400

    Update to apply astyle
    Remove C++11 initializer and emplace.
---
 src/main/cpp/mapfilter.cpp                  | 40 +++++++++++++++++------------
 src/main/include/log4cxx/filter/mapfilter.h | 10 ++++----
 src/test/cpp/filter/mapfiltertest.cpp       | 38 +++++++++++++--------------
 3 files changed, 48 insertions(+), 40 deletions(-)

diff --git a/src/main/cpp/mapfilter.cpp b/src/main/cpp/mapfilter.cpp
index da03464..d527a1a 100644
--- a/src/main/cpp/mapfilter.cpp
+++ b/src/main/cpp/mapfilter.cpp
@@ -32,48 +32,56 @@ void MapFilter::setOption(const LogString& option,
 	const LogString& value)
 {
 
-	if (StringHelper::equalsIgnoreCase(option, LOG4CXX_STR("ACCEPTONMATCH"), LOG4CXX_STR("acceptonmatch"))) {
-
+	if (StringHelper::equalsIgnoreCase(option, LOG4CXX_STR("ACCEPTONMATCH"), LOG4CXX_STR("acceptonmatch")))
+	{
 		acceptOnMatch = OptionConverter::toBoolean(value, acceptOnMatch);
 	}
-	else if (StringHelper::equalsIgnoreCase(option, LOG4CXX_STR("OPERATOR"), LOG4CXX_STR("operator"))) {
-
+	else if (StringHelper::equalsIgnoreCase(option, LOG4CXX_STR("OPERATOR"), LOG4CXX_STR("operator")))
+	{
 		mustMatchAll = StringHelper::equalsIgnoreCase(value, LOG4CXX_STR("AND"), LOG4CXX_STR("and")) ? true : false;
 	}
-	else if (!option.empty() && !value.empty()) {
-
-		mapKeyValList.emplace(option, value);
+	else if (!option.empty() && !value.empty())
+	{
+		mapKeyValList[option] = value;
 	}
 }
 
 Filter::FilterDecision MapFilter::decide(
 	const log4cxx::spi::LoggingEventPtr& event) const
 {
-	if (mapKeyValList.empty()) {
+	if (mapKeyValList.empty())
+	{
 		return Filter::NEUTRAL;
 	}
 
-	bool	matched = true;
-	for (auto it = mapKeyValList.cbegin(); it != mapKeyValList.cend(); ++it) {
+	bool    matched = true;
+
+	for (auto it = mapKeyValList.cbegin(); it != mapKeyValList.cend(); ++it)
+	{
 		LogString curval;
 		event->getMDC(it->first, curval);
 
-		if (curval.empty() || curval != it->second) {
+		if (curval.empty() || curval != it->second)
+		{
 			matched = false;
 		}
-		else {
+		else
+		{
 			matched = true;
 		}
-			
-		if (mustMatchAll != matched) {
+
+		if (mustMatchAll != matched)
+		{
 			break;
 		}
 	}
 
-	if (acceptOnMatch)	{
+	if (acceptOnMatch)
+	{
 		return matched ? Filter::ACCEPT : Filter::DENY;
 	}
-	else {
+	else
+	{
 		return matched ? Filter::DENY : Filter::ACCEPT;
 	}
 }
diff --git a/src/main/include/log4cxx/filter/mapfilter.h b/src/main/include/log4cxx/filter/mapfilter.h
index 5bc37b9..2745344 100644
--- a/src/main/include/log4cxx/filter/mapfilter.h
+++ b/src/main/include/log4cxx/filter/mapfilter.h
@@ -32,14 +32,14 @@ namespace filter
  * A Filter that operates on a Map.
  */
 
- using keyvallist = std::map<LogString, LogString>;
+using KeyValList = std::map<LogString, LogString>;
 
 class LOG4CXX_EXPORT MapFilter: public log4cxx::spi::Filter
 {
 	private:
-		bool acceptOnMatch{true};
-		bool mustMatchAll{false};	// true = AND; false = OR
-		keyvallist mapKeyValList;
+		bool acceptOnMatch = true;
+		bool mustMatchAll = false;  // true = AND; false = OR
+		KeyValList mapKeyValList;
 
 	public:
 		DECLARE_LOG4CXX_OBJECT(MapFilter)
@@ -48,7 +48,7 @@ class LOG4CXX_EXPORT MapFilter: public log4cxx::spi::Filter
 		LOG4CXX_CAST_ENTRY_CHAIN(log4cxx::spi::Filter)
 		END_LOG4CXX_CAST_MAP()
 
-		MapFilter(){}
+		MapFilter() {}
 
 		/**
 		Set options
diff --git a/src/test/cpp/filter/mapfiltertest.cpp b/src/test/cpp/filter/mapfiltertest.cpp
index b34f57c..bfb9e53 100644
--- a/src/test/cpp/filter/mapfiltertest.cpp
+++ b/src/test/cpp/filter/mapfiltertest.cpp
@@ -124,35 +124,35 @@ public:
 		Pool p;
 		filter->activateOptions(p);
 
-		filter->setMustMatchAll(true);		// AND T/F
-		LOGUNIT_ASSERT_EQUAL(Filter::DENY, filter->decide(event));		// does not match second
+		filter->setMustMatchAll(true);      // AND T/F
+		LOGUNIT_ASSERT_EQUAL(Filter::DENY, filter->decide(event));      // does not match second
 
-		filter->setMustMatchAll(false);	// OR T/F
-		LOGUNIT_ASSERT_EQUAL(Filter::ACCEPT, filter->decide(event));	// matches first
+		filter->setMustMatchAll(false); // OR T/F
+		LOGUNIT_ASSERT_EQUAL(Filter::ACCEPT, filter->decide(event));    // matches first
 
-		filter->setKeyValue(LOG4CXX_STR("my.name"), LOG4CXX_STR("Test"));	
+		filter->setKeyValue(LOG4CXX_STR("my.name"), LOG4CXX_STR("Test"));
 
-		filter->setMustMatchAll(true);		// AND T/T
-		LOGUNIT_ASSERT_EQUAL(Filter::ACCEPT, filter->decide(event));	// matches all
+		filter->setMustMatchAll(true);      // AND T/T
+		LOGUNIT_ASSERT_EQUAL(Filter::ACCEPT, filter->decide(event));    // matches all
 
-		filter->setMustMatchAll(false);	// OR T/T
-		LOGUNIT_ASSERT_EQUAL(Filter::ACCEPT, filter->decide(event));	// matches first
+		filter->setMustMatchAll(false); // OR T/T
+		LOGUNIT_ASSERT_EQUAL(Filter::ACCEPT, filter->decide(event));    // matches first
 
-		filter->setKeyValue(LOG4CXX_STR("my.ip"), LOG4CXX_STR("localhost"));	
+		filter->setKeyValue(LOG4CXX_STR("my.ip"), LOG4CXX_STR("localhost"));
 
-		filter->setMustMatchAll(true);		// AND F/T
-		LOGUNIT_ASSERT_EQUAL(Filter::DENY, filter->decide(event));		// does not match first
+		filter->setMustMatchAll(true);      // AND F/T
+		LOGUNIT_ASSERT_EQUAL(Filter::DENY, filter->decide(event));      // does not match first
 
-		filter->setMustMatchAll(false);	// OR F/T
-		LOGUNIT_ASSERT_EQUAL(Filter::ACCEPT, filter->decide(event));	// matches second
+		filter->setMustMatchAll(false); // OR F/T
+		LOGUNIT_ASSERT_EQUAL(Filter::ACCEPT, filter->decide(event));    // matches second
 
-		filter->setKeyValue(LOG4CXX_STR("my.name"), LOG4CXX_STR("Unkonwn"));	
+		filter->setKeyValue(LOG4CXX_STR("my.name"), LOG4CXX_STR("Unkonwn"));
 
-		filter->setMustMatchAll(true);		// AND F/F
-		LOGUNIT_ASSERT_EQUAL(Filter::DENY, filter->decide(event));		// does not match first
+		filter->setMustMatchAll(true);      // AND F/F
+		LOGUNIT_ASSERT_EQUAL(Filter::DENY, filter->decide(event));      // does not match first
 
-		filter->setMustMatchAll(false);	// OR F/F
-		LOGUNIT_ASSERT_EQUAL(Filter::DENY, filter->decide(event));		// matches none
+		filter->setMustMatchAll(false); // OR F/F
+		LOGUNIT_ASSERT_EQUAL(Filter::DENY, filter->decide(event));      // matches none
 	}
 
 };