libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
cborstreamreaderinterface.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/processing/cbor/cborstreamreaderinterface.h
3 * \date 11/02/2025
4 * \author Olivier Langella
5 * \brief common interface to read CBOR streams with convenient framework
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
29
33
35{
36 // qWarning() << "~CborStreamReaderInterface";
37 if(mpa_cborReader != nullptr)
38 delete mpa_cborReader;
39 mpa_cborReader = nullptr;
40}
41
42
43void
45{
46 // qWarning() << "close PsmFileReaderBase";
47 if(mpa_cborReader != nullptr)
48 delete mpa_cborReader;
49 mpa_cborReader = nullptr;
50 // qWarning() << "close PsmFileReaderBase";
51}
52
53bool
55{
56 bool is_ok = false;
58 qDebug() << mpa_cborReader->type();
59 if(mpa_cborReader->type() == QCborStreamReader::String)
60 {
61 is_ok = mpa_cborReader->decodeString(m_expectedString);
62 }
63
64 return is_ok;
65}
66
67
68void
70{
71
72 if(mpa_cborReader != nullptr)
73 delete mpa_cborReader;
74 mpa_cborReader = nullptr;
76 // just use the QIODevice
77 mpa_cborReader->setDevice(pcborfile);
78}
79void
81{
82
83 if(mpa_cborReader != nullptr)
84 delete mpa_cborReader;
85 mpa_cborReader = nullptr;
87 // try to mmap the file, this is faster
88 char *ptr =
89 reinterpret_cast<char *>(pcborfile->map(0, pcborfile->size(), QFile::MapPrivateOption));
90 if(ptr)
91 {
92 // worked
93 m_data = QByteArray::fromRawData(ptr, pcborfile->size());
94 mpa_cborReader->addData(m_data);
95 }
96 else if(pcborfile->isSequential())
97 {
98 // details requires full contents, so allocate memory
99 m_data = pcborfile->readAll();
100 mpa_cborReader->addData(m_data);
101 }
102 else
103 {
104 // just use the QIODevice
105 mpa_cborReader->setDevice(pcborfile);
106 }
107}
virtual void close()
convenient function to clean pointer before leaving
simple override of the raw QCborStreamReader This adds convenient functions to put CBOR data into C++...