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:59 UTC
[logging-log4cxx] 04/05: Support non-C++11-compilers like legacy
Borland bcc32.
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 85a47e80259f33c4a2d3603e40d22a1f60f67ace
Author: Thorsten Schöning <ts...@am-soft.de>
AuthorDate: Sat Jun 6 14:42:02 2020 +0200
Support non-C++11-compilers like legacy Borland bcc32.
---
src/main/cpp/mapfilter.cpp | 16 ++++++++++------
src/main/include/log4cxx/filter/mapfilter.h | 25 ++++++++++++++-----------
2 files changed, 24 insertions(+), 17 deletions(-)
diff --git a/src/main/cpp/mapfilter.cpp b/src/main/cpp/mapfilter.cpp
index d527a1a..09e38ca 100644
--- a/src/main/cpp/mapfilter.cpp
+++ b/src/main/cpp/mapfilter.cpp
@@ -28,10 +28,14 @@ using namespace log4cxx::helpers;
IMPLEMENT_LOG4CXX_OBJECT(MapFilter)
-void MapFilter::setOption(const LogString& option,
- const LogString& value)
+MapFilter::MapFilter() : acceptOnMatch(true), mustMatchAll(false)
{
+}
+
+void MapFilter::setOption( const LogString& option,
+ const LogString& value)
+{
if (StringHelper::equalsIgnoreCase(option, LOG4CXX_STR("ACCEPTONMATCH"), LOG4CXX_STR("acceptonmatch")))
{
acceptOnMatch = OptionConverter::toBoolean(value, acceptOnMatch);
@@ -42,21 +46,21 @@ void MapFilter::setOption(const LogString& option,
}
else if (!option.empty() && !value.empty())
{
- mapKeyValList[option] = value;
+ keyVals[option] = value;
}
}
Filter::FilterDecision MapFilter::decide(
const log4cxx::spi::LoggingEventPtr& event) const
{
- if (mapKeyValList.empty())
+ if (keyVals.empty())
{
return Filter::NEUTRAL;
}
- bool matched = true;
+ bool matched = true;
- for (auto it = mapKeyValList.cbegin(); it != mapKeyValList.cend(); ++it)
+ for (KeyVals::const_iterator it = keyVals.begin(); it != keyVals.end(); ++it)
{
LogString curval;
event->getMDC(it->first, curval);
diff --git a/src/main/include/log4cxx/filter/mapfilter.h b/src/main/include/log4cxx/filter/mapfilter.h
index f4653e0..4f03616 100644
--- a/src/main/include/log4cxx/filter/mapfilter.h
+++ b/src/main/include/log4cxx/filter/mapfilter.h
@@ -28,18 +28,18 @@ namespace log4cxx
{
namespace filter
{
+
/**
* A Filter that operates on a Map.
*/
-
class LOG4CXX_EXPORT MapFilter: public log4cxx::spi::Filter
{
- typedef std::map < LogString, LogString > KeyValList;
+ typedef std::map < LogString, LogString > KeyVals;
private:
- bool acceptOnMatch = true;
- bool mustMatchAll = false; // true = AND; false = OR
- KeyValList mapKeyValList;
+ bool acceptOnMatch;
+ bool mustMatchAll; // true = AND; false = OR
+ KeyVals keyVals;
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
@@ -58,14 +58,15 @@ class LOG4CXX_EXPORT MapFilter: public log4cxx::spi::Filter
inline void setKeyValue(const LogString& strKey, const LogString& strValue)
{
- this->mapKeyValList[strKey] = strValue;
+ this->keyVals[strKey] = strValue;
}
inline const LogString& getValue(const LogString& strKey) const
{
- static const LogString empty{};
- auto it = mapKeyValList.find(strKey);
- return (it != mapKeyValList.end() ? it->second : empty);
+ static const LogString empty;
+ const KeyVals::const_iterator it(this->keyVals.find(strKey));
+
+ return (it != keyVals.end() ? it->second : empty);
}
inline void setAcceptOnMatch(bool acceptOnMatch1)
@@ -94,8 +95,10 @@ class LOG4CXX_EXPORT MapFilter: public log4cxx::spi::Filter
*/
FilterDecision decide(const spi::LoggingEventPtr& event) const;
}; // class MapFilter
+
LOG4CXX_PTR_DEF(MapFilter);
-} // namespace filter
+
+} // namespace filter
} // namespace log4cxx
#if defined(_MSC_VER)