libpappsomspp
Library for mass spectrometry
cborstreamwriter.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/processing/cbor/cborstreamwriter.cpp
3 * \date 05/07/2025
4 * \author Olivier Langella
5 * \brief PAPPSO CBOR stream writer
6 */
7
8/*******************************************************************************
9 * Copyright (c) 2025 Olivier Langella <Olivier.Langella@universite-paris-saclay.fr>.
10 *
11 * This file is part of PAPPSOms-tools.
12 *
13 * PAPPSOms-tools is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * PAPPSOms-tools is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with PAPPSOms-tools. If not, see <http://www.gnu.org/licenses/>.
25 *
26 ******************************************************************************/
27
28#include "cborstreamwriter.h"
29#include <QDateTime>
30#include <QThreadPool>
31#include "../../utils.h"
32#include <QCborValue>
33
34pappso::cbor::CborStreamWriter::CborStreamWriter(QByteArray *data) : QCborStreamWriter(data)
35{
36}
37
38pappso::cbor::CborStreamWriter::CborStreamWriter(QIODevice *device) : QCborStreamWriter(device)
39{
40}
41
42
44{
45}
46
47
48void
50 const QString &software_version,
51 const QString &type,
52 const QString &operation)
53{
54 append("informations");
55 startMap();
56 append(QLatin1String("software"));
57 append(software_name);
58 append(QLatin1String("version"));
59 append(software_version);
60 append(QLatin1String("type"));
61 append(type);
62 append(QLatin1String("operation"));
63 append(operation);
64 append(QLatin1String("cpu_used"));
65 append(QThreadPool::globalInstance()->maxThreadCount());
66 append(QLatin1String("pappsomspp_version"));
68 append(QLatin1String("sysinfo_machine_hostname"));
69 append(QSysInfo::machineHostName());
70 append(QLatin1String("sysinfo_product_name"));
71 append(QSysInfo::prettyProductName());
72 append(QLatin1String("timestamp"));
73 append(QDateTime::currentDateTime().toString(Qt::ISODate));
74 endMap();
75}
76
77
78void
79pappso::cbor::CborStreamWriter::writeArray(const std::vector<std::size_t> &int_list)
80{
81 startArray(int_list.size());
82 for(auto num : int_list)
83 {
84 append((quint64)num);
85 }
86 endArray();
87}
88
89void
90pappso::cbor::CborStreamWriter::writeArray(const std::vector<double> &double_list)
91{
92 startArray(double_list.size());
93 for(auto num : double_list)
94 {
95 append(num);
96 }
97 endArray();
98}
99
100void
101pappso::cbor::CborStreamWriter::writeArray(const std::vector<int> &positions)
102{
103
104 startArray(positions.size());
105 for(auto num : positions)
106 {
107 append(num);
108 }
109 endArray();
110}
111
112void
114{
115 startArray(str_list.size());
116 for(auto str_item : str_list)
117 {
118 append(str_item);
119 }
120 endArray();
121}
122
123
124void
126{
127 QCborValue(cbor_map).toCbor(*this);
128}
129
130void
132{
133 QCborValue(cbor_array).toCbor(*this);
134}
PAPPSO CBOR stream reader.
static QString getVersion()
Definition: utils.cpp:623
void writeInformations(const QString &software_name, const QString &software_version, const QString &type, const QString &operation)
void writeArray(const std::vector< std::size_t > &int_list)
void writeCborMap(const QCborMap &cbor_map)
void writeCborArray(const QCborArray &cbor_array)