Apollo 10.0
自动驾驶开放平台
identity.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. 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
17#ifndef CYBER_TRANSPORT_COMMON_IDENTITY_H_
18#define CYBER_TRANSPORT_COMMON_IDENTITY_H_
19
20#include <cstdint>
21#include <cstring>
22#include <string>
23
24namespace apollo {
25namespace cyber {
26namespace transport {
27
28constexpr uint8_t ID_SIZE = 8;
29
30class Identity {
31 public:
32 explicit Identity(bool need_generate = true);
33 Identity(const Identity& another);
34 virtual ~Identity();
35
36 Identity& operator=(const Identity& another);
37 bool operator==(const Identity& another) const;
38 bool operator!=(const Identity& another) const;
39
40 std::string ToString() const;
41 size_t Length() const;
42 uint64_t HashValue() const;
43
44 const char* data() const { return data_; }
45 void set_data(const char* data) {
46 if (data == nullptr) {
47 return;
48 }
49 std::memcpy(data_, data, sizeof(data_));
50 Update();
51 }
52
53 private:
54 void Update();
55
56 char data_[ID_SIZE];
57 uint64_t hash_value_;
58};
59
60} // namespace transport
61} // namespace cyber
62} // namespace apollo
63
64#endif // CYBER_TRANSPORT_COMMON_IDENTITY_H_
const char * data() const
Definition identity.h:44
std::string ToString() const
Definition identity.cc:60
void set_data(const char *data)
Definition identity.h:45
Identity & operator=(const Identity &another)
Definition identity.cc:44
bool operator!=(const Identity &another) const
Definition identity.cc:56
bool operator==(const Identity &another) const
Definition identity.cc:52
constexpr uint8_t ID_SIZE
Definition identity.h:28
class register implement
Definition arena_queue.h:37