20#ifndef LIBREPCB_CORE_CIRCUITIDENTIFIER_H
21#define LIBREPCB_CORE_CIRCUITIDENTIFIER_H
26#include "../exceptions.h"
27#include "../qtcompat.h"
28#include "../serialization/sexpression.h"
29#include "../utils/toolbox.h"
31#include <type_safe/constrained_type.hpp>
35#include <optional.hpp>
47 template <
typename Value,
typename Predicate>
48 static constexpr auto verify(Value&& val,
const Predicate& p) ->
49 typename std::decay<Value>::type {
51 ? std::forward<Value>(val)
54 QString(QCoreApplication::translate(
"CircuitIdentifier",
55 "Invalid identifier: '%1'"))
57 std::forward<Value>(val));
65 return QRegularExpression(
"\\A[-a-zA-Z0-9._+/!?&@#$()]{1,32}\\z")
66 .match(value, 0, QRegularExpression::PartialPreferCompleteMatch)
72 const QString& userInput)
noexcept {
74 userInput, QRegularExpression(
"[^-a-zA-Z0-9._+/!?&@#$()]"),
true,
false,
99 const QString& rhs)
noexcept {
100 return (*lhs) == rhs;
104 return lhs == (*rhs);
107 const QString& rhs)
noexcept {
108 return (*lhs) != rhs;
112 return lhs != (*rhs);
115 const QString& rhs)
noexcept {
124 return (*lhs) % (*rhs);
139 const tl::optional<CircuitIdentifier>& obj) {
152 return deserialize<CircuitIdentifier>(node);
163 stream << QString(
"CircuitIdentifier('%1')").arg(*obj);
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
Definition: occmodel.cpp:77
bool operator==(const AttributeKey &lhs, const QString &rhs) noexcept
Definition: attributekey.h:86
type_safe::constrained_type< QString, CircuitIdentifierConstraint, CircuitIdentifierVerifier > CircuitIdentifier
Definition: circuitidentifier.h:96
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
static QString cleanCircuitIdentifier(const QString &userInput) noexcept
Definition: circuitidentifier.h:71
bool operator!=(const AttributeKey &lhs, const QString &rhs) noexcept
Definition: attributekey.h:92
QtCompat::Hash qHash(const CircuitIdentifier &key, QtCompat::Hash seed=0) noexcept
Definition: circuitidentifier.h:167
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
Definition: circuitidentifier.h:61
bool operator()(const QString &value) const noexcept
Definition: circuitidentifier.h:64
static const constexpr int MAX_LENGTH
Definition: circuitidentifier.h:62
Definition: circuitidentifier.h:46
static constexpr auto verify(Value &&val, const Predicate &p) -> typename std::decay< Value >::type
Definition: circuitidentifier.h:48