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-2024 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
39namespace sf
40{
41class InputStream;
42class SoundFileReader;
43class SoundFileWriter;
44
50{
51public:
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
149private:
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
#define SFML_AUDIO_API
Abstract class for custom file input streams.
Manages and instantiates sound file readers and writers.
static void unregisterWriter()
Unregister a writer.
static std::unique_ptr< SoundFileReader > createReaderFromFilename(const std::filesystem::path &filename)
Instantiate the right reader for the given file on disk.
static std::unique_ptr< SoundFileWriter > createWriterFromFilename(const std::filesystem::path &filename)
Instantiate the right writer for the given file on disk.
static std::unique_ptr< SoundFileReader > createReaderFromStream(InputStream &stream)
Instantiate the right codec for the given file in stream.
static std::unique_ptr< SoundFileReader > createReaderFromMemory(const void *data, std::size_t sizeInBytes)
Instantiate the right codec for the given file in memory.
static void registerWriter()
Register a new writer.
static void unregisterReader()
Unregister a reader.
static void registerReader()
Register a new reader.
static bool isReaderRegistered()
Check if a reader is registered.
static bool isWriterRegistered()
Check if a writer is registered.