|
|
|||
File indexing completed on 2026-06-02 08:58:13
0001 //////////////////////////////////////////////////////////// 0002 // 0003 // SFML - Simple and Fast Multimedia Library 0004 // Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org) 0005 // 0006 // This software is provided 'as-is', without any express or implied warranty. 0007 // In no event will the authors be held liable for any damages arising from the use of this software. 0008 // 0009 // Permission is granted to anyone to use this software for any purpose, 0010 // including commercial applications, and to alter it and redistribute it freely, 0011 // subject to the following restrictions: 0012 // 0013 // 1. The origin of this software must not be misrepresented; 0014 // you must not claim that you wrote the original software. 0015 // If you use this software in a product, an acknowledgment 0016 // in the product documentation would be appreciated but is not required. 0017 // 0018 // 2. Altered source versions must be plainly marked as such, 0019 // and must not be misrepresented as being the original software. 0020 // 0021 // 3. This notice may not be removed or altered from any source distribution. 0022 // 0023 //////////////////////////////////////////////////////////// 0024 0025 #ifndef SFML_SOUNDFILEFACTORY_HPP 0026 #define SFML_SOUNDFILEFACTORY_HPP 0027 0028 //////////////////////////////////////////////////////////// 0029 // Headers 0030 //////////////////////////////////////////////////////////// 0031 #include <SFML/Audio/Export.hpp> 0032 #include <string> 0033 #include <vector> 0034 0035 0036 namespace sf 0037 { 0038 class InputStream; 0039 class SoundFileReader; 0040 class SoundFileWriter; 0041 0042 //////////////////////////////////////////////////////////// 0043 /// \brief Manages and instantiates sound file readers and writers 0044 /// 0045 //////////////////////////////////////////////////////////// 0046 class SFML_AUDIO_API SoundFileFactory 0047 { 0048 public: 0049 0050 //////////////////////////////////////////////////////////// 0051 /// \brief Register a new reader 0052 /// 0053 /// \see unregisterReader 0054 /// 0055 //////////////////////////////////////////////////////////// 0056 template <typename T> 0057 static void registerReader(); 0058 0059 //////////////////////////////////////////////////////////// 0060 /// \brief Unregister a reader 0061 /// 0062 /// \see registerReader 0063 /// 0064 //////////////////////////////////////////////////////////// 0065 template <typename T> 0066 static void unregisterReader(); 0067 0068 //////////////////////////////////////////////////////////// 0069 /// \brief Register a new writer 0070 /// 0071 /// \see unregisterWriter 0072 /// 0073 //////////////////////////////////////////////////////////// 0074 template <typename T> 0075 static void registerWriter(); 0076 0077 //////////////////////////////////////////////////////////// 0078 /// \brief Unregister a writer 0079 /// 0080 /// \see registerWriter 0081 /// 0082 //////////////////////////////////////////////////////////// 0083 template <typename T> 0084 static void unregisterWriter(); 0085 0086 //////////////////////////////////////////////////////////// 0087 /// \brief Instantiate the right reader for the given file on disk 0088 /// 0089 /// It's up to the caller to release the returned reader 0090 /// 0091 /// \param filename Path of the sound file 0092 /// 0093 /// \return A new sound file reader that can read the given file, or null if no reader can handle it 0094 /// 0095 /// \see createReaderFromMemory, createReaderFromStream 0096 /// 0097 //////////////////////////////////////////////////////////// 0098 static SoundFileReader* createReaderFromFilename(const std::string& filename); 0099 0100 //////////////////////////////////////////////////////////// 0101 /// \brief Instantiate the right codec for the given file in memory 0102 /// 0103 /// It's up to the caller to release the returned reader 0104 /// 0105 /// \param data Pointer to the file data in memory 0106 /// \param sizeInBytes Total size of the file data, in bytes 0107 /// 0108 /// \return A new sound file codec that can read the given file, or null if no codec can handle it 0109 /// 0110 /// \see createReaderFromFilename, createReaderFromStream 0111 /// 0112 //////////////////////////////////////////////////////////// 0113 static SoundFileReader* createReaderFromMemory(const void* data, std::size_t sizeInBytes); 0114 0115 //////////////////////////////////////////////////////////// 0116 /// \brief Instantiate the right codec for the given file in stream 0117 /// 0118 /// It's up to the caller to release the returned reader 0119 /// 0120 /// \param stream Source stream to read from 0121 /// 0122 /// \return A new sound file codec that can read the given file, or null if no codec can handle it 0123 /// 0124 /// \see createReaderFromFilename, createReaderFromMemory 0125 /// 0126 //////////////////////////////////////////////////////////// 0127 static SoundFileReader* createReaderFromStream(InputStream& stream); 0128 0129 //////////////////////////////////////////////////////////// 0130 /// \brief Instantiate the right writer for the given file on disk 0131 /// 0132 /// It's up to the caller to release the returned writer 0133 /// 0134 /// \param filename Path of the sound file 0135 /// 0136 /// \return A new sound file writer that can write given file, or null if no writer can handle it 0137 /// 0138 //////////////////////////////////////////////////////////// 0139 static SoundFileWriter* createWriterFromFilename(const std::string& filename); 0140 0141 private: 0142 0143 //////////////////////////////////////////////////////////// 0144 // Types 0145 //////////////////////////////////////////////////////////// 0146 struct ReaderFactory 0147 { 0148 bool (*check)(InputStream&); 0149 SoundFileReader* (*create)(); 0150 }; 0151 typedef std::vector<ReaderFactory> ReaderFactoryArray; 0152 0153 struct WriterFactory 0154 { 0155 bool (*check)(const std::string&); 0156 SoundFileWriter* (*create)(); 0157 }; 0158 typedef std::vector<WriterFactory> WriterFactoryArray; 0159 0160 //////////////////////////////////////////////////////////// 0161 // Static member data 0162 //////////////////////////////////////////////////////////// 0163 static ReaderFactoryArray s_readers; //!< List of all registered readers 0164 static WriterFactoryArray s_writers; //!< List of all registered writers 0165 }; 0166 0167 } // namespace sf 0168 0169 #include <SFML/Audio/SoundFileFactory.inl> 0170 0171 #endif // SFML_SOUNDFILEFACTORY_HPP 0172 0173 0174 //////////////////////////////////////////////////////////// 0175 /// \class sf::SoundFileFactory 0176 /// \ingroup audio 0177 /// 0178 /// This class is where all the sound file readers and writers are 0179 /// registered. You should normally only need to use its registration 0180 /// and unregistration functions; readers/writers creation and manipulation 0181 /// are wrapped into the higher-level classes sf::InputSoundFile and 0182 /// sf::OutputSoundFile. 0183 /// 0184 /// To register a new reader (writer) use the sf::SoundFileFactory::registerReader 0185 /// (registerWriter) static function. You don't have to call the unregisterReader 0186 /// (unregisterWriter) function, unless you want to unregister a format before your 0187 /// application ends (typically, when a plugin is unloaded). 0188 /// 0189 /// Usage example: 0190 /// \code 0191 /// sf::SoundFileFactory::registerReader<MySoundFileReader>(); 0192 /// sf::SoundFileFactory::registerWriter<MySoundFileWriter>(); 0193 /// \endcode 0194 /// 0195 /// \see sf::InputSoundFile, sf::OutputSoundFile, sf::SoundFileReader, sf::SoundFileWriter 0196 /// 0197 ////////////////////////////////////////////////////////////
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|