<commit_before>#include "XmlSerializer.h"
#include "StreamWidget.h"
#include <QFile>
#include <iostream>


XmlElement::XmlElement(const QString &name)
    :elementName(name)
{
}


XmlStruct::XmlStruct(const QString &name)
    :XmlElement(name)
{
}

XmlStruct::~XmlStruct()
{
    XmlElement* elem;

    foreach(elem, values)
        delete elem;

}


XmlValue::XmlValue(const QString &name, const QString &value)
    :XmlElement(name),
      value(value)
{
}


QString XmlStruct::getElementString(int intend) const
{
    QString result("");
    XmlElement* elem;

    for(int i = 0; i < intend; i++)
        result.append("\t");

    result.append("<" + elementName + ">\n");

    foreach(elem, values)
        result.append(elem->getElementString(intend + 1));

    for(int i = 0; i < intend; i++)
        result.append("\t");

    result.append("</" + elementName + ">\n");

    return result;
}

void XmlStruct::addElement(XmlElement* elem)
{
    values.append(elem);
}


QString XmlValue::getElementString(int intend) const
{
    QString result("");

    for(int i = 0; i < intend; i++)
        result.append("\t");

    result.append("<" + elementName + "=\"" + value + "\"/>\n");

    return result;
}


XmlSerializer::XmlSerializer(QString fileName)
    : fileName(fileName),
      appProto(0),
      clientCount(1)
{
}


XmlSerializer::~XmlSerializer()
{

    XmlElement* elem;

    if(elements.empty())
    {
        delete appProto;

        foreach(elem, clients)
        {
            delete elem;
            elem = 0;
        }

        foreach(elem, streams)
        {
            delete elem;
            elem = 0;
        }

        foreach(elem, simulationParams)
        {
            delete elem;
            elem = 0;
        }
    }
    else
    {
        foreach(elem, elements)
            delete elem;
    }
}

void XmlSerializer::addClientsElement(const ClientWidget *client)
{
    XmlStruct* elem = new XmlStruct("client");

    QString number("");

    if(client->clientCount->value() == 1)
    {
        number = QString::number(clientCount);
    }
    else
    {
        number = QString::number(clientCount);
        number.append(":");
        number.append(QString::number(client->clientCount->value()));
    }

    elem->addElement(new XmlValue("no", number));

    clientCount += client->clientCount->value();

    elem->addElement(new XmlValue("delay", QString::number(client->delay->value())));
    elem->addElement(new XmlValue("uplink", QString::number(client->uplink->value())));
    elem->addElement(new XmlValue("downlink", QString::number(client->downlink->value())));
    elem->addElement(new XmlValue("loss", QString::number(client->loss->value())));
    elem->addElement(new XmlValue("jointime", QString::number(client->arrive->value())));
    elem->addElement(new XmlValue("exittime", QString::number(client->exit->value())));
    elem->addElement(new XmlValue("pcap", client->pcap->isChecked() ? "yes" : "no"));
    elem->addElement(new XmlValue("graphs", client->graph->isChecked() ? "yes" : "no"));

    clients.append(elem);
}


void XmlSerializer::addAppProtoElement(uint ackSize, uint delayedAck, uint retransmit, uint headerSize)
{
    delete appProto;
    appProto = new XmlStruct("appproto");

    appProto->addElement(new XmlValue("acksize", QString::number(ackSize)));
    appProto->addElement(new XmlValue("delayedack", QString::number(delayedAck)));
    appProto->addElement(new XmlValue("retransmit", QString::number(retransmit)));
    appProto->addElement(new XmlValue("headersize", QString::number(headerSize)));
}


void XmlSerializer::addStreamElement(const StreamWidget* stream)
{

    XmlStruct* streamElement = new XmlStruct("stream");

    if(stream->tcpUsed())
        streamElement->addElement(new XmlValue("type", "tcp"));
    else
        streamElement->addElement(new XmlValue("type", "udp"));

    if(stream->appProto->isChecked())
        streamElement->addElement(new XmlValue("appproto", "yes"));
    else
        streamElement->addElement(new XmlValue("appproto", "no"));

    streamElement->addElement(new XmlValue("servergametick", QString::number(stream->serverGameTick->value())));
    streamElement->addElement(new XmlValue("clientgametick", QString::number(stream->clientGameTick->value())));

    addMessages(streamElement, stream->messages);
<commit_msg>Added missing value in serialization.<commit_after>#include "XmlSerializer.h"
#include "StreamWidget.h"
#include <QFile>
#include <iostream>


XmlElement::XmlElement(const QString &name)
    :elementName(name)
{
}


XmlStruct::XmlStruct(const QString &name)
    :XmlElement(name)
{
}

XmlStruct::~XmlStruct()
{
    XmlElement* elem;

    foreach(elem, values)
        delete elem;

}


XmlValue::XmlValue(const QString &name, const QString &value)
    :XmlElement(name),
      value(value)
{
}


QString XmlStruct::getElementString(int intend) const
{
    QString result("");
    XmlElement* elem;

    for(int i = 0; i < intend; i++)
        result.append("\t");

    result.append("<" + elementName + ">\n");

    foreach(elem, values)
        result.append(elem->getElementString(intend + 1));

    for(int i = 0; i < intend; i++)
        result.append("\t");

    result.append("</" + elementName + ">\n");

    return result;
}

void XmlStruct::addElement(XmlElement* elem)
{
    values.append(elem);
}


QString XmlValue::getElementString(int intend) const
{
    QString result("");

    for(int i = 0; i < intend; i++)
        result.append("\t");

    result.append("<" + elementName + "=\"" + value + "\"/>\n");

    return result;
}


XmlSerializer::XmlSerializer(QString fileName)
    : fileName(fileName),
      appProto(0),
      clientCount(1)
{
}


XmlSerializer::~XmlSerializer()
{

    XmlElement* elem;

    if(elements.empty())
    {
        delete appProto;

        foreach(elem, clients)
        {
            delete elem;
            elem = 0;
        }

        foreach(elem, streams)
        {
            delete elem;
            elem = 0;
        }

        foreach(elem, simulationParams)
        {
            delete elem;
            elem = 0;
        }
    }
    else
    {
        foreach(elem, elements)
            delete elem;
    }
}

void XmlSerializer::addClientsElement(const ClientWidget *client)
{
    XmlStruct* elem = new XmlStruct("client");

    QString number("");

    if(client->clientCount->value() == 1)
    {
        number = QString::number(clientCount);
    }
    else
    {
        number = QString::number(clientCount);
        number.append(":");
        number.append(QString::number(client->clientCount->value()));
    }

    elem->addElement(new XmlValue("no", number));

    clientCount += client->clientCount->value();

    elem->addElement(new XmlValue("delay", QString::number(client->delay->value())));
    elem->addElement(new XmlValue("uplink", QString::number(client->uplink->value())));
    elem->addElement(new XmlValue("downlink", QString::number(client->downlink->value())));
    elem->addElement(new XmlValue("loss", QString::number(client->loss->value())));
    elem->addElement(new XmlValue("jointime", QString::number(client->arrive->value())));
    elem->addElement(new XmlValue("exittime", QString::number(client->exit->value())));
    elem->addElement(new XmlValue("pcap", client->pcap->isChecked() ? "yes" : "no"));
    elem->addElement(new XmlValue("graphs", client->graph->isChecked() ? "yes" : "no"));

    clients.append(elem);
}


void XmlSerializer::addAppProtoElement(uint ackSize, uint delayedAck, uint retransmit, uint headerSize)
{
    delete appProto;
    appProto = new XmlStruct("appproto");

    appProto->addElement(new XmlValue("acksize", QString::number(ackSize)));
    appProto->addElement(new XmlValue("delayedack", QString::number(delayedAck)));
    appProto->addElement(new XmlValue("retransmit", QString::number(retransmit)));
    appProto->addElement(new XmlValue("headersize", QString::number(headerSize)));
}


void XmlSerializer::addStreamElement(const StreamWidget* stream)
{

    XmlStruct* streamElement = new XmlStruct("stream");

    if(stream->tcpUsed())
        streamElement->addElement(new XmlValue("type", "tcp"));
    else
        streamElement->addElement(new XmlValue("type", "udp"));

    if(stream->appProto->isChecked())
        streamElement->addElement(new XmlValue("appproto", "yes"));
    else
        streamElement->addElement(new XmlValue("appproto", "no"));

    if(stream->ordered->isChecked())
        streamElement->addElement(new XmlValue("ordered", "yes"));
    else
        streamElement->addElement(new XmlValue("ordered", "no"));

    streamElement->addElement(new XmlValue("servergametick", QString::number(stream->serverGameTick->value())));
    streamElement->addElement(new XmlValue("clientgametick", QString::number(stream->clientGameTick->value())));

    addMessages(streamElement, stream->messages);

{'fraction_non_alphanumeric': 0.16512832057631696, 'fraction_numerical': 0.0022512381809995496, 'mean_word_length': 3.5540748334187597, 'pattern_counts': {'":': 2, '<': 19, '<?xml version=': 0, '>': 117, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6678707', 'n_tokens_mistral': 2785, 'n_tokens_neox': 2637, 'n_words': 478}