m2etis  0.4
Key.h
Go to the documentation of this file.
1 /*
2  Copyright (2016) Michael Baer, Daniel Bonrath, 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 
22 #ifndef __M2ETIS_MESSAGE_KEY_H__
23 #define __M2ETIS_MESSAGE_KEY_H__
24 
25 #include <string>
26 #include <vector>
27 
28 #include "boost/serialization/base_object.hpp"
29 
30 namespace m2etis {
31 namespace message {
32 
40  template<class KeyProvider>
41  class Key : public KeyProvider {
42  public:
46  Key() : KeyProvider() {
47  }
48 
53  Key(const Key & rval) {
54  KeyProvider::setKey(rval);
55  }
56 
61  explicit Key(const std::string & val) : KeyProvider() {
62  KeyProvider::setKey(val);
63  }
64 
65  explicit Key(const std::vector<unsigned char> & val) : KeyProvider() {
66  KeyProvider::deserialize(val);
67  }
68 
69  inline static size_t size() {
70  return KeyProvider::KEYLENGTH;
71  }
72 
78  inline std::string toStr() const {
79  return KeyProvider::keytoStr();
80  }
81 
83  KeyProvider::setKey(rval);
84  return *this;
85  }
86 
87  bool operator==(const Key<KeyProvider> & rval) const {
88  return KeyProvider::equals(rval);
89  }
90 
91  bool operator!=(const Key<KeyProvider> & rval) const {
92  return !(*this == rval);
93  }
94 
95  bool operator<(const Key<KeyProvider> & rval) const {
96  return KeyProvider::smaller(rval);
97  }
98 
99  bool operator>(const Key<KeyProvider> & rval) const {
100  return !(*this < rval) && (*this != rval);
101  }
102 
103  private:
105 
106  template<class Archive>
107  void serialize(Archive & ar, unsigned int /* version */) {
108  ar & boost::serialization::base_object<KeyProvider>(*this);
109  }
110  };
111 
112 } /* namespace message */
113 } /* namespace m2etis */
114 
115 #endif /* __M2ETIS_MESSAGE_KEY_H__ */
116 
std::string toStr() const
Gets a string representation of the key.
Definition: Key.h:78
Key(const std::string &val)
Constructor.
Definition: Key.h:61
bool operator==(const Key< KeyProvider > &rval) const
Definition: Key.h:87
Key(const Key &rval)
Copy Constructor.
Definition: Key.h:53
static size_t size()
Definition: Key.h:69
Key< KeyProvider > & operator=(const Key< KeyProvider > &rval)
Definition: Key.h:82
bool operator!=(const Key< KeyProvider > &rval) const
Definition: Key.h:91
Key(const std::vector< unsigned char > &val)
Definition: Key.h:65
bool operator>(const Key< KeyProvider > &rval) const
Definition: Key.h:99
friend class boost::serialization::access
Definition: Key.h:104
Key()
Default constructor.
Definition: Key.h:46