20#ifndef LIBREPCB_CORE_COMPONENTPREFIX_H
21#define LIBREPCB_CORE_COMPONENTPREFIX_H
26#include "../../exceptions.h"
27#include "../../serialization/sexpression.h"
28#include "../../utils/toolbox.h"
30#include <type_safe/constrained_type.hpp>
46 template <
typename Value,
typename Predicate>
47 static constexpr auto verify(Value&& val,
const Predicate& p) ->
48 typename std::decay<Value>::type {
50 ? std::forward<Value>(val)
53 QString(QCoreApplication::translate(
54 "ComponentPrefix",
"Invalid component prefix: '%1'"))
56 std::forward<Value>(val));
62 return QRegularExpression(
"\\A[a-zA-Z_]{0,16}\\z")
63 .match(value, 0, QRegularExpression::PartialPreferCompleteMatch)
84 const QString& rhs)
noexcept {
92 const QString& rhs)
noexcept {
100 const QString& rhs)
noexcept {
125 stream << QString(
"ComponentPrefix('%1')").arg(*obj);
130 std::size_t seed = 0) noexcept {
131 return ::qHash(*key, seed);
136 userInput, QRegularExpression(
"[^a-zA-Z_]"),
true,
false,
false,
"_", 16);
140 const QString& prefix)
noexcept {
142 : std::optional<ComponentPrefix>();
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
Definition occmodel.cpp:77
std::size_t qHash(const AttributeKey &key, std::size_t seed=0) noexcept
Definition attributekey.h:113
static QString cleanComponentPrefix(const QString &userInput) noexcept
Definition componentprefix.h:134
bool operator==(const AttributeKey &lhs, const QString &rhs) noexcept
Definition attributekey.h:80
std::unique_ptr< SExpression > serialize(const AttributeKey &obj)
Definition attributekey.h:94
type_safe::constrained_type< QString, ComponentPrefixConstraint, ComponentPrefixVerifier > ComponentPrefix
Definition componentprefix.h:81
bool operator!=(const AttributeKey &lhs, const QString &rhs) noexcept
Definition attributekey.h:86
AttributeKey deserialize(const SExpression &node)
Definition attributekey.h:99
QDataStream & operator<<(QDataStream &stream, const AttributeKey &obj)
Definition attributekey.h:103
static std::optional< ComponentPrefix > parseComponentPrefix(const QString &prefix) noexcept
Definition componentprefix.h:139
QString operator%(const ComponentPrefix &lhs, const QString &rhs) noexcept
Definition componentprefix.h:99
Definition componentprefix.h:60
bool operator()(const QString &value) const noexcept
Definition componentprefix.h:61
Definition componentprefix.h:45
static constexpr auto verify(Value &&val, const Predicate &p) -> typename std::decay< Value >::type
Definition componentprefix.h:47