20#ifndef LIBREPCB_CORE_ATTRIBUTEKEY_H
21#define LIBREPCB_CORE_ATTRIBUTEKEY_H
26#include "../serialization/sexpression.h"
27#include "../utils/toolbox.h"
29#include <type_safe/constrained_type.hpp>
43 template <
typename Value,
typename Predicate>
44 static constexpr auto verify(Value&& val,
const Predicate& p) ->
45 typename std::decay<Value>::type {
47 ? std::forward<Value>(val)
50 QString(QCoreApplication::translate(
51 "AttributeKey",
"Invalid attribute key: '%1'"))
53 std::forward<Value>(val));
59 return QRegularExpression(
"\\A[_0-9A-Z]{1,40}\\z")
60 .match(value, 0, QRegularExpression::PartialPreferCompleteMatch)
109 stream << QString(
"AttributeKey('%1')").arg(*obj);
114 std::size_t seed = 0) noexcept {
115 return ::qHash(*key, seed);
120 userInput, QRegularExpression(
"[^_0-9A-Z]"),
true,
false,
true,
"_", 40);
124 const QString& name)
noexcept {
126 : std::optional<AttributeKey>();
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
type_safe::constrained_type< QString, AttributeKeyConstraint, AttributeKeyVerifier > AttributeKey
Definition attributekey.h:78
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
static QString cleanAttributeKey(const QString &userInput) noexcept
Definition attributekey.h:118
bool operator!=(const AttributeKey &lhs, const QString &rhs) noexcept
Definition attributekey.h:86
static std::optional< AttributeKey > parseAttributeKey(const QString &name) noexcept
Definition attributekey.h:123
AttributeKey deserialize(const SExpression &node)
Definition attributekey.h:99
QDataStream & operator<<(QDataStream &stream, const AttributeKey &obj)
Definition attributekey.h:103
Definition attributekey.h:57
bool operator()(const QString &value) const noexcept
Definition attributekey.h:58
Definition attributekey.h:42
static constexpr auto verify(Value &&val, const Predicate &p) -> typename std::decay< Value >::type
Definition attributekey.h:44