File indexing completed on 2024-12-22 03:35:43

0001 /*
0002     File                 : BinaryFilter.h
0003     Project              : LabPlot
0004     Description          : Binary I/O-filter
0005     --------------------------------------------------------------------
0006     SPDX-FileCopyrightText: 2015-2018 Stefan Gerlach <stefan.gerlach@uni.kn>
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 #ifndef BINARYFILTER_H
0010 #define BINARYFILTER_H
0011 
0012 #include "backend/datasources/filters/AbstractFileFilter.h"
0013 #include <QDataStream>
0014 #include <limits>
0015 
0016 class BinaryFilterPrivate;
0017 class QIODevice;
0018 
0019 class BinaryFilter : public AbstractFileFilter {
0020     Q_OBJECT
0021     Q_ENUMS(DataType)
0022 
0023 public:
0024     // TODO; use ColumnMode when it supports all these types
0025     enum class DataType { INT8, INT16, INT32, INT64, UINT8, UINT16, UINT32, UINT64, REAL32, REAL64 };
0026 
0027     BinaryFilter();
0028     ~BinaryFilter() override;
0029 
0030     static QStringList dataTypes();
0031     static int dataSize(BinaryFilter::DataType);
0032     static size_t rowNumber(const QString& fileName, size_t vectors, BinaryFilter::DataType, size_t maxRows = std::numeric_limits<std::size_t>::max());
0033     static QString fileInfoString(const QString&);
0034 
0035     // read data from any device
0036     void
0037     readDataFromDevice(QIODevice&, AbstractDataSource* = nullptr, AbstractFileFilter::ImportMode = AbstractFileFilter::ImportMode::Replace, int lines = -1);
0038     void readDataFromFile(const QString& fileName, AbstractDataSource*, AbstractFileFilter::ImportMode = AbstractFileFilter::ImportMode::Replace) override;
0039     void write(const QString& fileName, AbstractDataSource*) override;
0040     QVector<QStringList> preview(const QString& fileName, int lines);
0041 
0042     void setVectors(const size_t);
0043     size_t vectors() const;
0044 
0045     void setDataType(const BinaryFilter::DataType);
0046     BinaryFilter::DataType dataType() const;
0047     void setByteOrder(const QDataStream::ByteOrder);
0048     QDataStream::ByteOrder byteOrder() const;
0049     void setSkipStartBytes(const size_t);
0050     size_t skipStartBytes() const;
0051     void setStartRow(const int);
0052     int startRow() const;
0053     void setEndRow(const int);
0054     int endRow() const;
0055     void setSkipBytes(const size_t);
0056     size_t skipBytes() const;
0057     void setCreateIndexEnabled(const bool);
0058 
0059     void setAutoModeEnabled(const bool);
0060     bool isAutoModeEnabled() const;
0061 
0062     void save(QXmlStreamWriter*) const override;
0063     bool load(XmlStreamReader*) override;
0064 
0065 private:
0066     std::unique_ptr<BinaryFilterPrivate> const d;
0067     friend class BinaryFilterPrivate;
0068 };
0069 
0070 #endif