KDb

KDbRecordData.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2002 Lucijan Busch <lucijan@gmx.at>
3 Copyright (C) 2003 Daniel Molkentin <molkentin@kde.org>
4 Copyright (C) 2003-2016 Jarosław Staniek <staniek@kde.org>
5
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this program; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20
21 Original Author: Till Busch <till@bux.at>
22 Original Project: buX (www.bux.at)
23*/
24
25#include "KDbRecordData.h"
26#include "KDbGlobal.h"
27#include "KDbUtils.h"
28#include "kdb_debug.h"
29
30QVariant KDbRecordData::s_null;
31
32QDebug operator<<(QDebug dbg, const KDbRecordData& data)
33{
34 if (data.isEmpty()) {
35 dbg.nospace() << QLatin1String("EMPTY RECORD DATA");
36 }
37 else {
38 dbg.nospace() << "RECORD DATA (" << data.size() << " COLUMNS):";
39 for (int i = 0; i < data.size(); i++) {
40 dbg.nospace()
41 << " " << i << ":" << KDbUtils::squeezedValue(data[i]);
42 }
43 }
44 return dbg.space();
45}
46
48{
49 if (m_numCols > 0) {
50 for (int i = 0; i < m_numCols; i++)
51 free(m_data[i]);
52 free(m_data);
53 m_data = nullptr;
54 m_numCols = 0;
55 }
56}
57
58void KDbRecordData::resize(int numCols)
59{
60 if (m_numCols == numCols)
61 return;
62 else if (m_numCols < numCols) { // grow
63 m_data = (QVariant **)realloc(m_data, numCols * sizeof(QVariant *));
64 memset(m_data + m_numCols, 0, (numCols - m_numCols) * sizeof(QVariant *));
65 m_numCols = numCols;
66 } else { // shrink
67 for (int i = numCols; i < m_numCols; i++)
68 delete m_data[i];
69 m_data = (QVariant **)realloc(m_data, numCols * sizeof(QVariant *));
70 m_numCols = numCols;
71 }
72}
73
75{
76 for (int i = 0; i < m_numCols; i++) {
77 delete m_data[i];
78 m_data[i] = nullptr;
79 }
80}
81
83{
84 QList<QVariant> list;
85 list.reserve(m_numCols);
86 for (int i = 0; i < m_numCols; ++i) {
87 list.append(*m_data[i]);
88 }
89 return list;
90}
Structure for storing single record with type information.
QList< QVariant > toList() const
Converts this record to QList<QVariant>
void resize(int numCols)
QDebug operator<<(QDebug dbg, const DcrawInfoContainer &c)
QDebug & nospace()
QDebug & space()
void append(QList< T > &&value)
void reserve(qsizetype size)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:00:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.