File indexing completed on 2025-10-12 05:10:51

0001 /*
0002     This file is part of the Okteta Kasten module, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2009 Friedrich W. H. Kossebau <kossebau@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #ifndef KASTEN_ADDRESSVALIDATOR_HPP
0010 #define KASTEN_ADDRESSVALIDATOR_HPP
0011 
0012 // Okteta core
0013 #include <Okteta/OktetaCore>
0014 #include <Okteta/Address>
0015 // Qt
0016 #include <QValidator>
0017 #include <QRegularExpression>
0018 
0019 namespace Okteta {
0020 
0021 class ValueCodec;
0022 
0023 class AddressValidator : public QValidator
0024 {
0025     Q_OBJECT
0026 
0027 public:
0028     // matching Okteta::ValueCoding
0029     enum Coding
0030     {
0031         InvalidCoding = -1,
0032         HexadecimalCoding = 0,
0033         DecimalCoding,
0034         OctalCoding,
0035         ExpressionCoding
0036     };
0037     // XXX shouldn't this better be in address.h? Sometime later maybe
0038     enum AddressType
0039     {
0040         InvalidAddressType = -1,
0041         AbsoluteAddress = 0,
0042         RelativeForwards,
0043         RelativeBackwards
0044     };
0045 
0046 public:
0047     explicit AddressValidator(QObject* parent, Coding codecId = HexadecimalCoding);
0048     ~AddressValidator() override;
0049 
0050 public: // QValidator API
0051     QValidator::State validate(QString& string, int& pos) const override;
0052 
0053 public:
0054     AddressType addressType() const;
0055     /** Sets one of the value codecs or any char codec */
0056     void setCodec(Coding codecId);
0057 
0058 public:
0059     Address toAddress(const QString& string, AddressType* type = nullptr) const;
0060     QString toString(Address address, AddressType addressType) const;
0061 
0062 private:
0063     Coding mCodecId;
0064     ValueCodec* mValueCodec;
0065 
0066     static const QRegularExpression expressionRegex;
0067 };
0068 
0069 }
0070 
0071 #endif