SoundFileFactory.hpp
1 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2015 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 #ifndef CPP3DS_SOUNDFILEFACTORY_HPP
26 #define CPP3DS_SOUNDFILEFACTORY_HPP
27 
29 // Headers
31 #include <string>
32 #include <vector>
33 
34 
35 namespace cpp3ds
36 {
37 class InputStream;
38 class SoundFileReader;
39 class SoundFileWriter;
40 
46 {
47 public:
48 
55  template <typename T>
56  static void registerReader();
57 
64  template <typename T>
65  static void unregisterReader();
66 
73  template <typename T>
74  static void registerWriter();
75 
82  template <typename T>
83  static void unregisterWriter();
84 
97  static SoundFileReader* createReaderFromFilename(const std::string& filename);
98 
112  static SoundFileReader* createReaderFromMemory(const void* data, std::size_t sizeInBytes);
113 
127 
138  static SoundFileWriter* createWriterFromFilename(const std::string& filename);
139 
140 private:
141 
143  // Types
145  struct ReaderFactory
146  {
147  bool (*check)(InputStream&);
148  SoundFileReader* (*create)();
149  };
150  typedef std::vector<ReaderFactory> ReaderFactoryArray;
151 
152  struct WriterFactory
153  {
154  bool (*check)(const std::string&);
155  SoundFileWriter* (*create)();
156  };
157  typedef std::vector<WriterFactory> WriterFactoryArray;
158 
160  // Static member data
162  static ReaderFactoryArray s_readers;
163  static WriterFactoryArray s_writers;
164 };
165 
166 } // namespace cpp3ds
167 
168 #include <cpp3ds/Audio/SoundFileFactory.inl>
169 
170 #endif // CPP3DS_SOUNDFILEFACTORY_HPP
171 
172 
static void registerWriter()
Register a new writer.
static SoundFileReader * createReaderFromMemory(const void *data, std::size_t sizeInBytes)
Instantiate the right codec for the given file in memory.
Abstract base class for sound file encoding.
Abstract class for custom file input streams.
Definition: InputStream.hpp:40
static void unregisterReader()
Unregister a reader.
static void unregisterWriter()
Unregister a writer.
static SoundFileReader * createReaderFromFilename(const std::string &filename)
Instantiate the right reader for the given file on disk.
static SoundFileReader * createReaderFromStream(InputStream &stream)
Instantiate the right codec for the given file in stream.
static void registerReader()
Register a new reader.
Manages and instantiates sound file readers and writers.
static SoundFileWriter * createWriterFromFilename(const std::string &filename)
Instantiate the right writer for the given file on disk.
Abstract base class for sound file decoding.