EHM DAL 0.2.5
Data abstraction layer for Eastside Hockey Manager
Loading...
Searching...
No Matches
string.h
1#pragma once
2
3// Application headers
4#include "include/data_types/private/abstract_data_type.h"
5
6// Qt headers
7class QDataStream;
8class QRegularExpression;
9#include <QString>
10class QVariant;
11
15namespace ehm_dal::data_types {
16
17// --- Text string wrapper --- //
22{
23public:
32 String(const QString &text);
33 String(const QString &a, const QString &b, const QVariant &c);
34 String(const std::vector<QVariant> &text_list);
35
36 // Comparison
43 inline qint32 compare(const String &rhs, const Qt::CaseSensitivity case_sensitivity) const
44 {
45 return get().compare(rhs.get(), case_sensitivity);
46 }
53 inline bool isIdenticalTo(const String &rhs, const Qt::CaseSensitivity case_sensitivity) const
54 {
55 return (get().compare(rhs.get(), case_sensitivity) == 0);
56 }
61 QString matchString() const;
66 inline static QString toMatchString(const QString &text)
67 {
68 String str(text);
69 return str.matchString();
70 }
78 inline static QString toMatchString(const QString &a, const QString &b, const QVariant &c)
79 {
80 String str(a, b, c);
81 return str.matchString();
82 }
88 inline static QString toMatchString(const std::vector<QVariant> &text_list)
89 {
90 String str(text_list);
91 return str.matchString();
92 }
93
94 // File i/o
100 void readCharArray(QDataStream &in, const quint16 length);
101 void writeCharArray(QDataStream &in, const quint16 length);
102
103 // Get data
108 inline QString get() const { return string_; }
113 inline qsizetype size() const { return string_.size(); }
117 QString toHex() const;
118
119 // Set data
123 inline void clear() { string_.clear(); }
124
125private:
126 QString string_;
127
128 // Comparison
129 static QRegularExpression accented_characters_;
130
131 // File i/o
132 friend QDataStream &operator>>(QDataStream &in, String &data);
133 friend QDataStream &operator<<(QDataStream &out, const String &data);
134
135 // Get data
140 inline QVariant value(const qint32 role = Qt::DisplayRole) const override
141 {
142 Q_UNUSED(role)
143 return string_;
144 }
145
150 inline void setValue(const QVariant &value) override { string_ = value.toString().trimmed(); }
151
152 // Standard text lengths (mostly for EHM 200x)
153 enum ENUM_TEXT_LENGTHS {
154 SAV_INDEX_TEXT_LENGTH = 260, // EHM 200x and EHM 1 saved games
155 LONG_TEXT_LENGTH = 101,
156 STANDARD_TEXT_LENGTH = 51,
157 SHORT_TEXT_LENGTH = 26,
158 REAL_SHORT_TEXT_LENGTH = 6,
159 THREE_LETTER_TEXT_LENGTH = 4,
160 SIX_LETTER_TEXT_LENGTH = 7
161 };
162};
163
164// File i/o
165QDataStream &operator>>(QDataStream &in, String &data);
166QDataStream &operator<<(QDataStream &out, const String &data);
167
168} // namespace ehm_dal::data_types
169
170
The AbstractDataType class provides common virtual functions for all integral game data types.
Definition: abstract_data_type.h:11
QVariant data(const qint32 role=Qt::DisplayRole) const
Returns the data stored under the given role for the item.
The String class acts as a QString wrapper for EHM text strings.
Definition: string.h:22
bool isIdenticalTo(const String &rhs, const Qt::CaseSensitivity case_sensitivity) const
Checks whether two Strings are identical.
Definition: string.h:53
qsizetype size() const
Returns the number of characters in the current text string.
Definition: string.h:113
QString matchString() const
Returns the string text as a match string suitable for comparing against other match strings....
QString toHex() const
Returns the text string in hexidecimal format.
static QString toMatchString(const QString &a, const QString &b, const QVariant &c)
Convenience static function for QString matchString() const;. Combines a, b and c into a single strin...
Definition: string.h:78
static QString toMatchString(const std::vector< QVariant > &text_list)
Convenience static function for QString matchString() const;. Combines the elemtns of text_list into ...
Definition: string.h:88
QString get() const
Returns the current text string.
Definition: string.h:108
static QString toMatchString(const QString &text)
Convenience static function for QString matchString() const;.
Definition: string.h:66
void clear()
Clears the curreny text string.
Definition: string.h:123
void readCharArray(QDataStream &in, const quint16 length)
Read an array of 8-bit chars as a text string and store in the String.
String(const QString &text)
Constructs the String with text.
String()
Default constructor.
qint32 compare(const String &rhs, const Qt::CaseSensitivity case_sensitivity) const
Compares two Strings. This is the same as QString::compare()
Definition: string.h:43
namespace ehm_dal::data_types
Definition: attribute.h:6