Hazelcast C++ Client
Hazelcast C++ Client Library
item_listener.h
1 /*
2  * Copyright (c) 2008-2021, Hazelcast, Inc. All Rights Reserved.
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 #pragma once
17 
18 #include <utility>
19 #include <functional>
20 
21 #include "hazelcast/util/export.h"
22 #include "hazelcast/util/noop.h"
23 #include "hazelcast/util/type_traits.h"
24 
25 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
26 #pragma warning(push)
27 #pragma warning(disable: 4251) //for dll export
28 #endif
29 
30 namespace hazelcast {
31  namespace client {
32  class item_event;
33 
34  namespace impl {
35  template<typename> class item_event_handler;
36  }
37 
51  class HAZELCAST_API item_listener final {
52  public:
58  template<typename Handler,
59  typename = util::enable_if_rvalue_ref_t<Handler &&>>
60  item_listener &on_added(Handler &&h) & {
61  added_ = std::forward<Handler>(h);
62  return *this;
63  }
64 
68  template<typename Handler,
69  typename = util::enable_if_rvalue_ref_t<Handler &&>>
70  item_listener &&on_added(Handler &&h) && {
71  on_added(std::forward<Handler>(h));
72  return std::move(*this);
73  }
74 
79  template<typename Handler>
80  item_listener &on_removed(Handler &&h) & {
81  removed_ = std::forward<Handler>(h);
82  return *this;
83  }
84 
88  template<typename Handler>
89  item_listener &&on_removed(Handler &&h) && {
90  on_removed(std::forward<Handler>(h));
91  return std::move(*this);
92  }
93 
94  private:
95  using HandlerType = std::function<void(item_event &&)>;
96  HandlerType added_ = util::noop<item_event &&>,
97  removed_ = util::noop<item_event &&>;
98 
99  template<typename>
100  friend class impl::item_event_handler;
101  };
102  }
103 }
104 
105 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
106 #pragma warning(pop)
107 #endif
Item listener for IQueue, ISet and IList.
Definition: item_listener.h:51
item_listener && on_added(Handler &&h) &&
Definition: item_listener.h:70
item_listener & on_added(Handler &&h) &
Set an handler function to be invoked when an item is added.
Definition: item_listener.h:60
item_listener && on_removed(Handler &&h) &&
Definition: item_listener.h:89
item_listener & on_removed(Handler &&h) &
Set an handler function to be invoked when an item is removed.
Definition: item_listener.h:80