KDEGames

virtualfileqt-openal.cpp
1/*
2 SPDX-FileCopyrightText: 2019 Alexander Potashev <aspotashev@gmail.com>
3
4 SPDX-License-Identifier: LGPL-2.0-only
5*/
6
7#include "virtualfileqt-openal.h"
8
9VirtualFileQt::VirtualFileQt(const QString &path)
10 : m_file(path)
11{
12}
13
14bool VirtualFileQt::open()
15{
16 return m_file.open(QIODevice::ReadOnly);
17}
18
19int64_t VirtualFileQt::getFileLen() const
20{
21 return static_cast<int64_t>(m_file.size());
22}
23
24int64_t VirtualFileQt::seek(int64_t offset, int whence)
25{
26 switch (whence) {
27 case SEEK_SET:
28 return m_file.seek(static_cast<quint64>(offset)) ? m_file.pos() : -1;
29 case SEEK_CUR:
30 return m_file.seek(m_file.pos() + static_cast<quint64>(offset)) ? m_file.pos() : -1;
31 case SEEK_END:
32 return m_file.seek(m_file.size() + static_cast<quint64>(offset)) ? m_file.pos() : -1;
33 default:
34 return -1;
35 }
36}
37
38int64_t VirtualFileQt::read(void *ptr, int64_t count)
39{
40 return static_cast<int64_t>(m_file.read(static_cast<char *>(ptr), static_cast<qint64>(count)));
41}
42
43int64_t VirtualFileQt::write(const void *, int64_t)
44{
45 // Writing is not supported.
46 return 0;
47}
48
49int64_t VirtualFileQt::tell()
50{
51 return static_cast<int64_t>(m_file.pos());
52}
53
54sf_count_t sf_get_filelen(void *user_data)
55{
56 return static_cast<sf_count_t>(VirtualFileQt::get(user_data)->getFileLen());
57}
58
59sf_count_t sf_seek(sf_count_t offset, int whence, void *user_data)
60{
61 return static_cast<sf_count_t>(VirtualFileQt::get(user_data)->seek(static_cast<int64_t>(offset), whence));
62}
63
64sf_count_t sf_read(void *ptr, sf_count_t count, void *user_data)
65{
66 return static_cast<sf_count_t>(VirtualFileQt::get(user_data)->read(ptr, static_cast<int64_t>(count)));
67}
68
69sf_count_t sf_write(const void *ptr, sf_count_t count, void *user_data)
70{
71 return static_cast<sf_count_t>(VirtualFileQt::get(user_data)->write(ptr, static_cast<int64_t>(count)));
72}
73
74sf_count_t sf_tell(void *user_data)
75{
76 return static_cast<sf_count_t>(VirtualFileQt::get(user_data)->tell());
77}
78
79SF_VIRTUAL_IO sfVirtualIO = {
80 sf_get_filelen,
81 sf_seek,
82 sf_read,
83 sf_write,
84 sf_tell,
85};
86
87SF_VIRTUAL_IO &VirtualFileQt::getSndfileVirtualIO()
88{
89 return sfVirtualIO;
90}
91
92VirtualFileQt *VirtualFileQt::get(void *user_data)
93{
94 return static_cast<VirtualFileQt *>(user_data);
95}
QString path(const QString &relativePath)
bool open(FILE *fh, OpenMode mode, FileHandleFlags handleFlags)
virtual qint64 size() const const override
virtual qint64 pos() const const override
virtual bool seek(qint64 pos) override
QByteArray read(qint64 maxSize)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:09:35 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.