Hazelcast C++ Client
Hazelcast C++ Client Library
item_listener.h
1 /*
2  * Copyright (c) 2008-2022, 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>
36 class item_event_handler;
37 }
38 
51 class HAZELCAST_API item_listener final
52 {
53 public:
59  template<typename Handler,
60  typename = util::enable_if_rvalue_ref_trait<Handler&&>>
61  item_listener& on_added(Handler&& h) &
62  {
63  added_ = std::forward<Handler>(h);
64  return *this;
65  }
66 
70  template<typename Handler,
71  typename = util::enable_if_rvalue_ref_trait<Handler&&>>
72  item_listener&& on_added(Handler&& h) &&
73  {
74  on_added(std::forward<Handler>(h));
75  return std::move(*this);
76  }
77 
83  template<typename Handler>
84  item_listener& on_removed(Handler&& h) &
85  {
86  removed_ = std::forward<Handler>(h);
87  return *this;
88  }
89 
93  template<typename Handler>
94  item_listener&& on_removed(Handler&& h) &&
95  {
96  on_removed(std::forward<Handler>(h));
97  return std::move(*this);
98  }
99 
100 private:
101  using HandlerType = std::function<void(item_event&&)>;
102  HandlerType added_ = util::noop<item_event&&>,
103  removed_ = util::noop<item_event&&>;
104 
105  template<typename>
106  friend class impl::item_event_handler;
107 };
108 } // namespace client
109 } // namespace hazelcast
110 
111 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
112 #pragma warning(pop)
113 #endif
Item listener for IQueue, ISet and IList.
Definition: item_listener.h:52
item_listener && on_added(Handler &&h) &&
Definition: item_listener.h:72
item_listener & on_added(Handler &&h) &
Set an handler function to be invoked when an item is added.
Definition: item_listener.h:61
item_listener && on_removed(Handler &&h) &&
Definition: item_listener.h:94
item_listener & on_removed(Handler &&h) &
Set an handler function to be invoked when an item is removed.
Definition: item_listener.h:84