LibrePCB Developers Documentation
Loading...
Searching...
No Matches
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 "../../serialization/sexpression.h"
28#include "../../utils/toolbox.h"
29
30#include <type_safe/constrained_type.hpp>
31
32#include <QtCore>
33
34/*******************************************************************************
35 * Namespace / Forward Declarations
36 ******************************************************************************/
37namespace librepcb {
38
39/*******************************************************************************
40 * Class ComponentSymbolVariantItemSuffix
41 ******************************************************************************/
42
44 const QString& userInput) noexcept {
45 return Toolbox::cleanUserInputString(userInput,
46 QRegularExpression("[^0-9a-zA-Z_]"),
47 true, false, false, "_", 16);
48}
49
51 template <typename Value, typename Predicate>
52 static constexpr auto verify(Value&& val, const Predicate& p) ->
53 typename std::decay<Value>::type {
54 return p(val) ? std::forward<Value>(val)
55 : (throw RuntimeError(
56 __FILE__, __LINE__,
57 QString(QCoreApplication::translate(
58 "ComponentSymbolVariantItemSuffix",
59 "Invalid component symbol suffix: '%1'"))
60 .arg(val)),
61 std::forward<Value>(val));
62 }
63};
64
66 bool operator()(const QString& value) const noexcept {
67 return QRegularExpression("\\A[0-9a-zA-Z_]{0,16}\\z")
68 .match(value, 0, QRegularExpression::PartialPreferCompleteMatch)
69 .hasMatch();
70 }
71};
72
86 type_safe::constrained_type<QString,
89
91 const QString& rhs) noexcept {
92 return (*lhs) == rhs;
93}
94inline bool operator==(const QString& lhs,
95 const ComponentSymbolVariantItemSuffix& rhs) noexcept {
96 return lhs == (*rhs);
97}
99 const QString& rhs) noexcept {
100 return (*lhs) != rhs;
101}
102inline bool operator!=(const QString& lhs,
103 const ComponentSymbolVariantItemSuffix& rhs) noexcept {
104 return lhs != (*rhs);
105}
107 const QString& rhs) noexcept {
108 return (*lhs) % rhs;
109}
110inline QString operator%(const QString& lhs,
111 const ComponentSymbolVariantItemSuffix& rhs) noexcept {
112 return lhs % (*rhs);
113}
114
115template <>
116inline std::unique_ptr<SExpression> serialize(
118 return SExpression::createString(*obj);
119}
120
121template <>
125
126inline QDataStream& operator<<(QDataStream& stream,
128 stream << *obj;
129 return stream;
130}
131
132inline QDebug operator<<(QDebug stream,
134 stream << QString("ComponentSymbolVariantItemSuffix('%1')").arg(*obj);
135 return stream;
136}
137
138inline std::size_t qHash(const ComponentSymbolVariantItemSuffix& key,
139 std::size_t seed = 0) noexcept {
140 return ::qHash(*key, seed);
141}
142
143/*******************************************************************************
144 * End of File
145 ******************************************************************************/
146
147} // namespace librepcb
148
149#endif
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:247
Definition occmodel.cpp:76
std::size_t qHash(const AttributeKey &key, std::size_t seed=0) noexcept
Definition attributekey.h:118
bool operator==(const AttributeKey &lhs, const QString &rhs) noexcept
Definition attributekey.h:85
std::unique_ptr< SExpression > serialize(const AttributeKey &obj)
Definition attributekey.h:99
bool operator!=(const AttributeKey &lhs, const QString &rhs) noexcept
Definition attributekey.h:91
static QString cleanComponentSymbolVariantItemSuffix(const QString &userInput) noexcept
Definition componentsymbolvariantitemsuffix.h:43
AttributeKey deserialize(const SExpression &node)
Definition attributekey.h:104
QDataStream & operator<<(QDataStream &stream, const AttributeKey &obj)
Definition attributekey.h:108
QString operator%(const ComponentPrefix &lhs, const QString &rhs) noexcept
Definition componentprefix.h:102
type_safe::constrained_type< QString, ComponentSymbolVariantItemSuffixConstraint, ComponentSymbolVariantItemSuffixVerifier > ComponentSymbolVariantItemSuffix
Definition componentsymbolvariantitemsuffix.h:88
Definition componentsymbolvariantitemsuffix.h:65
bool operator()(const QString &value) const noexcept
Definition componentsymbolvariantitemsuffix.h:66
Definition componentsymbolvariantitemsuffix.h:50
static constexpr auto verify(Value &&val, const Predicate &p) -> typename std::decay< Value >::type
Definition componentsymbolvariantitemsuffix.h:52