BlackWhitelist.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <ostream>
4 #include <set>
5 #include <string>
6 
7 namespace armarx
8 {
9 
10  /**
11  * @brief A combination of blacklist and whitelist.
12  *
13  * An element is included if
14  * (1) it is not in the blacklist, and
15  * (2) the whitelist is empty or it contains the element.
16  */
17  template <typename Key>
19  {
20  public:
21  /// Construct an empty blacklist and whitelist.
22  BlackWhitelist() = default;
23 
24  /**
25  * An element is included if
26  * (1) it is not in the blacklist, and
27  * (2) the whitelist is empty or it contains the element.
28  */
29  bool
30  isIncluded(const Key& element) const
31  {
32  return !isExcluded(element);
33  }
34 
35  /**
36  * An element is excluded if
37  * (1) it is in the blacklist, or
38  * (2) it is not in the non-empty whitelist
39  */
40  bool
41  isExcluded(const Key& element) const
42  {
43  return black.count(element) > 0 || (!white.empty() && white.count(element) == 0);
44  }
45 
46  /// Elements in this list are always excluded.
47  std::set<Key> black;
48  /// If not empty, only these elements are included.
49  std::set<Key> white;
50 
51  template <class K>
52  friend std::ostream& operator<<(std::ostream& os, const BlackWhitelist<K>& bw);
53  };
54 
55  template <class K>
56  std::ostream&
57  operator<<(std::ostream& os, const BlackWhitelist<K>& bw)
58  {
59  os << "Blacklist (" << bw.black.size() << "): ";
60  for (const auto& e : bw.black)
61  {
62  os << "\n\t" << e;
63  }
64  os << "\n";
65 
66  os << "Whitelist (" << bw.white.size() << "):";
67  for (const auto& e : bw.white)
68  {
69  os << "\n\t" << e;
70  }
71  return os;
72  }
73 
75 
76 } // namespace armarx
armarx::BlackWhitelist::operator<<
friend std::ostream & operator<<(std::ostream &os, const BlackWhitelist< K > &bw)
Definition: BlackWhitelist.h:57
armarx::BlackWhitelist::isExcluded
bool isExcluded(const Key &element) const
An element is excluded if (1) it is in the blacklist, or (2) it is not in the non-empty whitelist.
Definition: BlackWhitelist.h:41
armarx::BlackWhitelist::black
std::set< Key > black
Elements in this list are always excluded.
Definition: BlackWhitelist.h:47
armarx::BlackWhitelist::isIncluded
bool isIncluded(const Key &element) const
An element is included if (1) it is not in the blacklist, and (2) the whitelist is empty or it contai...
Definition: BlackWhitelist.h:30
armarx::BlackWhitelist::BlackWhitelist
BlackWhitelist()=default
Construct an empty blacklist and whitelist.
armarx::BlackWhitelist::white
std::set< Key > white
If not empty, only these elements are included.
Definition: BlackWhitelist.h:49
armarx::BlackWhitelist
A combination of blacklist and whitelist.
Definition: BlackWhitelist.h:18
armarx::operator<<
std::ostream & operator<<(std::ostream &os, const PythonApplicationManager::Paths &paths)
Definition: PythonApplicationManager.cpp:285
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27