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