client-cpp  0.10.0
RecordFuture.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014-2016 CyberVision, Inc.
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 
17 #ifndef RECORDFUTURE_HPP_
18 #define RECORDFUTURE_HPP_
19 
20 #include <future>
21 #include <atomic>
22 
23 #include "kaa/log/RecordInfo.hpp"
24 
25 namespace kaa {
26 
27 class RecordFuture {
28 public:
29  RecordFuture(std::future<RecordInfo>&& future)
30  : future_(std::move(future)), recordFutureId_(recordFutureCounter++) {}
31 
32  RecordFuture(RecordFuture&& recordFuture)
33  : future_(std::move(recordFuture.future_)), recordFutureId_(recordFuture.recordFutureId_) {}
34 
36  return RecordFuture(std::move(recordFuture));
37  }
38 
39  RecordFuture(const RecordFuture&) = delete;
40  RecordFuture operator=(const RecordFuture&) = delete;
41 
42  std::size_t getRecordFutureId() const {
43  return recordFutureId_;
44  }
45 
46  bool operator<(const RecordFuture& recordFuture) const {
47  return recordFutureId_ < recordFuture.recordFutureId_;
48  }
49 
50  bool operator==(const RecordFuture& recordFuture) const {
51  return recordFutureId_ == recordFuture.recordFutureId_;
52  }
53 
54  bool operator!=(const RecordFuture& recordFuture) const {
55  return recordFutureId_ != recordFuture.recordFutureId_;
56  }
57 
58  /*
59  * START: Partial future interface.
60  */
61  RecordInfo get() {
62  return future_.get();
63  }
64 
65  void wait() const {
66  future_.wait();
67  }
68 
69  /*
70  * END: Partial future interface.
71  */
72 
73 private:
74  typedef std::atomic_size_t RecordFutureCounterType;
75  static RecordFutureCounterType recordFutureCounter;
76 
77 private:
78  std::future<RecordInfo> future_;
79  std::size_t recordFutureId_;
80 };
81 
82 } /* namespace kaa */
83 
84 namespace std {
85 template<>
86 struct hash<kaa::RecordFuture>
87 {
89  typedef std::size_t result_type;
91  {
92  return s.getRecordFutureId();
93  }
94 };
95 }
96 
97 #endif /* RECORDFUTURE_HPP_ */
RecordFuture(std::future< RecordInfo > &&future)
RecordFuture(RecordFuture &&recordFuture)
bool operator!=(const RecordFuture &recordFuture) const
result_type operator()(argument_type const &s) const
bool operator<(const RecordFuture &recordFuture) const
void wait() const
kaa::RecordFuture argument_type
bool operator==(const RecordFuture &recordFuture) const
Describes unique log record delivery info.
Definition: RecordInfo.hpp:30
RecordFuture operator=(RecordFuture &&recordFuture)
std::size_t getRecordFutureId() const