LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
devicepadsignalmap.h
Go to the documentation of this file.
1 /*
2  * LibrePCB - Professional EDA for everyone!
3  * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4  * https://librepcb.org/
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef LIBREPCB_LIBRARY_DEVICEPADSIGNALMAP_H
21 #define LIBREPCB_LIBRARY_DEVICEPADSIGNALMAP_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
30 
31 #include <QtCore>
32 
33 /*******************************************************************************
34  * Namespace / Forward Declarations
35  ******************************************************************************/
36 namespace librepcb {
37 namespace library {
38 
39 /*******************************************************************************
40  * Class DevicePadSignalMapItem
41  ******************************************************************************/
42 
46 class DevicePadSignalMapItem final : public QObject, public SerializableObject {
47  Q_OBJECT
48 
49 public:
50  // Constructors / Destructor
51  DevicePadSignalMapItem() = delete;
52  DevicePadSignalMapItem(const DevicePadSignalMapItem& other) noexcept;
53  DevicePadSignalMapItem(const Uuid& pad,
54  const tl::optional<Uuid>& signal) noexcept;
55  explicit DevicePadSignalMapItem(const SExpression& node);
56  ~DevicePadSignalMapItem() noexcept;
57 
58  // Getters
59  const Uuid& getUuid() const noexcept {
60  return mPadUuid;
61  } // used for UuidObjectMap
62  const Uuid& getPadUuid() const noexcept { return mPadUuid; }
63  const tl::optional<Uuid>& getSignalUuid() const noexcept {
64  return mSignalUuid;
65  }
66 
67  // Setters
68  void setSignalUuid(const tl::optional<Uuid>& uuid) noexcept;
69 
71  void serialize(SExpression& root) const override;
72 
73  // Operator Overloadings
74  bool operator==(const DevicePadSignalMapItem& rhs) const noexcept;
75  bool operator!=(const DevicePadSignalMapItem& rhs) const noexcept {
76  return !(*this == rhs);
77  }
79 
80 signals:
81  void signalUuidChanged(const tl::optional<Uuid>& uuid);
82 
83 private: // Data
85  tl::optional<Uuid> mSignalUuid;
86 };
87 
88 /*******************************************************************************
89  * Class DevicePadSignalMap
90  ******************************************************************************/
91 
93  static constexpr const char* tagname = "pad";
94 };
95 using DevicePadSignalMap =
106 
107 /*******************************************************************************
108  * Class DevicePadSignalMapHelpers
109  ******************************************************************************/
110 
112 public:
113  DevicePadSignalMapHelpers() = delete; // disable instantiation
114 
115  static tl::optional<Uuid> tryGetSignalUuid(const DevicePadSignalMap& map,
116  const Uuid& pad) noexcept {
117  std::shared_ptr<const DevicePadSignalMapItem> item = map.find(pad);
118  return item ? item->getSignalUuid() : tl::nullopt;
119  }
120 
121  static DevicePadSignalMap create(const QSet<Uuid> pads) noexcept {
122  DevicePadSignalMap map;
123  foreach (const Uuid& pad, pads) {
124  map.append(std::make_shared<DevicePadSignalMapItem>(pad, tl::nullopt));
125  }
126  return map;
127  }
128 
129  static void setPads(DevicePadSignalMap& map, QSet<Uuid> pads) noexcept {
130  foreach (const Uuid& pad, map.getUuidSet() - pads) { map.remove(pad); }
131  foreach (const Uuid& pad, pads - map.getUuidSet()) {
132  map.append(std::make_shared<DevicePadSignalMapItem>(pad, tl::nullopt));
133  }
134  Q_ASSERT(map.getUuidSet() == pads);
135  }
136 };
137 
138 /*******************************************************************************
139  * End of File
140  ******************************************************************************/
141 
142 } // namespace library
143 } // namespace librepcb
144 
145 #endif // LIBREPCB_LIBRARY_DEVICEPADSIGNALMAP_H
void setSignalUuid(const tl::optional< Uuid > &uuid) noexcept
Definition: devicepadsignalmap.cpp:60
The CmdListElementRemove class.
Definition: cmdlistelementremove.h:44
~DevicePadSignalMapItem() noexcept
Definition: devicepadsignalmap.cpp:53
DevicePadSignalMapItem & operator=(const DevicePadSignalMapItem &rhs) noexcept
Definition: devicepadsignalmap.cpp:87
tl::optional< Uuid > mSignalUuid
tl::nullopt if not connected to a signal
Definition: devicepadsignalmap.h:85
const Uuid & getPadUuid() const noexcept
Definition: devicepadsignalmap.h:62
Definition: devicepadsignalmap.h:92
const Uuid & getUuid() const noexcept
Definition: devicepadsignalmap.h:59
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:46
The CmdListElementsSwap class.
Definition: cmdlistelementsswap.h:44
Uuid mPadUuid
must be valid
Definition: devicepadsignalmap.h:84
void signalUuidChanged(const tl::optional< Uuid > &uuid)
static constexpr const char * tagname
Definition: devicepadsignalmap.h:93
Definition: devicepadsignalmap.h:111
int append(const std::shared_ptr< T > &obj) noexcept
Definition: serializableobjectlist.h:307
static tl::optional< Uuid > tryGetSignalUuid(const DevicePadSignalMap &map, const Uuid &pad) noexcept
Definition: devicepadsignalmap.h:115
The DevicePadSignalMapItem class.
Definition: devicepadsignalmap.h:46
bool operator==(const DevicePadSignalMapItem &rhs) const noexcept
Definition: devicepadsignalmap.cpp:80
The CmdListElementInsert class.
Definition: cmdlistelementinsert.h:44
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: devicepadsignalmap.cpp:71
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
static DevicePadSignalMap create(const QSet< Uuid > pads) noexcept
Definition: devicepadsignalmap.h:121
The SExpression class.
Definition: sexpression.h:60
bool operator!=(const DevicePadSignalMapItem &rhs) const noexcept
Definition: devicepadsignalmap.h:75
static void setPads(DevicePadSignalMap &map, QSet< Uuid > pads) noexcept
Definition: devicepadsignalmap.h:129
const tl::optional< Uuid > & getSignalUuid() const noexcept
Definition: devicepadsignalmap.h:63