olp-cpp-sdk  1.22.0
FilterGroup.h
1 /*
2  * Copyright (C) 2019-2021 HERE Europe B.V.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * SPDX-License-Identifier: Apache-2.0
17  * License-Filename: LICENSE
18  */
19 
20 #pragma once
21 
22 #include <istream>
23 #include <string>
24 #include <unordered_map>
25 #include <utility>
26 
27 #include <boost/none.hpp>
28 #include <boost/optional.hpp>
29 
30 #include <olp/core/CoreApi.h>
31 #include <olp/core/logging/Level.h>
32 
33 namespace olp {
34 namespace logging {
40 class CORE_API FilterGroup {
41  public:
42  inline FilterGroup();
43 
45  FilterGroup(const FilterGroup&) = default;
46 
48  FilterGroup& operator=(const FilterGroup&) = default;
49 
51  inline FilterGroup(FilterGroup&& other) noexcept;
52 
54  inline FilterGroup& operator=(FilterGroup&& other) noexcept;
55 
61  inline boost::optional<Level> getLevel() const;
62 
68  inline FilterGroup& setLevel(Level level);
69 
76  inline FilterGroup& clearLevel();
77 
85  inline boost::optional<Level> getLevel(const std::string& tag) const;
86 
93  inline FilterGroup& setLevel(Level level, const std::string& tag);
94 
101  inline FilterGroup& clearLevel(const std::string& tag);
102 
106  inline FilterGroup& clear();
107 
116  bool load(const std::string& fileName);
117 
142  bool load(std::istream& stream);
143 
151  static boost::optional<Level> stringToLevel(const std::string& levelStr);
152 
153  private:
154  friend class Log;
155 
156  boost::optional<Level> m_defaultLevel;
157  std::unordered_map<std::string, Level> m_tagLevels;
158 };
159 
160 inline FilterGroup::FilterGroup() : m_defaultLevel(boost::none) {}
161 
162 inline FilterGroup::FilterGroup(FilterGroup&& other) noexcept
163  : m_defaultLevel(std::move(other.m_defaultLevel)),
164  m_tagLevels(std::move(other.m_tagLevels)) {}
165 
166 inline FilterGroup& FilterGroup::operator=(FilterGroup&& other) noexcept {
167  m_defaultLevel = std::move(other.m_defaultLevel);
168  m_tagLevels = std::move(other.m_tagLevels);
169  return *this;
170 }
171 
172 inline boost::optional<Level> FilterGroup::getLevel() const {
173  return m_defaultLevel;
174 }
175 
176 inline FilterGroup& FilterGroup::setLevel(Level level) {
177  m_defaultLevel = level;
178  return *this;
179 }
180 
182  m_defaultLevel = boost::none;
183  return *this;
184 }
185 
186 inline boost::optional<Level> FilterGroup::getLevel(
187  const std::string& tag) const {
188  auto foundIter = m_tagLevels.find(tag);
189  if (foundIter == m_tagLevels.end()) return boost::none;
190  return foundIter->second;
191 }
192 
193 inline FilterGroup& FilterGroup::setLevel(Level level, const std::string& tag) {
194  m_tagLevels[tag] = level;
195  return *this;
196 }
197 
198 inline FilterGroup& FilterGroup::clearLevel(const std::string& tag) {
199  m_tagLevels.erase(tag);
200  return *this;
201 }
202 
204  m_defaultLevel = boost::none;
205  m_tagLevels.clear();
206  return *this;
207 }
208 
209 } // namespace logging
210 } // namespace olp
Groups together log levels for different tags.
Definition: FilterGroup.h:40
FilterGroup & clearLevel()
Clears the default log level.
Definition: FilterGroup.h:181
FilterGroup & operator=(const FilterGroup &)=default
The default copy assignment operator.
bool load(const std::string &fileName)
Loads the filter group from a file.
static boost::optional< Level > stringToLevel(const std::string &levelStr)
Converts the string log level to the enum level format.
bool load(std::istream &stream)
Loads the filter group from a stream.
FilterGroup(const FilterGroup &)=default
The default copy constructor.
FilterGroup & setLevel(Level level)
Sets the default log level.
Definition: FilterGroup.h:176
FilterGroup & clear()
Clears the filter group.
Definition: FilterGroup.h:203
boost::optional< Level > getLevel() const
Gets the default log level.
Definition: FilterGroup.h:172
A primary interface for log messages.
Definition: Log.h:432
Rules all the other namespaces.
Definition: AppleSignInProperties.h:24