Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/SFML/Audio/SoundFileFactory.inl is written in an unsupported language. File is not indexed.

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 ////////////////////////////////////////////////////////////
0026 // Headers
0027 ////////////////////////////////////////////////////////////
0028 
0029 
0030 namespace sf
0031 {
0032 namespace priv
0033 {
0034     template <typename T> SoundFileReader* createReader() {return new T;}
0035     template <typename T> SoundFileWriter* createWriter() {return new T;}
0036 }
0037 
0038 ////////////////////////////////////////////////////////////
0039 template <typename T>
0040 void SoundFileFactory::registerReader()
0041 {
0042     // Make sure the same class won't be registered twice
0043     unregisterReader<T>();
0044 
0045     // Create a new factory with the functions provided by the class
0046     ReaderFactory factory;
0047     factory.check = &T::check;
0048     factory.create = &priv::createReader<T>;
0049 
0050     // Add it
0051     s_readers.push_back(factory);
0052 }
0053 
0054 
0055 ////////////////////////////////////////////////////////////
0056 template <typename T>
0057 void SoundFileFactory::unregisterReader()
0058 {
0059     // Remove the instance(s) of the reader from the array of factories
0060     for (ReaderFactoryArray::iterator it = s_readers.begin(); it != s_readers.end(); )
0061     {
0062         if (it->create == &priv::createReader<T>)
0063             it = s_readers.erase(it);
0064         else
0065             ++it;
0066     }
0067 }
0068 
0069 ////////////////////////////////////////////////////////////
0070 template <typename T>
0071 void SoundFileFactory::registerWriter()
0072 {
0073     // Make sure the same class won't be registered twice
0074     unregisterWriter<T>();
0075 
0076     // Create a new factory with the functions provided by the class
0077     WriterFactory factory;
0078     factory.check = &T::check;
0079     factory.create = &priv::createWriter<T>;
0080 
0081     // Add it
0082     s_writers.push_back(factory);
0083 }
0084 
0085 
0086 ////////////////////////////////////////////////////////////
0087 template <typename T>
0088 void SoundFileFactory::unregisterWriter()
0089 {
0090     // Remove the instance(s) of the writer from the array of factories
0091     for (WriterFactoryArray::iterator it = s_writers.begin(); it != s_writers.end(); )
0092     {
0093         if (it->create == &priv::createWriter<T>)
0094             it = s_writers.erase(it);
0095         else
0096             ++it;
0097     }
0098 }
0099 
0100 } // namespace sf