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 
47 public:
48  // Signals
49  enum class Event {
52  };
55 
56  // Constructors / Destructor
57  DevicePadSignalMapItem() = delete;
58  DevicePadSignalMapItem(const DevicePadSignalMapItem& other) noexcept;
59  DevicePadSignalMapItem(const Uuid& pad,
60  const tl::optional<Uuid>& signal) noexcept;
61  explicit DevicePadSignalMapItem(const SExpression& node);
62  ~DevicePadSignalMapItem() noexcept;
63 
64  // Getters
65  const Uuid& getUuid() const noexcept {
66  return mPadUuid;
67  } // used for UuidObjectMap
68  const Uuid& getPadUuid() const noexcept { return mPadUuid; }
69  const tl::optional<Uuid>& getSignalUuid() const noexcept {
70  return mSignalUuid;
71  }
72 
73  // Setters
74  bool setSignalUuid(const tl::optional<Uuid>& uuid) noexcept;
75 
77  void serialize(SExpression& root) const override;
78 
79  // Operator Overloadings
80  bool operator==(const DevicePadSignalMapItem& rhs) const noexcept;
81  bool operator!=(const DevicePadSignalMapItem& rhs) const noexcept {
82  return !(*this == rhs);
83  }
85 
86 private: // Data
88  tl::optional<Uuid> mSignalUuid;
89 };
90 
91 /*******************************************************************************
92  * Class DevicePadSignalMap
93  ******************************************************************************/
94 
96  static constexpr const char* tagname = "pad";
97 };
98 using DevicePadSignalMap =
111 
112 /*******************************************************************************
113  * Class DevicePadSignalMapHelpers
114  ******************************************************************************/
115 
117 public:
118  DevicePadSignalMapHelpers() = delete; // disable instantiation
119 
120  static tl::optional<Uuid> tryGetSignalUuid(const DevicePadSignalMap& map,
121  const Uuid& pad) noexcept {
122  std::shared_ptr<const DevicePadSignalMapItem> item = map.find(pad);
123  return item ? item->getSignalUuid() : tl::nullopt;
124  }
125 
126  static DevicePadSignalMap create(const QSet<Uuid> pads) noexcept {
127  DevicePadSignalMap map;
128  foreach (const Uuid& pad, pads) {
129  map.append(std::make_shared<DevicePadSignalMapItem>(pad, tl::nullopt));
130  }
131  return map;
132  }
133 
134  static void setPads(DevicePadSignalMap& map, QSet<Uuid> pads) noexcept {
135  foreach (const Uuid& pad, map.getUuidSet() - pads) { map.remove(pad); }
136  foreach (const Uuid& pad, pads - map.getUuidSet()) {
137  map.append(std::make_shared<DevicePadSignalMapItem>(pad, tl::nullopt));
138  }
139  Q_ASSERT(map.getUuidSet() == pads);
140  }
141 };
142 
143 /*******************************************************************************
144  * End of File
145  ******************************************************************************/
146 
147 } // namespace library
148 } // namespace librepcb
149 
150 #endif // LIBREPCB_LIBRARY_DEVICEPADSIGNALMAP_H
bool 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:91
tl::optional< Uuid > mSignalUuid
tl::nullopt if not connected to a signal
Definition: devicepadsignalmap.h:88
const Uuid & getPadUuid() const noexcept
Definition: devicepadsignalmap.h:68
Definition: devicepadsignalmap.h:95
Event
Definition: devicepadsignalmap.h:49
const Uuid & getUuid() const noexcept
Definition: devicepadsignalmap.h:65
Slot< DevicePadSignalMapItem, Event > OnEditedSlot
Definition: devicepadsignalmap.h:54
Signal< DevicePadSignalMapItem, Event > onEdited
Definition: devicepadsignalmap.h:53
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:43
The CmdListElementsSwap class.
Definition: cmdlistelementsswap.h:44
Uuid mPadUuid
must be valid
Definition: devicepadsignalmap.h:87
static constexpr const char * tagname
Definition: devicepadsignalmap.h:96
Definition: devicepadsignalmap.h:116
int append(const std::shared_ptr< T > &obj) noexcept
Definition: serializableobjectlist.h:321
static tl::optional< Uuid > tryGetSignalUuid(const DevicePadSignalMap &map, const Uuid &pad) noexcept
Definition: devicepadsignalmap.h:120
The DevicePadSignalMapItem class.
Definition: devicepadsignalmap.h:46
bool operator==(const DevicePadSignalMapItem &rhs) const noexcept
Definition: devicepadsignalmap.cpp:84
The Signal class is used to emit signals on non-QObject derived classes.
Definition: signalslot.h:65
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:75
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:126
The Slot class is used to receive signals from non-QObject derived classes.
Definition: signalslot.h:36
The SExpression class.
Definition: sexpression.h:57
bool operator!=(const DevicePadSignalMapItem &rhs) const noexcept
Definition: devicepadsignalmap.h:81
static void setPads(DevicePadSignalMap &map, QSet< Uuid > pads) noexcept
Definition: devicepadsignalmap.h:134
const tl::optional< Uuid > & getSignalUuid() const noexcept
Definition: devicepadsignalmap.h:69