Files
pilotclient/src/blackmisc/tuple.cpp
Mathew Sutcliffe 11824206a1 refs #210 added Private::Attribute
* An Attribute contains a reference to a data member, plus some metadata
* Creates the concept of a "meta tuple", a tuple of Attribute objects
* New facilities in TupleConverterBase to be used inside the macro
* Flags allow individual data members to be selectively enabled or disabled depending on how the tuple is used
* Selective enable/disable is implemented by removing the indices of the flagged members from the index_sequence
2014-06-18 23:45:01 +01:00

38 lines
1.4 KiB
C++

/* Copyright (C) 2014 VATSIM Community / authors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "tuple.h"
namespace BlackMisc
{
TupleConverterBase::Parser::Parser(QString string)
{
string.remove(QRegExp("^\\s*\\(\\s*")); // remove first '('
string.remove(QRegExp("\\s*\\)\\s*$")); // remove last ')'
QString current;
int level = 0;
for (const auto c : string)
{
if (c == '(') { level++; }
if (c == ')') { level++; }
if (c == ',' && level == 0) { m_raw.push_back(current.trimmed()); current.clear(); }
else { current += c; }
}
if (! current.trimmed().isEmpty()) { m_raw.push_back(current.trimmed()); current.clear(); }
for (const auto &member : m_raw)
{
QRegExp simple("^o\\.(\\w+)$");
if (member.contains(simple)) { m_names.push_back(simple.cap(1)); continue; }
QRegExp meta("^attr\\s*\\(\\s*o\\.(\\w+)");
if (member.contains(meta)) { m_names.push_back(meta.cap(1)); continue; }
qFatal("BLACK_DECLARE_TUPLE_CONVERSION: Parser couldn't extract member name from \"%s\"", qPrintable(member));
}
for (auto &name : m_names) { name.remove(QRegExp("^m_")); }
}
} // namespace