Apollo 10.0
自动驾驶开放平台
identity.cc
浏览该文件的文档.
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
18
19#include <uuid/uuid.h>
20
21#include "cyber/common/util.h"
22
23namespace apollo {
24namespace cyber {
25namespace transport {
26
27Identity::Identity(bool need_generate) : hash_value_(0) {
28 std::memset(data_, 0, ID_SIZE);
29 if (need_generate) {
30 uuid_t uuid;
31 uuid_generate(uuid);
32 std::memcpy(data_, uuid, ID_SIZE);
33 Update();
34 }
35}
36
38 std::memcpy(data_, rhs.data_, ID_SIZE);
39 hash_value_ = rhs.hash_value_;
40}
41
43
45 if (this != &rhs) {
46 std::memcpy(data_, rhs.data_, ID_SIZE);
47 hash_value_ = rhs.hash_value_;
48 }
49 return *this;
50}
51
52bool Identity::operator==(const Identity& rhs) const {
53 return std::memcmp(data_, rhs.data_, ID_SIZE) == 0;
54}
55
56bool Identity::operator!=(const Identity& rhs) const {
57 return std::memcmp(data_, rhs.data_, ID_SIZE) != 0;
58}
59
60std::string Identity::ToString() const { return std::to_string(hash_value_); }
61
62size_t Identity::Length() const { return ID_SIZE; }
63
64uint64_t Identity::HashValue() const { return hash_value_; }
65
66void Identity::Update() {
67 hash_value_ = common::Hash(std::string(data_, ID_SIZE));
68}
69
70} // namespace transport
71} // namespace cyber
72} // namespace apollo
std::string ToString() const
Definition identity.cc:60
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
Identity(bool need_generate=true)
Definition identity.cc:27
std::size_t Hash(const std::string &key)
Definition util.h:27
constexpr uint8_t ID_SIZE
Definition identity.h:28
class register implement
Definition arena_queue.h:37