Skip to content

Commit

Permalink
Implement possibility of optionals for qt-serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
beckdave committed Jan 11, 2024
1 parent b8640b0 commit 4de808b
Show file tree
Hide file tree
Showing 3 changed files with 348 additions and 24 deletions.
2 changes: 2 additions & 0 deletions inc/finalmq/serializeqt/SerializerQt.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ namespace finalmq {

int m_levelStruct = 0;
const Mode m_mode = Mode::NONE;

int m_abortStruct = -1;
};

Internal m_internal;
Expand Down
34 changes: 33 additions & 1 deletion src/serializeqt/ParserQt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <iostream>
#include <codecvt>
#include <locale>
#include <algorithm>


namespace finalmq {
Expand Down Expand Up @@ -87,6 +88,10 @@ namespace finalmq {
static const std::string BITS_16 = "16";
static const std::string BITS_32 = "32";

static const std::string QT_ABORTSTRUCT = "qtabortstruct";
static const std::string QT_FALSE = "false";
static const std::string QT_TRUE = "true";

bool ParserQt::parseStructIntern(const MetaStruct& stru, bool wrappedByQVariant)
{
if (!m_ptr || m_size < 0)
Expand All @@ -96,9 +101,10 @@ namespace finalmq {
}

bool ok = true;
bool abortStruct = false;

const ssize_t numberOfFields = stru.getFieldsSize();
for (ssize_t i = 0; i < numberOfFields && ok; ++i)
for (ssize_t i = 0; i < numberOfFields && ok && !abortStruct; ++i)
{
const MetaField* field = stru.getFieldByIndex(i);
assert(field);
Expand All @@ -119,6 +125,17 @@ namespace finalmq {
if (ok)
{
m_visitor.enterBool(*field, static_cast<bool>(value));

// check abort
const std::string& valueAbort = field->getProperty(QT_ABORTSTRUCT);
if (!valueAbort.empty())
{
if (((valueAbort == QT_TRUE) && value) ||
((valueAbort == QT_FALSE) && !value))
{
abortStruct = true;
}
}
}
}
break;
Expand Down Expand Up @@ -360,6 +377,21 @@ namespace finalmq {
if (ok)
{
m_visitor.enterEnum(*field, value);

// check abort
const std::string& valueAbort = field->getProperty(QT_ABORTSTRUCT);
if (!valueAbort.empty())
{
std::string strValue = en->getNameByValue(value);
std::vector<std::string> valuesAbort;
Utils::split(valueAbort, 0, valueAbort.size(), '|', valuesAbort);
abortStruct = (std::find(valuesAbort.begin(), valuesAbort.end(), strValue) != valuesAbort.end());
if (!abortStruct)
{
std::string aliasValue = en->getAliasByValue(value);
abortStruct = (std::find(valuesAbort.begin(), valuesAbort.end(), aliasValue) != valuesAbort.end());
}
}
}
}
else
Expand Down
Loading

0 comments on commit 4de808b

Please sign in to comment.