SFML 3.0.2
Loading...
Searching...
No Matches
SoundFileFactory.hpp
Go to the documentation of this file.
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2025 Laurent Gomila (laurent@sfml-dev.org)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#pragma once
26
28// Headers
30#include <SFML/Audio/Export.hpp>
31
32#include <filesystem>
33#include <memory>
34#include <unordered_map>
35
36#include <cstddef>
37
38
39 namespace sf
40{
41 class InputStream;
42 class SoundFileReader;
43 class SoundFileWriter;
44
49 class SFML_AUDIO_API SoundFileFactory
50{
51 public:
58 template <typename T>
59 static void registerReader();
60
67 template <typename T>
68 static void unregisterReader();
69
74 template <typename T>
75 [[nodiscard]] static bool isReaderRegistered();
76
83 template <typename T>
84 static void registerWriter();
85
92 template <typename T>
93 static void unregisterWriter();
94
99 template <typename T>
100 [[nodiscard]] static bool isWriterRegistered();
101
112 [[nodiscard]] static std::unique_ptr<SoundFileReader> createReaderFromFilename(const std::filesystem::path& filename);
113
125 [[nodiscard]] static std::unique_ptr<SoundFileReader> createReaderFromMemory(const void* data, std::size_t sizeInBytes);
126
137 [[nodiscard]] static std::unique_ptr<SoundFileReader> createReaderFromStream(InputStream& stream);
138
147 [[nodiscard]] static std::unique_ptr<SoundFileWriter> createWriterFromFilename(const std::filesystem::path& filename);
148
149 private:
151 // Types
153 template <typename T>
154 using CreateFnPtr = std::unique_ptr<T> (*)();
155
156 using ReaderCheckFnPtr = bool (*)(InputStream&);
157 using WriterCheckFnPtr = bool (*)(const std::filesystem::path&);
158
159 using ReaderFactoryMap = std::unordered_map<CreateFnPtr<SoundFileReader>, ReaderCheckFnPtr>;
160 using WriterFactoryMap = std::unordered_map<CreateFnPtr<SoundFileWriter>, WriterCheckFnPtr>;
161
163 // Static member functions
165 [[nodiscard]] static ReaderFactoryMap& getReaderFactoryMap();
166 [[nodiscard]] static WriterFactoryMap& getWriterFactoryMap();
167};
168
169} // namespace sf
170
171#include <SFML/Audio/SoundFileFactory.inl>
172
173
Export.hpp
SFML_AUDIO_API
#define SFML_AUDIO_API
Definition Audio/Export.hpp:42
sf::InputStream
Abstract class for custom file input streams.
Definition InputStream.hpp:46
sf::SoundFileFactory
Manages and instantiates sound file readers and writers.
Definition SoundFileFactory.hpp:50
sf::SoundFileFactory::unregisterWriter
static void unregisterWriter()
Unregister a writer.
sf::SoundFileFactory::createReaderFromFilename
static std::unique_ptr< SoundFileReader > createReaderFromFilename(const std::filesystem::path &filename)
Instantiate the right reader for the given file on disk.
sf::SoundFileFactory::createWriterFromFilename
static std::unique_ptr< SoundFileWriter > createWriterFromFilename(const std::filesystem::path &filename)
Instantiate the right writer for the given file on disk.
sf::SoundFileFactory::createReaderFromStream
static std::unique_ptr< SoundFileReader > createReaderFromStream(InputStream &stream)
Instantiate the right codec for the given file in stream.
sf::SoundFileFactory::createReaderFromMemory
static std::unique_ptr< SoundFileReader > createReaderFromMemory(const void *data, std::size_t sizeInBytes)
Instantiate the right codec for the given file in memory.
sf::SoundFileFactory::registerWriter
static void registerWriter()
Register a new writer.
sf::SoundFileFactory::unregisterReader
static void unregisterReader()
Unregister a reader.
sf::SoundFileFactory::registerReader
static void registerReader()
Register a new reader.
sf::SoundFileFactory::isReaderRegistered
static bool isReaderRegistered()
Check if a reader is registered.
sf::SoundFileFactory::isWriterRegistered
static bool isWriterRegistered()
Check if a writer is registered.
sf::SoundFileReader
Abstract base class for sound file decoding.
Definition SoundFileReader.hpp:49
sf::SoundFileWriter
Abstract base class for sound file encoding.
Definition SoundFileWriter.hpp:47
sf
Definition AudioResource.hpp:36