Apollo  6.0
Open source self driving car software
identity.h
Go to the documentation of this file.
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 
24 namespace apollo {
25 namespace cyber {
26 namespace transport {
27 
28 constexpr uint8_t ID_SIZE = 8;
29 
30 class 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_
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
constexpr uint8_t ID_SIZE
Definition: identity.h:28
bool operator==(const Identity &another) const
Definition: identity.h:30
Identity & operator=(const Identity &another)
Identity(bool need_generate=true)
bool operator!=(const Identity &another) const
void set_data(const char *data)
Definition: identity.h:45
const char * data() const
Definition: identity.h:44