client-cpp  0.10.0
TransportProtocolId.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 TRANSPORT_PROTOCOL_ID_HPP_
18 #define TRANSPORT_PROTOCOL_ID_HPP_
19 
20 #include <cstdint>
21 
22 #include "kaa/gen/EndpointGen.hpp"
23 
24 namespace kaa {
25 
26 /*
27  * An identifier used to uniquely represent a transport protocol.
28  */
30 {
31 public:
32  TransportProtocolId(const std::int32_t& id, const std::int32_t& version)
33  : id_(id), version_(version) {}
34 
35  TransportProtocolId(const ProtocolVersionPair& protocolId)
36  : id_(protocolId.id), version_(protocolId.version) {}
37 
38  std::int32_t getId() const {
39  return id_;
40  }
41 
42  std::int32_t getVersion() const {
43  return version_;
44  }
45 
46  bool operator==(const TransportProtocolId& protocolId) const {
47  return (id_ == protocolId.id_ && version_ == protocolId.version_);
48  }
49 
50  bool operator!=(const TransportProtocolId& protocolId) const {
51  return !(*this == protocolId);
52  }
53 
54  bool operator<(const TransportProtocolId& protocolId) const {
55  return (hashCode() < protocolId.hashCode());
56  }
57 
58  bool operator>(const TransportProtocolId& protocolId) const {
59  return (hashCode() > protocolId.hashCode());
60  }
61 
62 private:
63  std::uint32_t hashCode() const {
64  const std::uint32_t prime = 31;
65 
66  std::uint32_t hashCode = 1;
67  hashCode = prime * hashCode + id_;
68  hashCode = prime * hashCode + version_;
69 
70  return hashCode;
71  }
72 
73 private:
74  std::int32_t id_;
75  std::int32_t version_;
76 };
77 
78 } /* namespace kaa */
79 
80 #endif /* TRANSPORT_PROTOCOL_ID_HPP_ */
TransportProtocolId(const ProtocolVersionPair &protocolId)
bool operator!=(const TransportProtocolId &protocolId) const
std::int32_t getId() const
bool operator<(const TransportProtocolId &protocolId) const
bool operator==(const TransportProtocolId &protocolId) const
std::int32_t getVersion() const
TransportProtocolId(const std::int32_t &id, const std::int32_t &version)
bool operator>(const TransportProtocolId &protocolId) const