identt
HelpQuery.hpp
Go to the documentation of this file.
1 
33 #ifndef _IDENTT_QUERY_HELPQUERY_HPP_
34 #define _IDENTT_QUERY_HELPQUERY_HPP_
35 
36 #include <memory>
37 #include <string>
38 #include <vector>
39 #include <algorithm>
40 #include <boost/thread/locks.hpp>
41 #include <boost/thread/shared_mutex.hpp>
42 
43 namespace identt {
44 namespace query {
45 
46 class HelpQuery {
47 public:
48  struct HelpT {
49  const unsigned int scope;
50  const std::string route;
51  const std::vector<std::string> desc;
52  };
53 
54  using pointer=std::shared_ptr<HelpQuery>;
55  using LockT = boost::shared_mutex;
56  using WriteLockT = boost::unique_lock< LockT >;
57  using ReadLockT = boost::shared_lock< LockT >;
58  using HelpListT = std::vector<HelpT>;
59 
64  HelpQuery() = default;
65 
66 
70  HelpQuery(const HelpQuery&) = delete;
71  HelpQuery& operator=(const HelpQuery&) = delete;
72 
76  virtual ~HelpQuery () {}
77 
87  void add(HelpT h)
88  {
89  WriteLockT lock (shared_lock);
90  helplist.emplace_back(h);
91  }
92 
102  HelpListT get(const unsigned int scope)
103  {
104  HelpListT hl;
105  ReadLockT lock (shared_lock);
106  std::copy_if( helplist.begin() , helplist.end(), std::back_inserter(hl), [scope](const HelpT& h) {
107  return (h.scope & scope);
108  });
109  return hl;
110  }
111 
112 private:
113  HelpListT helplist;
114  LockT shared_lock;
115 
116 
117 };
118 
119 } // namespace query
120 } // namespace identt
121 #endif /* _IDENTT_QUERY_HELPQUERY_HPP_ */
Definition: HelpQuery.hpp:46
HelpQuery()=default
constructor
Definition: CryptoBase.hpp:49
virtual ~HelpQuery()
destructor
Definition: HelpQuery.hpp:76
void add(HelpT h)
add : add one HelpT item
Definition: HelpQuery.hpp:87
Definition: HelpQuery.hpp:48