HAL
base_pin.h
Go to the documentation of this file.
1 // MIT License
2 //
3 // Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved.
4 // Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved.
5 // Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved.
6 // Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS"). All Rights reserved.
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 // SOFTWARE.
25 
26 #pragma once
27 
28 #include "hal_core/defines.h"
33 
34 #include <string>
35 
36 namespace hal
37 {
43  template<class T>
44  class BasePin
45  {
46  public:
47  virtual ~BasePin() = default;
48 
55  bool operator==(const BasePin& other) const
56  {
57  return m_id == other.get_id() && m_name == other.get_name() && m_direction == other.get_direction() && m_type == other.get_type()
58  && m_group.first->get_name() == other.get_group().first->get_name() && m_group.second == other.get_group().second;
59  }
60 
67  bool operator!=(const BasePin& other) const
68  {
69  return !operator==(other);
70  }
71 
77  ssize_t get_hash() const
78  {
79  return (uintptr_t)this;
80  }
81 
88  u32 get_id() const
89  {
90  return m_id;
91  }
92 
98  void set_name(const std::string& name)
99  {
100  m_name = name;
101  }
102 
108  const std::string& get_name() const
109  {
110  return m_name;
111  }
112 
119  {
121  }
122 
129  {
130  return m_direction;
131  }
132 
139  {
140  m_type = type;
141  }
142 
149  {
150  return m_type;
151  }
152 
158  const std::pair<PinGroup<T>*, i32>& get_group() const
159  {
160  return m_group;
161  }
162 
163  private:
164  friend PinGroup<T>;
165 
166  BasePin(const BasePin&) = delete;
167  BasePin(BasePin&&) = delete;
168  BasePin& operator=(const BasePin&) = delete;
169  BasePin& operator=(BasePin&&) = delete;
170 
171  protected:
173  std::string m_name;
176  std::pair<PinGroup<T>*, i32> m_group = {nullptr, 0};
177 
187  {
188  }
189  };
190 } // namespace hal
void set_name(const std::string &name)
Definition: base_pin.h:98
BasePin(const u32 id, const std::string &name, PinDirection direction, PinType type=PinType::none)
Definition: base_pin.h:186
const std::string & get_name() const
Definition: base_pin.h:108
virtual ~BasePin()=default
void set_type(PinType type)
Definition: base_pin.h:138
u32 get_id() const
Definition: base_pin.h:88
bool operator==(const BasePin &other) const
Definition: base_pin.h:55
PinType get_type() const
Definition: base_pin.h:148
PinType m_type
Definition: base_pin.h:175
void set_direction(PinDirection direction)
Definition: base_pin.h:118
ssize_t get_hash() const
Definition: base_pin.h:77
const std::pair< PinGroup< T > *, i32 > & get_group() const
Definition: base_pin.h:158
PinDirection get_direction() const
Definition: base_pin.h:128
std::pair< PinGroup< T > *, i32 > m_group
Definition: base_pin.h:176
std::string m_name
Definition: base_pin.h:173
PinDirection m_direction
Definition: base_pin.h:174
bool operator!=(const BasePin &other) const
Definition: base_pin.h:67
int32_t i32
Definition: defines.h:36
PinDirection
Definition: pin_direction.h:36
PinType
Definition: pin_type.h:36
quint32 u32
PinType type
PinDirection direction
std::string name
i32 id