Skip to content

Commit 5794fce

Browse files
First changes
1 parent d1323c5 commit 5794fce

File tree

12 files changed

+463
-307
lines changed

12 files changed

+463
-307
lines changed

YUViewLib/src/common/Functions.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,21 @@ std::optional<int> toInt(const std::string_view text)
236236
return value;
237237
}
238238

239+
std::vector<std::string> splitString(const std::string_view text, const char delimiter)
240+
{
241+
std::vector<std::string> results;
242+
243+
auto currentIt = text.begin();
244+
while (true)
245+
{
246+
const auto nextDelimiter = std::find(currentIt, text.end(), delimiter);
247+
results.emplace_back(currentIt, nextDelimiter);
248+
if (nextDelimiter == text.end())
249+
return results;
250+
currentIt = nextDelimiter + 1;
251+
}
252+
253+
return results;
254+
}
255+
239256
} // namespace functions

YUViewLib/src/common/Functions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,6 @@ template <typename T, typename R> inline T clip(T val, Range<R> range)
101101
std::optional<unsigned> toUnsigned(const std::string_view text);
102102
std::optional<int> toInt(const std::string_view text);
103103

104+
std::vector<std::string> splitString(const std::string_view text, const char delimiter);
105+
104106
} // namespace functions
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/* This file is part of YUView - The YUV player with advanced analytics toolset
2+
* <https://github.com/IENT/YUView>
3+
* Copyright (C) 2015 Institut für Nachrichtentechnik, RWTH Aachen University, GERMANY
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation; either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* In addition, as a special exception, the copyright holders give
11+
* permission to link the code of portions of this program with the
12+
* OpenSSL library under certain conditions as described in each
13+
* individual source file, and distribute linked combinations including
14+
* the two.
15+
*
16+
* You must obey the GNU General Public License in all respects for all
17+
* of the code used other than OpenSSL. If you modify file(s) with this
18+
* exception, you may extend this exception to your version of the
19+
* file(s), but you are not obligated to do so. If you do not wish to do
20+
* so, delete this exception statement from your version. If you delete
21+
* this exception statement from all source files in the program, then
22+
* also delete it here.
23+
*
24+
* This program is distributed in the hope that it will be useful,
25+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
26+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+
* GNU General Public License for more details.
28+
*
29+
* You should have received a copy of the GNU General Public License
30+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
31+
*/
32+
33+
#include "DataSourceLineReader.h"
34+
35+
namespace datasource
36+
{
37+
38+
DataSourceLineReader::DataSourceLineReader(std::unique_ptr<IDataSource> dataSource)
39+
: dataSource(std::move(dataSource))
40+
{
41+
}
42+
43+
std::vector<InfoItem> DataSourceLineReader::getInfoList() const
44+
{
45+
return this->dataSource->getInfoList();
46+
};
47+
48+
bool DataSourceLineReader::atEnd() const
49+
{
50+
return this->dataSource->atEnd();
51+
}
52+
53+
bool DataSourceLineReader::isOk() const
54+
{
55+
return this->dataSource->isOk();
56+
}
57+
58+
std::int64_t DataSourceLineReader::getPosition() const
59+
{
60+
return this->dataSource->getPosition();
61+
}
62+
63+
bool DataSourceLineReader::wasSourceModified() const
64+
{
65+
return this->dataSource->wasSourceModified();
66+
}
67+
68+
bool DataSourceLineReader::seek(const std::int64_t pos)
69+
{
70+
return this->dataSource->seek(pos);
71+
}
72+
73+
std::string DataSourceLineReader::readLine()
74+
{
75+
// Fill buffer and read ...
76+
}
77+
78+
} // namespace datasource
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/* This file is part of YUView - The YUV player with advanced analytics toolset
2+
* <https://github.com/IENT/YUView>
3+
* Copyright (C) 2015 Institut für Nachrichtentechnik, RWTH Aachen University, GERMANY
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation; either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* In addition, as a special exception, the copyright holders give
11+
* permission to link the code of portions of this program with the
12+
* OpenSSL library under certain conditions as described in each
13+
* individual source file, and distribute linked combinations including
14+
* the two.
15+
*
16+
* You must obey the GNU General Public License in all respects for all
17+
* of the code used other than OpenSSL. If you modify file(s) with this
18+
* exception, you may extend this exception to your version of the
19+
* file(s), but you are not obligated to do so. If you do not wish to do
20+
* so, delete this exception statement from your version. If you delete
21+
* this exception statement from all source files in the program, then
22+
* also delete it here.
23+
*
24+
* This program is distributed in the hope that it will be useful,
25+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
26+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+
* GNU General Public License for more details.
28+
*
29+
* You should have received a copy of the GNU General Public License
30+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
31+
*/
32+
33+
#pragma once
34+
35+
#include "IDataSource.h"
36+
37+
namespace datasource
38+
{
39+
40+
class DataSourceLineReader
41+
{
42+
public:
43+
DataSourceLineReader(std::unique_ptr<IDataSource> dataSource);
44+
45+
[[nodiscard]] std::vector<InfoItem> getInfoList() const;
46+
[[nodiscard]] bool atEnd() const;
47+
[[nodiscard]] bool isOk() const;
48+
[[nodiscard]] std::int64_t getPosition() const;
49+
50+
[[nodiscard]] bool wasSourceModified() const;
51+
52+
[[nodiscard]] bool seek(const std::int64_t pos);
53+
[[nodiscard]] std::string readLine();
54+
55+
[[nodiscard]] std::optional<std::int64_t> getFileSize() const;
56+
57+
protected:
58+
std::unique_ptr<IDataSource> dataSource;
59+
60+
std::string textBuffer;
61+
};
62+
63+
} // namespace datasource

YUViewLib/src/filesource/FileSource.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,15 @@ bool FileSource::getAndResetFileChangedFlag()
151151
return b;
152152
}
153153

154+
std::string FileSource::readLine()
155+
{
156+
if (!this->isFileOpened)
157+
return {};
158+
159+
const auto line = this->srcFile.readLine();
160+
return line.toStdString();
161+
}
162+
154163
void FileSource::updateFileWatchSetting()
155164
{
156165
// Install a file watcher if file watching is active in the settings.

YUViewLib/src/filesource/FileSource.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class FileSource : public QObject
8484
bool isOk() const { return this->isFileOpened; }
8585

8686
virtual bool atEnd() const { return !this->isFileOpened ? true : this->srcFile.atEnd(); }
87-
QByteArray readLine() { return !this->isFileOpened ? QByteArray() : this->srcFile.readLine(); }
87+
std::string readLine();
8888
virtual bool seek(int64_t pos) { return !this->isFileOpened ? false : this->srcFile.seek(pos); }
8989
int64_t pos() { return !this->isFileOpened ? 0 : this->srcFile.pos(); }
9090

YUViewLib/src/statistics/StatisticsFileBase.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@
3535
namespace stats
3636
{
3737

38-
StatisticsFileBase::StatisticsFileBase(const QString &filename)
38+
StatisticsFileBase::StatisticsFileBase(std::unique_ptr<datasource::IDataSource> &&dataSource)
3939
{
40-
this->file.openFile(filename.toStdString());
41-
if (!this->file.isOk())
40+
this->dataSource = std::move(dataSource);
41+
42+
if (!this->dataSource || !this->dataSource->isOk())
4243
{
43-
this->errorMessage = "Error opening file " + filename;
44+
this->errorMessage = "Invalid data source";
4445
this->error = true;
4546
}
4647
}
@@ -54,7 +55,7 @@ InfoData StatisticsFileBase::getInfo() const
5455
{
5556
InfoData info("Statistics File info");
5657

57-
for (const auto &infoItem : this->file.getFileInfoList())
58+
for (const auto &infoItem : this->dataSource->getInfoList())
5859
info.items.append(infoItem);
5960
info.items.append(InfoItem("Sorted by POC"sv, this->fileSortedByPOC ? "Yes" : "No"));
6061
info.items.append(InfoItem("Parsing:", std::to_string(this->parsingProgress) + "..."));

YUViewLib/src/statistics/StatisticsFileBase.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
#pragma once
3434

35-
#include "filesource/FileSource.h"
35+
#include "dataSource/IDataSource.h"
3636
#include "statistics/StatisticsData.h"
3737

3838
#include <QObject>
@@ -47,7 +47,7 @@ class StatisticsFileBase : public QObject
4747
Q_OBJECT
4848

4949
public:
50-
StatisticsFileBase(const QString &filename);
50+
StatisticsFileBase(std::unique_ptr<datasource::IDataSource> &&dataSource);
5151
virtual ~StatisticsFileBase();
5252

5353
// Parse the whole file and get the positions where a new POC/type starts and save them. Later we
@@ -59,13 +59,11 @@ class StatisticsFileBase : public QObject
5959

6060
operator bool() const { return !this->error; };
6161

62-
// -1 if it could not be parser from the file
63-
virtual double getFramerate() const { return -1; }
62+
virtual std::optional<double> getFramerate() const { return {}; }
6463

6564
int getMaxPoc() const { return this->maxPOC; }
6665

67-
bool isFileChanged() { return this->file.getAndResetFileChangedFlag(); }
68-
void updateSettings() { this->file.updateFileWatchSetting(); }
66+
bool isFileChanged() const { return this->dataSource->wasSourceModified(); }
6967

7068
InfoData getInfo() const;
7169

@@ -77,7 +75,7 @@ class StatisticsFileBase : public QObject
7775
void readPOC(int newPoc);
7876

7977
protected:
80-
FileSource file;
78+
std::unique_ptr<datasource::IDataSource> dataSource;
8179

8280
// Set if the file is sorted by POC and the types are 'random' within this POC (true)
8381
// or if the file is sorted by typeID and the POC is 'random'

0 commit comments

Comments
 (0)