LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
attribute.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_ATTRIBUTE_H
21 #define LIBREPCB_ATTRIBUTE_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../fileio/cmd/cmdlistelementinsert.h"
27 #include "../fileio/cmd/cmdlistelementremove.h"
28 #include "../fileio/cmd/cmdlistelementsswap.h"
29 #include "../fileio/serializableobjectlist.h"
30 #include "attributekey.h"
31 
32 #include <QtCore>
33 
34 /*******************************************************************************
35  * Namespace / Forward Declarations
36  ******************************************************************************/
37 namespace librepcb {
38 
39 class AttributeType;
40 class AttributeUnit;
41 
42 /*******************************************************************************
43  * Class Attribute
44  ******************************************************************************/
45 
49 class Attribute final : public SerializableObject {
50  Q_DECLARE_TR_FUNCTIONS(Attribute)
51 
52 public:
53  // Constructors / Destructor
54  Attribute() = delete;
55  Attribute(const Attribute& other) noexcept;
56  explicit Attribute(const SExpression& node);
57  Attribute(const AttributeKey& key, const AttributeType& type,
58  const QString& value, const AttributeUnit* unit);
59  ~Attribute() noexcept;
60 
61  // Getters
62  const AttributeKey& getKey() const noexcept { return mKey; }
63  const QString& getName() const noexcept {
64  return *mKey;
65  } // required for SerializableObjectList
66  const AttributeType& getType() const noexcept { return *mType; }
67  const AttributeUnit* getUnit() const noexcept { return mUnit; }
68  const QString& getValue() const noexcept { return mValue; }
69  QString getValueTr(bool showUnit) const noexcept;
70 
71  // Setters
72  void setKey(const AttributeKey& key) noexcept { mKey = key; }
73  void setTypeValueUnit(const AttributeType& type, const QString& value,
74  const AttributeUnit* unit);
75 
76  // General Methods
77 
79  void serialize(SExpression& root) const override;
80 
81  // Operator Overloadings
82  bool operator==(const Attribute& rhs) const noexcept;
83  bool operator!=(const Attribute& rhs) const noexcept {
84  return !(*this == rhs);
85  }
86  Attribute& operator=(const Attribute& rhs) = delete;
87 
88 private: // Methods
89  bool checkAttributesValidity() const noexcept;
90 
91 private: // Data
94  QString mValue;
96 };
97 
98 /*******************************************************************************
99  * Class AttributeList
100  ******************************************************************************/
101 
103  static constexpr const char* tagname = "attribute";
104 };
105 using AttributeList =
107 using CmdAttributeInsert =
109 using CmdAttributeRemove =
111 using CmdAttributesSwap =
113 
114 /*******************************************************************************
115  * End of File
116  ******************************************************************************/
117 
118 } // namespace librepcb
119 
120 #endif // LIBREPCB_ATTRIBUTE_H
const AttributeType * mType
Definition: attribute.h:93
const AttributeUnit * getUnit() const noexcept
Definition: attribute.h:67
void setKey(const AttributeKey &key) noexcept
Definition: attribute.h:72
const AttributeType & getType() const noexcept
Definition: attribute.h:66
Attribute & operator=(const Attribute &rhs)=delete
The CmdListElementRemove class.
Definition: cmdlistelementremove.h:44
const QString & getValue() const noexcept
Definition: attribute.h:68
QString mValue
Definition: attribute.h:94
type_safe::constrained_type< QString, AttributeKeyConstraint, AttributeKeyVerifier > AttributeKey
Definition: attributekey.h:83
Definition: attribute.h:102
QString getValueTr(bool showUnit) const noexcept
Definition: attribute.cpp:67
bool operator!=(const Attribute &rhs) const noexcept
Definition: attribute.h:83
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
const AttributeKey & getKey() const noexcept
Definition: attribute.h:62
The AttributeUnit class.
Definition: attributeunit.h:42
~Attribute() noexcept
Definition: attribute.cpp:60
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: attribute.cpp:93
const QString & getName() const noexcept
Definition: attribute.h:63
const AttributeUnit * mUnit
Definition: attribute.h:95
The Attribute class.
Definition: attribute.h:49
AttributeKey mKey
Definition: attribute.h:92
The CmdListElementInsert class.
Definition: cmdlistelementinsert.h:44
The AttributeType class.
Definition: attributetype.h:44
The SExpression class.
Definition: sexpression.h:60
bool operator==(const Attribute &rhs) const noexcept
Definition: attribute.cpp:109
bool checkAttributesValidity() const noexcept
Definition: attribute.cpp:121
void setTypeValueUnit(const AttributeType &type, const QString &value, const AttributeUnit *unit)
Definition: attribute.cpp:75