LibrePCB Developers Documentation
csvfile.h
Go to the documentation of this file.
1/*
2 * LibrePCB - Professional EDA for everyone!
3 * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4 * https://librepcb.org/
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (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
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef LIBREPCB_CORE_CSVFILE_H
21#define LIBREPCB_CORE_CSVFILE_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include <QtCore>
27
28/*******************************************************************************
29 * Namespace / Forward Declarations
30 ******************************************************************************/
31namespace librepcb {
32
33class FilePath;
34
35/*******************************************************************************
36 * Class CsvFile
37 ******************************************************************************/
38
58class CsvFile final {
59 Q_DECLARE_TR_FUNCTIONS(CsvFile)
60
61public:
62 // Constructors / Destructor
63 CsvFile() noexcept;
64 CsvFile(const CsvFile& other) = delete;
65 ~CsvFile() noexcept;
66
72 const QString& getComment() const noexcept { return mComment; }
73
79 const QStringList& getHeader() const noexcept { return mHeader; }
80
86 const QList<QStringList>& getValues() const noexcept { return mValues; }
87
93 void setComment(const QString& comment) noexcept;
94
102 void setHeader(const QStringList& header) noexcept;
103
112 void addValue(const QStringList& value);
113
119 QString toString() const noexcept;
120
128 void saveToFile(const FilePath& csvFp) const;
129
130 // Operator Overloadings
131 CsvFile& operator=(const CsvFile& rhs) = delete;
132
133private: // Methods
134 QString getCommentLines() const noexcept;
135 QString lineToString(const QStringList& line) const noexcept;
136 static QString escapeValue(const QString& value) noexcept;
137
138private: // Data
139 QString mComment;
140 QStringList mHeader;
141 QList<QStringList> mValues;
142};
143
144/*******************************************************************************
145 * End of File
146 ******************************************************************************/
147
148} // namespace librepcb
149
150#endif
The CsvFile class represents a comma-separated values (CSV) file.
Definition: csvfile.h:58
void setHeader(const QStringList &header) noexcept
Set the header items.
Definition: csvfile.cpp:54
static QString escapeValue(const QString &value) noexcept
Definition: csvfile.cpp:116
const QStringList & getHeader() const noexcept
Get the CSV header items.
Definition: csvfile.h:79
~CsvFile() noexcept
Definition: csvfile.cpp:43
QString getCommentLines() const noexcept
Definition: csvfile.cpp:84
CsvFile(const CsvFile &other)=delete
QStringList mHeader
Definition: csvfile.h:140
QString toString() const noexcept
Build CSV file content and return it as a string.
Definition: csvfile.cpp:67
CsvFile() noexcept
Definition: csvfile.cpp:40
void addValue(const QStringList &value)
Add a row of values.
Definition: csvfile.cpp:59
const QList< QStringList > & getValues() const noexcept
Get the CSV values.
Definition: csvfile.h:86
QString lineToString(const QStringList &line) const noexcept
Definition: csvfile.cpp:99
QList< QStringList > mValues
Definition: csvfile.h:141
void setComment(const QString &comment) noexcept
Set file comment.
Definition: csvfile.cpp:50
QString mComment
Definition: csvfile.h:139
void saveToFile(const FilePath &csvFp) const
Write CSV file content to a file.
Definition: csvfile.cpp:76
const QString & getComment() const noexcept
Get the comment of the file.
Definition: csvfile.h:72
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:129
Definition: occmodel.cpp:77