MCPcopy Create free account
hub / github.com/SFML/SFML / createReaderFromFilename

Method createReaderFromFilename

src/SFML/Audio/SoundFileFactory.cpp:48–74  ·  view source on GitHub ↗

///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

46{
47////////////////////////////////////////////////////////////
48std::unique_ptr<SoundFileReader> SoundFileFactory::createReaderFromFilename(const std::filesystem::path& filename)
49{
50 // Wrap the input file into a file stream
51 FileInputStream stream;
52 if (!stream.open(filename))
53 {
54 err() << "Failed to open sound file (couldn't open stream)\n" << formatDebugPathInfo(filename) << std::endl;
55 return nullptr;
56 }
57
58 // Test the filename in all the registered factories
59 for (const auto& [fpCreate, fpCheck] : getReaderFactoryMap())
60 {
61 if (!stream.seek(0).has_value())
62 {
63 err() << "Failed to seek sound stream" << std::endl;
64 return nullptr;
65 }
66
67 if (fpCheck(stream))
68 return fpCreate();
69 }
70
71 // No suitable reader found
72 err() << "Failed to open sound file (format not supported)\n" << formatDebugPathInfo(filename) << std::endl;
73 return nullptr;
74}
75
76
77////////////////////////////////////////////////////////////

Callers

nothing calls this directly

Calls 3

formatDebugPathInfoFunction · 0.85
openMethod · 0.45
seekMethod · 0.45

Tested by

no test coverage detected