/* This file is autogenerated. DO NOT CHANGE. All changes will be lost */


#include "qtprotobufnamespace/optional/tests/optional.qpb.h"

#include <QtProtobuf/qprotobufregistration.h>

#include <cmath>

namespace qtprotobufnamespace::optional::tests {

class TestStringMessage_QtProtobufData : public QSharedData
{
public:
    TestStringMessage_QtProtobufData()
        : QSharedData()
    {
    }

    TestStringMessage_QtProtobufData(const TestStringMessage_QtProtobufData &other)
        : QSharedData(other),
          m_stringField(other.m_stringField)
    {
    }

    QString m_stringField;
};

TestStringMessage::~TestStringMessage() = default;

static constexpr struct {
    QtProtobufPrivate::QProtobufPropertyOrdering::Data data;
    const std::array<uint, 5> qt_protobuf_TestStringMessage_uint_data;
    const char qt_protobuf_TestStringMessage_char_data[66];
} qt_protobuf_TestStringMessage_metadata {
    // data
    {
        0, /* = version */
        1, /* = num fields */
        2, /* = field number offset */
        3, /* = property index offset */
        4, /* = field flags offset */
        52, /* = message full name length */
    },
    // uint_data
    {
        // JSON name offsets:
        53, /* = stringField */
        65, /* = end-of-string-marker */
        // Field numbers:
        2, /* = stringField */
        // Property indices:
        0, /* = stringField */
        // Field flags:
        uint(QtProtobufPrivate::FieldFlag::NoFlags), /* = stringField */
    },
    // char_data
    /* metadata char_data: */
    "qtprotobufnamespace.optional.tests.TestStringMessage\0" /* = full message name */
    /* field char_data: */
    "stringField\0"
};

const QtProtobufPrivate::QProtobufPropertyOrdering TestStringMessage::staticPropertyOrdering = {
    &qt_protobuf_TestStringMessage_metadata.data
};

void TestStringMessage::registerTypes()
{
    qRegisterMetaType<TestStringMessage>();
    qRegisterMetaType<TestStringMessageRepeated>();
}

TestStringMessage::TestStringMessage()
    : QProtobufMessage(&TestStringMessage::staticMetaObject, &TestStringMessage::staticPropertyOrdering),
      dptr(new TestStringMessage_QtProtobufData)
{
}

TestStringMessage::TestStringMessage(const TestStringMessage &other)
    = default;
TestStringMessage &TestStringMessage::operator =(const TestStringMessage &other)
{
    TestStringMessage temp(other);
    swap(temp);
    return *this;
}
TestStringMessage::TestStringMessage(TestStringMessage &&other) noexcept
    = default;
bool comparesEqual(const TestStringMessage &lhs, const TestStringMessage &rhs) noexcept
{
    return operator ==(static_cast<const QProtobufMessage&>(lhs),
                       static_cast<const QProtobufMessage&>(rhs))
        && lhs.dptr->m_stringField == rhs.dptr->m_stringField;
}

const QString &TestStringMessage::stringField() const &
{
    return dptr->m_stringField;
}

void TestStringMessage::setStringField(const QString &stringField)
{
    if (dptr->m_stringField != stringField) {
        dptr.detach();
        dptr->m_stringField = stringField;
    }
}

void TestStringMessage::setStringField(QString &&stringField)
{
    if (dptr->m_stringField != stringField) {
        dptr.detach();
        dptr->m_stringField = std::move(stringField);
    }
}


class OptionalMessage_QtProtobufData : public QSharedData
{
public:
    OptionalMessage_QtProtobufData()
        : QSharedData(),
          m_testField(0),
          m_testFieldBool(false),
          m_testFieldMessage(nullptr),
          m_testFieldMessageOpt(nullptr)
    {
    }

    OptionalMessage_QtProtobufData(const OptionalMessage_QtProtobufData &other)
        : QSharedData(other),
          m_testField(other.m_testField),
          m_testFieldOpt(other.m_testFieldOpt),
          m_testFieldBool(other.m_testFieldBool),
          m_testFieldBoolOpt(other.m_testFieldBoolOpt),
          m_testFieldBytes(other.m_testFieldBytes),
          m_testFieldBytesOpt(other.m_testFieldBytesOpt),
          m_testFieldString(other.m_testFieldString),
          m_testFieldStringOpt(other.m_testFieldStringOpt),
          m_testFieldMessage(other.m_testFieldMessage
                                               ? new TestStringMessage(*other.m_testFieldMessage)
                                               : nullptr),
          m_testFieldMessageOpt(other.m_testFieldMessageOpt
                                               ? new TestStringMessage(*other.m_testFieldMessageOpt)
                                               : nullptr)
    {
    }

    QtProtobuf::sint32 m_testField;
    std::optional<QtProtobuf::sint32> m_testFieldOpt;
    bool m_testFieldBool;
    std::optional<bool> m_testFieldBoolOpt;
    QByteArray m_testFieldBytes;
    std::optional<QByteArray> m_testFieldBytesOpt;
    QString m_testFieldString;
    std::optional<QString> m_testFieldStringOpt;
    QtProtobufPrivate::QProtobufLazyMessagePointer<TestStringMessage> m_testFieldMessage;
    QtProtobufPrivate::QProtobufLazyMessagePointer<TestStringMessage> m_testFieldMessageOpt;
};

OptionalMessage::~OptionalMessage() = default;

static constexpr struct {
    QtProtobufPrivate::QProtobufPropertyOrdering::Data data;
    const std::array<uint, 41> qt_protobuf_OptionalMessage_uint_data;
    const char qt_protobuf_OptionalMessage_char_data[211];
} qt_protobuf_OptionalMessage_metadata {
    // data
    {
        0, /* = version */
        10, /* = num fields */
        11, /* = field number offset */
        21, /* = property index offset */
        31, /* = field flags offset */
        50, /* = message full name length */
    },
    // uint_data
    {
        // JSON name offsets:
        51, /* = testField */
        61, /* = testFieldOpt */
        74, /* = testFieldBool */
        88, /* = testFieldBoolOpt */
        105, /* = testFieldBytes */
        120, /* = testFieldBytesOpt */
        138, /* = testFieldString */
        154, /* = testFieldStringOpt */
        173, /* = testFieldMessage */
        190, /* = testFieldMessageOpt */
        210, /* = end-of-string-marker */
        // Field numbers:
        1, /* = testField */
        2, /* = testFieldOpt */
        3, /* = testFieldBool */
        4, /* = testFieldBoolOpt */
        5, /* = testFieldBytes */
        6, /* = testFieldBytesOpt */
        7, /* = testFieldString */
        8, /* = testFieldStringOpt */
        9, /* = testFieldMessage */
        10, /* = testFieldMessageOpt */
        // Property indices:
        0, /* = testField */
        1, /* = testFieldOpt */
        3, /* = testFieldBool */
        4, /* = testFieldBoolOpt */
        6, /* = testFieldBytes */
        7, /* = testFieldBytesOpt */
        9, /* = testFieldString */
        10, /* = testFieldStringOpt */
        12, /* = testFieldMessage */
        14, /* = testFieldMessageOpt */
        // Field flags:
        uint(QtProtobufPrivate::FieldFlag::NoFlags), /* = testField */
        uint(QtProtobufPrivate::FieldFlag::Optional | QtProtobufPrivate::FieldFlag::ExplicitPresence), /* = testFieldOpt */
        uint(QtProtobufPrivate::FieldFlag::NoFlags), /* = testFieldBool */
        uint(QtProtobufPrivate::FieldFlag::Optional | QtProtobufPrivate::FieldFlag::ExplicitPresence), /* = testFieldBoolOpt */
        uint(QtProtobufPrivate::FieldFlag::NoFlags), /* = testFieldBytes */
        uint(QtProtobufPrivate::FieldFlag::Optional | QtProtobufPrivate::FieldFlag::ExplicitPresence), /* = testFieldBytesOpt */
        uint(QtProtobufPrivate::FieldFlag::NoFlags), /* = testFieldString */
        uint(QtProtobufPrivate::FieldFlag::Optional | QtProtobufPrivate::FieldFlag::ExplicitPresence), /* = testFieldStringOpt */
        uint(QtProtobufPrivate::FieldFlag::ExplicitPresence | QtProtobufPrivate::FieldFlag::Message), /* = testFieldMessage */
        uint(QtProtobufPrivate::FieldFlag::ExplicitPresence | QtProtobufPrivate::FieldFlag::Message), /* = testFieldMessageOpt */
    },
    // char_data
    /* metadata char_data: */
    "qtprotobufnamespace.optional.tests.OptionalMessage\0" /* = full message name */
    /* field char_data: */
    "testField\0testFieldOpt\0testFieldBool\0testFieldBoolOpt\0testFieldBytes\0"
    "testFieldBytesOpt\0testFieldString\0testFieldStringOpt\0testFieldMessage\0testFieldMessageOpt\0"
};

const QtProtobufPrivate::QProtobufPropertyOrdering OptionalMessage::staticPropertyOrdering = {
    &qt_protobuf_OptionalMessage_metadata.data
};

void OptionalMessage::registerTypes()
{
    qRegisterMetaType<OptionalMessage>();
    qRegisterMetaType<OptionalMessageRepeated>();
}

OptionalMessage::OptionalMessage()
    : QProtobufMessage(&OptionalMessage::staticMetaObject, &OptionalMessage::staticPropertyOrdering),
      dptr(new OptionalMessage_QtProtobufData)
{
}

OptionalMessage::OptionalMessage(const OptionalMessage &other)
    = default;
OptionalMessage &OptionalMessage::operator =(const OptionalMessage &other)
{
    OptionalMessage temp(other);
    swap(temp);
    return *this;
}
OptionalMessage::OptionalMessage(OptionalMessage &&other) noexcept
    = default;
bool comparesEqual(const OptionalMessage &lhs, const OptionalMessage &rhs) noexcept
{
    return operator ==(static_cast<const QProtobufMessage&>(lhs),
                       static_cast<const QProtobufMessage&>(rhs))
        && lhs.dptr->m_testField == rhs.dptr->m_testField
        && lhs.dptr->m_testFieldOpt == rhs.dptr->m_testFieldOpt
        && lhs.dptr->m_testFieldBool == rhs.dptr->m_testFieldBool
        && lhs.dptr->m_testFieldBoolOpt == rhs.dptr->m_testFieldBoolOpt
        && lhs.dptr->m_testFieldBytes == rhs.dptr->m_testFieldBytes
        && lhs.dptr->m_testFieldBytesOpt == rhs.dptr->m_testFieldBytesOpt
        && lhs.dptr->m_testFieldString == rhs.dptr->m_testFieldString
        && lhs.dptr->m_testFieldStringOpt == rhs.dptr->m_testFieldStringOpt
        && (lhs.dptr->m_testFieldMessage == rhs.dptr->m_testFieldMessage
            || *lhs.dptr->m_testFieldMessage == *rhs.dptr->m_testFieldMessage)
        && (lhs.dptr->m_testFieldMessageOpt == rhs.dptr->m_testFieldMessageOpt
            || *lhs.dptr->m_testFieldMessageOpt == *rhs.dptr->m_testFieldMessageOpt);
}

QtProtobuf::sint32 OptionalMessage::testField() const
{
    return dptr->m_testField;
}

QtProtobuf::sint32 OptionalMessage::testFieldOpt_p() const
{
    return dptr->m_testFieldOpt ?
        dptr->m_testFieldOpt.value() : QtProtobuf::sint32();
}

bool OptionalMessage::hasTestFieldOpt() const
{
    return dptr->m_testFieldOpt.has_value();
}
QtProtobuf::sint32 OptionalMessage::testFieldOpt() const
{
    Q_ASSERT(dptr->m_testFieldOpt.has_value());
    return dptr->m_testFieldOpt.value();
}

bool OptionalMessage::testFieldBool() const
{
    return dptr->m_testFieldBool;
}

bool OptionalMessage::testFieldBoolOpt_p() const
{
    return dptr->m_testFieldBoolOpt ?
        dptr->m_testFieldBoolOpt.value() : bool();
}

bool OptionalMessage::hasTestFieldBoolOpt() const
{
    return dptr->m_testFieldBoolOpt.has_value();
}
bool OptionalMessage::testFieldBoolOpt() const
{
    Q_ASSERT(dptr->m_testFieldBoolOpt.has_value());
    return dptr->m_testFieldBoolOpt.value();
}

const QByteArray &OptionalMessage::testFieldBytes() const &
{
    return dptr->m_testFieldBytes;
}

QByteArray OptionalMessage::testFieldBytesOpt_p() const
{
    return dptr->m_testFieldBytesOpt ?
        dptr->m_testFieldBytesOpt.value() : QByteArray();
}

bool OptionalMessage::hasTestFieldBytesOpt() const
{
    return dptr->m_testFieldBytesOpt.has_value();
}
QByteArray OptionalMessage::testFieldBytesOpt() const
{
    Q_ASSERT(dptr->m_testFieldBytesOpt.has_value());
    return dptr->m_testFieldBytesOpt.value();
}

const QString &OptionalMessage::testFieldString() const &
{
    return dptr->m_testFieldString;
}

QString OptionalMessage::testFieldStringOpt_p() const
{
    return dptr->m_testFieldStringOpt ?
        dptr->m_testFieldStringOpt.value() : QString();
}

bool OptionalMessage::hasTestFieldStringOpt() const
{
    return dptr->m_testFieldStringOpt.has_value();
}
QString OptionalMessage::testFieldStringOpt() const
{
    Q_ASSERT(dptr->m_testFieldStringOpt.has_value());
    return dptr->m_testFieldStringOpt.value();
}

TestStringMessage *OptionalMessage::testFieldMessage_p()
{
    if (!dptr->m_testFieldMessage)
        dptr.detach();
    return dptr->m_testFieldMessage.get();
}

bool OptionalMessage::hasTestFieldMessage() const
{
    return dptr->m_testFieldMessage.operator bool();
}

const TestStringMessage &OptionalMessage::testFieldMessage() const &
{
    return *dptr->m_testFieldMessage;
}

void OptionalMessage::clearTestFieldMessage()
{
    if (dptr->m_testFieldMessage) {
        dptr.detach();
        dptr->m_testFieldMessage.reset();
    }
}

TestStringMessage *OptionalMessage::testFieldMessageOpt_p()
{
    if (!dptr->m_testFieldMessageOpt)
        dptr.detach();
    return dptr->m_testFieldMessageOpt.get();
}

bool OptionalMessage::hasTestFieldMessageOpt() const
{
    return dptr->m_testFieldMessageOpt.operator bool();
}

const TestStringMessage &OptionalMessage::testFieldMessageOpt() const &
{
    return *dptr->m_testFieldMessageOpt;
}

void OptionalMessage::clearTestFieldMessageOpt()
{
    if (dptr->m_testFieldMessageOpt) {
        dptr.detach();
        dptr->m_testFieldMessageOpt.reset();
    }
}

void OptionalMessage::setTestField(QtProtobuf::sint32 testField)
{
    if (dptr->m_testField != testField) {
        dptr.detach();
        dptr->m_testField = testField;
    }
}

void OptionalMessage::setTestFieldOpt(QtProtobuf::sint32 testFieldOpt)
{
    if (!dptr->m_testFieldOpt || dptr->m_testFieldOpt.value() != testFieldOpt) {
        dptr.detach();
        dptr->m_testFieldOpt = testFieldOpt;
    }
}

void OptionalMessage::setTestFieldOpt_p(QtProtobuf::sint32 testFieldOpt)
{
    if (!dptr->m_testFieldOpt || dptr->m_testFieldOpt != testFieldOpt) {
        dptr.detach();
        dptr->m_testFieldOpt = testFieldOpt;
    }
}

void OptionalMessage::clearTestFieldOpt()
{
    if (dptr->m_testFieldOpt.has_value()) {
        dptr.detach();
        dptr->m_testFieldOpt.reset();
    }
}
void OptionalMessage::setTestFieldBool(bool testFieldBool)
{
    if (dptr->m_testFieldBool != testFieldBool) {
        dptr.detach();
        dptr->m_testFieldBool = testFieldBool;
    }
}

void OptionalMessage::setTestFieldBoolOpt(bool testFieldBoolOpt)
{
    if (!dptr->m_testFieldBoolOpt || dptr->m_testFieldBoolOpt.value() != testFieldBoolOpt) {
        dptr.detach();
        dptr->m_testFieldBoolOpt = testFieldBoolOpt;
    }
}

void OptionalMessage::setTestFieldBoolOpt_p(bool testFieldBoolOpt)
{
    if (!dptr->m_testFieldBoolOpt || dptr->m_testFieldBoolOpt != testFieldBoolOpt) {
        dptr.detach();
        dptr->m_testFieldBoolOpt = testFieldBoolOpt;
    }
}

void OptionalMessage::clearTestFieldBoolOpt()
{
    if (dptr->m_testFieldBoolOpt.has_value()) {
        dptr.detach();
        dptr->m_testFieldBoolOpt.reset();
    }
}
void OptionalMessage::setTestFieldBytes(const QByteArray &testFieldBytes)
{
    if (dptr->m_testFieldBytes != testFieldBytes) {
        dptr.detach();
        dptr->m_testFieldBytes = testFieldBytes;
    }
}

void OptionalMessage::setTestFieldBytes(QByteArray &&testFieldBytes)
{
    if (dptr->m_testFieldBytes != testFieldBytes) {
        dptr.detach();
        dptr->m_testFieldBytes = std::move(testFieldBytes);
    }
}

void OptionalMessage::setTestFieldBytesOpt(const QByteArray &testFieldBytesOpt)
{
    if (!dptr->m_testFieldBytesOpt || dptr->m_testFieldBytesOpt.value() != testFieldBytesOpt) {
        dptr.detach();
        dptr->m_testFieldBytesOpt = testFieldBytesOpt;
    }
}

void OptionalMessage::setTestFieldBytesOpt(QByteArray &&testFieldBytesOpt)
{
    if (!dptr->m_testFieldBytesOpt || dptr->m_testFieldBytesOpt.value() != testFieldBytesOpt) {
        dptr.detach();
        dptr->m_testFieldBytesOpt = std::move(testFieldBytesOpt);
    }
}

void OptionalMessage::setTestFieldBytesOpt_p(QByteArray testFieldBytesOpt)
{
    if (!dptr->m_testFieldBytesOpt || dptr->m_testFieldBytesOpt != testFieldBytesOpt) {
        dptr.detach();
        dptr->m_testFieldBytesOpt = testFieldBytesOpt;
    }
}

void OptionalMessage::clearTestFieldBytesOpt()
{
    if (dptr->m_testFieldBytesOpt.has_value()) {
        dptr.detach();
        dptr->m_testFieldBytesOpt.reset();
    }
}
void OptionalMessage::setTestFieldString(const QString &testFieldString)
{
    if (dptr->m_testFieldString != testFieldString) {
        dptr.detach();
        dptr->m_testFieldString = testFieldString;
    }
}

void OptionalMessage::setTestFieldString(QString &&testFieldString)
{
    if (dptr->m_testFieldString != testFieldString) {
        dptr.detach();
        dptr->m_testFieldString = std::move(testFieldString);
    }
}

void OptionalMessage::setTestFieldStringOpt(const QString &testFieldStringOpt)
{
    if (!dptr->m_testFieldStringOpt || dptr->m_testFieldStringOpt.value() != testFieldStringOpt) {
        dptr.detach();
        dptr->m_testFieldStringOpt = testFieldStringOpt;
    }
}

void OptionalMessage::setTestFieldStringOpt(QString &&testFieldStringOpt)
{
    if (!dptr->m_testFieldStringOpt || dptr->m_testFieldStringOpt.value() != testFieldStringOpt) {
        dptr.detach();
        dptr->m_testFieldStringOpt = std::move(testFieldStringOpt);
    }
}

void OptionalMessage::setTestFieldStringOpt_p(QString testFieldStringOpt)
{
    if (!dptr->m_testFieldStringOpt || dptr->m_testFieldStringOpt != testFieldStringOpt) {
        dptr.detach();
        dptr->m_testFieldStringOpt = testFieldStringOpt;
    }
}

void OptionalMessage::clearTestFieldStringOpt()
{
    if (dptr->m_testFieldStringOpt.has_value()) {
        dptr.detach();
        dptr->m_testFieldStringOpt.reset();
    }
}
void OptionalMessage::setTestFieldMessage_p(TestStringMessage *testFieldMessage)
{
    if (dptr->m_testFieldMessage.get() != testFieldMessage) {
        dptr.detach();
        dptr->m_testFieldMessage.reset(testFieldMessage);
    }
}

void OptionalMessage::setTestFieldMessage(const TestStringMessage &testFieldMessage)
{
    if (*dptr->m_testFieldMessage != testFieldMessage) {
        dptr.detach();
        *dptr->m_testFieldMessage = testFieldMessage;
    }
}

void OptionalMessage::setTestFieldMessage(TestStringMessage &&testFieldMessage)
{
    if (*dptr->m_testFieldMessage != testFieldMessage) {
        dptr.detach();
        *dptr->m_testFieldMessage = std::move(testFieldMessage);
    }
}

void OptionalMessage::setTestFieldMessageOpt_p(TestStringMessage *testFieldMessageOpt)
{
    if (dptr->m_testFieldMessageOpt.get() != testFieldMessageOpt) {
        dptr.detach();
        dptr->m_testFieldMessageOpt.reset(testFieldMessageOpt);
    }
}

void OptionalMessage::setTestFieldMessageOpt(const TestStringMessage &testFieldMessageOpt)
{
    if (*dptr->m_testFieldMessageOpt != testFieldMessageOpt) {
        dptr.detach();
        *dptr->m_testFieldMessageOpt = testFieldMessageOpt;
    }
}

void OptionalMessage::setTestFieldMessageOpt(TestStringMessage &&testFieldMessageOpt)
{
    if (*dptr->m_testFieldMessageOpt != testFieldMessageOpt) {
        dptr.detach();
        *dptr->m_testFieldMessageOpt = std::move(testFieldMessageOpt);
    }
}

} // namespace qtprotobufnamespace::optional::tests

#include "moc_optional.qpb.cpp"
