KDEGames

virtualfileqt-openal.cpp
1 /*
2  SPDX-FileCopyrightText: 2019 Alexander Potashev <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-only
5 */
6 
7 #include "virtualfileqt-openal.h"
8 
9 VirtualFileQt::VirtualFileQt(const QString &path)
10  : m_file(path)
11 {
12 }
13 
14 bool VirtualFileQt::open()
15 {
16  return m_file.open(QIODevice::ReadOnly);
17 }
18 
19 int64_t VirtualFileQt::getFileLen() const
20 {
21  return static_cast<int64_t>(m_file.size());
22 }
23 
24 int64_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 
38 int64_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 
43 int64_t VirtualFileQt::write(const void *, int64_t)
44 {
45  // Writing is not supported.
46  return 0;
47 }
48 
49 int64_t VirtualFileQt::tell()
50 {
51  return static_cast<int64_t>(m_file.pos());
52 }
53 
54 sf_count_t sf_get_filelen(void *user_data)
55 {
56  return static_cast<sf_count_t>(VirtualFileQt::get(user_data)->getFileLen());
57 }
58 
59 sf_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 
64 sf_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 
69 sf_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 
74 sf_count_t sf_tell(void *user_data)
75 {
76  return static_cast<sf_count_t>(VirtualFileQt::get(user_data)->tell());
77 }
78 
79 SF_VIRTUAL_IO sfVirtualIO = {
80  sf_get_filelen,
81  sf_seek,
82  sf_read,
83  sf_write,
84  sf_tell,
85 };
86 
87 SF_VIRTUAL_IO &VirtualFileQt::getSndfileVirtualIO()
88 {
89  return sfVirtualIO;
90 }
91 
92 VirtualFileQt *VirtualFileQt::get(void *user_data)
93 {
94  return static_cast<VirtualFileQt*>(user_data);
95 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Dec 7 2021 22:34:15 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.