KDEGames

virtualfileqt-openal.cpp
1 /***************************************************************************
2  * Copyright 2019 Alexander Potashev <[email protected]> *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU Library General Public License *
6  * version 2 as published by the Free Software Foundation *
7  * *
8  * This program is distributed in the hope that it will be useful, *
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
11  * GNU Library General Public License for more details. *
12  * *
13  * You should have received a copy of the GNU Library General Public *
14  * License along with this program; if not, write to the *
15  * Free Software Foundation, Inc., *
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
17  ***************************************************************************/
18 
19 #include "virtualfileqt-openal.h"
20 
21 VirtualFileQt::VirtualFileQt(const QString &path)
22  : m_file(path)
23 {
24 }
25 
26 bool VirtualFileQt::open()
27 {
28  return m_file.open(QIODevice::ReadOnly);
29 }
30 
31 int64_t VirtualFileQt::getFileLen() const
32 {
33  return static_cast<int64_t>(m_file.size());
34 }
35 
36 int64_t VirtualFileQt::seek(int64_t offset, int whence)
37 {
38  switch (whence) {
39  case SEEK_SET:
40  return m_file.seek(static_cast<quint64>(offset)) ? 0 : -1;
41  case SEEK_CUR:
42  return m_file.seek(m_file.pos() + static_cast<quint64>(offset)) ? 0 : -1;
43  case SEEK_END:
44  return m_file.seek(m_file.size() + static_cast<quint64>(offset)) ? 0 : -1;
45  default:
46  return -1;
47  }
48 }
49 
50 int64_t VirtualFileQt::read(void *ptr, int64_t count)
51 {
52  return static_cast<int64_t>(m_file.read(static_cast<char*>(ptr), static_cast<qint64>(count)));
53 }
54 
55 int64_t VirtualFileQt::write(const void *, int64_t)
56 {
57  // Writing is not supported.
58  return 0;
59 }
60 
61 int64_t VirtualFileQt::tell()
62 {
63  return static_cast<int64_t>(m_file.pos());
64 }
65 
66 sf_count_t sf_get_filelen(void *user_data)
67 {
68  return static_cast<sf_count_t>(VirtualFileQt::get(user_data)->getFileLen());
69 }
70 
71 sf_count_t sf_seek(sf_count_t offset, int whence, void *user_data)
72 {
73  return static_cast<sf_count_t>(VirtualFileQt::get(user_data)->seek(static_cast<int64_t>(offset), whence));
74 }
75 
76 sf_count_t sf_read(void *ptr, sf_count_t count, void *user_data)
77 {
78  return static_cast<sf_count_t>(VirtualFileQt::get(user_data)->read(ptr, static_cast<int64_t>(count)));
79 }
80 
81 sf_count_t sf_write(const void *ptr, sf_count_t count, void *user_data)
82 {
83  return static_cast<sf_count_t>(VirtualFileQt::get(user_data)->write(ptr, static_cast<int64_t>(count)));
84 }
85 
86 sf_count_t sf_tell(void *user_data)
87 {
88  return static_cast<sf_count_t>(VirtualFileQt::get(user_data)->tell());
89 }
90 
91 SF_VIRTUAL_IO sfVirtualIO = {
92  sf_get_filelen,
93  sf_seek,
94  sf_read,
95  sf_write,
96  sf_tell,
97 };
98 
99 SF_VIRTUAL_IO &VirtualFileQt::getSndfileVirtualIO()
100 {
101  return sfVirtualIO;
102 }
103 
104 VirtualFileQt *VirtualFileQt::get(void *user_data)
105 {
106  return static_cast<VirtualFileQt*>(user_data);
107 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Nov 26 2020 22:36:18 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.