LibrePCB Developers Documentation
componentsymbolvariantitemsuffix.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_CORE_COMPONENTSYMBOLVARIANTITEMSUFFIX_H
21#define LIBREPCB_CORE_COMPONENTSYMBOLVARIANTITEMSUFFIX_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../../exceptions.h"
27#include "../../qtcompat.h"
28#include "../../serialization/sexpression.h"
29#include "../../utils/toolbox.h"
30
31#include <type_safe/constrained_type.hpp>
32
33#include <QtCore>
34
35/*******************************************************************************
36 * Namespace / Forward Declarations
37 ******************************************************************************/
38namespace librepcb {
39
40/*******************************************************************************
41 * Class ComponentSymbolVariantItemSuffix
42 ******************************************************************************/
43
45 const QString& userInput) noexcept {
46 return Toolbox::cleanUserInputString(userInput,
47 QRegularExpression("[^0-9a-zA-Z_]"),
48 true, false, false, "_", 16);
49}
50
52 template <typename Value, typename Predicate>
53 static constexpr auto verify(Value&& val, const Predicate& p) ->
54 typename std::decay<Value>::type {
55 return p(val) ? std::forward<Value>(val)
56 : (throw RuntimeError(
57 __FILE__, __LINE__,
58 QString(QCoreApplication::translate(
59 "ComponentSymbolVariantItemSuffix",
60 "Invalid component symbol suffix: '%1'"))
61 .arg(val)),
62 std::forward<Value>(val));
63 }
64};
65
67 bool operator()(const QString& value) const noexcept {
68 return QRegularExpression("\\A[0-9a-zA-Z_]{0,16}\\z")
69 .match(value, 0, QRegularExpression::PartialPreferCompleteMatch)
70 .hasMatch();
71 }
72};
73
87 type_safe::constrained_type<QString,
90
92 const QString& rhs) noexcept {
93 return (*lhs) == rhs;
94}
95inline bool operator==(const QString& lhs,
96 const ComponentSymbolVariantItemSuffix& rhs) noexcept {
97 return lhs == (*rhs);
98}
100 const QString& rhs) noexcept {
101 return (*lhs) != rhs;
102}
103inline bool operator!=(const QString& lhs,
104 const ComponentSymbolVariantItemSuffix& rhs) noexcept {
105 return lhs != (*rhs);
106}
108 const QString& rhs) noexcept {
109 return (*lhs) % rhs;
110}
111inline QString operator%(const QString& lhs,
112 const ComponentSymbolVariantItemSuffix& rhs) noexcept {
113 return lhs % (*rhs);
114}
115
116template <>
117inline std::unique_ptr<SExpression> serialize(
119 return SExpression::createString(*obj);
120}
121
122template <>
124 return ComponentSymbolVariantItemSuffix(node.getValue()); // can throw
125}
126
127inline QDataStream& operator<<(QDataStream& stream,
129 stream << *obj;
130 return stream;
131}
132
133inline QDebug operator<<(QDebug stream,
135 stream << QString("ComponentSymbolVariantItemSuffix('%1')").arg(*obj);
136 return stream;
137}
138
140 QtCompat::Hash seed = 0) noexcept {
141 return ::qHash(*key, seed);
142}
143
144/*******************************************************************************
145 * End of File
146 ******************************************************************************/
147
148} // namespace librepcb
149
150#endif
uint Hash
Return type of Qt's qHash() function.
Definition: qtcompat.h:58
The RuntimeError class.
Definition: exceptions.h:218
The SExpression class.
Definition: sexpression.h:69
static std::unique_ptr< SExpression > createString(const QString &string)
Definition: sexpression.cpp:407
const QString & getValue() const
Definition: sexpression.cpp:71
static QString cleanUserInputString(const QString &input, const QRegularExpression &removeRegex, bool trim=true, bool toLower=false, bool toUpper=false, const QString &spaceReplacement=" ", int maxLength=-1) noexcept
Clean a user input string.
Definition: toolbox.cpp:242
Definition: occmodel.cpp:77
bool operator==(const AttributeKey &lhs, const QString &rhs) noexcept
Definition: attributekey.h:86
QtCompat::Hash qHash(const ComponentSymbolVariantItemSuffix &key, QtCompat::Hash seed=0) noexcept
Definition: componentsymbolvariantitemsuffix.h:139
QtCompat::Hash qHash(const AttributeKey &key, QtCompat::Hash seed=0) noexcept
Definition: attributekey.h:119
std::unique_ptr< SExpression > serialize(const AttributeKey &obj)
Definition: attributekey.h:100
bool operator!=(const AttributeKey &lhs, const QString &rhs) noexcept
Definition: attributekey.h:92
static QString cleanComponentSymbolVariantItemSuffix(const QString &userInput) noexcept
Definition: componentsymbolvariantitemsuffix.h:44
AttributeKey deserialize(const SExpression &node)
Definition: attributekey.h:105
QDataStream & operator<<(QDataStream &stream, const AttributeKey &obj)
Definition: attributekey.h:109
QString operator%(const ComponentPrefix &lhs, const QString &rhs) noexcept
Definition: componentprefix.h:103
type_safe::constrained_type< QString, ComponentSymbolVariantItemSuffixConstraint, ComponentSymbolVariantItemSuffixVerifier > ComponentSymbolVariantItemSuffix
Definition: componentsymbolvariantitemsuffix.h:89
Definition: componentsymbolvariantitemsuffix.h:66
bool operator()(const QString &value) const noexcept
Definition: componentsymbolvariantitemsuffix.h:67
Definition: componentsymbolvariantitemsuffix.h:51
static constexpr auto verify(Value &&val, const Predicate &p) -> typename std::decay< Value >::type
Definition: componentsymbolvariantitemsuffix.h:53