Bromeon
Resources/AudioKeys.hpp
Go to the documentation of this file.
00001 
00002 //
00003 // Thor C++ Library
00004 // Copyright (c) 2011-2012 Jan Haller
00005 // 
00006 // This software is provided 'as-is', without any express or implied
00007 // warranty. In no event will the authors be held liable for any damages
00008 // arising from the use of this software.
00009 // 
00010 // Permission is granted to anyone to use this software for any purpose,
00011 // including commercial applications, and to alter it and redistribute it
00012 // freely, subject to the following restrictions:
00013 // 
00014 // 1. The origin of this software must not be misrepresented; you must not
00015 //    claim that you wrote the original software. If you use this software
00016 //    in a product, an acknowledgment in the product documentation would be
00017 //    appreciated but is not required.
00018 // 
00019 // 2. Altered source versions must be plainly marked as such, and must not be
00020 //    misrepresented as being the original software.
00021 // 
00022 // 3. This notice may not be removed or altered from any source distribution.
00023 //
00025 
00028 
00029 #ifndef THOR_AUDIOKEYS_HPP
00030 #define THOR_AUDIOKEYS_HPP
00031 
00032 #include <Thor/Resources/ResourceKeyTraits.hpp>
00033 #include <Thor/SmartPtr/MovedPtr.hpp>
00034 #include <Thor/Detail/Swap.hpp>
00035 #include <Thor/Config.hpp>
00036 
00037 #include <SFML/Config.hpp>
00038 
00039 #include THOR_TR1_HEADER(functional)
00040 #include <string>
00041 
00042 
00043 namespace thor
00044 {
00045 
00048 
00051 namespace Resources
00052 {
00053 
00056     class THOR_API SoundBufferKey
00057     {
00058         // ---------------------------------------------------------------------------------------------------------------------------
00059         // Public member functions
00060         public:
00065             static SoundBufferKey       FromFile(const std::string& fileName, const std::string& tag = "");
00066 
00072             static SoundBufferKey       FromMemory(const void* data, std::size_t size, const std::string& tag = "");
00073 
00081             static SoundBufferKey       FromSamples(const sf::Int16* samples, std::size_t samplesCount,
00082                                             unsigned int channelsCount, unsigned int sampleRate, const std::string& tag = "");
00083             
00088             static SoundBufferKey       FromStream(sf::InputStream& stream, const std::string& tag = "");
00089 
00093             MovedPtr<sf::SoundBuffer, NoCopy> Load() const;
00094 
00097             void                        Swap(SoundBufferKey& other);
00098 
00099 
00100         // ---------------------------------------------------------------------------------------------------------------------------
00101         // Private member functions
00102         private:
00103             // Make default constructor private
00104                                         SoundBufferKey();
00105 
00106         
00107         // ---------------------------------------------------------------------------------------------------------------------------
00108         // Private variables
00109         private:
00110             std::tr1::function<bool(sf::SoundBuffer&)>  mLoader;
00111             std::string                                 mKey;
00112 
00113     
00114         // ---------------------------------------------------------------------------------------------------------------------------
00115         // Friends
00116         friend struct detail::KeyInfoAccessor;
00117     };
00118 
00119 
00126     class THOR_API MusicKey
00127     {
00128         // ---------------------------------------------------------------------------------------------------------------------------
00129         // Public member functions
00130         public:
00135             static MusicKey             FromFile(const std::string& fileName, const std::string& tag = "");
00136 
00142             static MusicKey             FromMemory(const void* data, std::size_t size, const std::string& tag = "");
00143 
00148             static MusicKey             FromStream(sf::InputStream& stream, const std::string& tag = "");
00149 
00153             MovedPtr<sf::Music, NoCopy> Load() const;
00154 
00157             void                        Swap(MusicKey& other);
00158 
00159 
00160         // ---------------------------------------------------------------------------------------------------------------------------
00161         // Private member functions
00162         private:
00163             // Make default constructor private
00164                                         MusicKey();
00165 
00166         
00167         // ---------------------------------------------------------------------------------------------------------------------------
00168         // Private variables
00169         private:
00170             std::tr1::function<bool(sf::Music&)>    mLoader;
00171             std::string                             mKey;
00172 
00173     
00174         // ---------------------------------------------------------------------------------------------------------------------------
00175         // Friends
00176         friend struct detail::KeyInfoAccessor;
00177     };
00178 
00179 
00182     bool THOR_API               operator< (const SoundBufferKey& lhs, const SoundBufferKey& rhs);
00183     
00186     bool THOR_API               operator< (const MusicKey& lhs, const MusicKey& rhs);
00187 
00188 
00191     THOR_GLOBAL_SWAP(SoundBufferKey)
00192 
00193     
00194 
00195     THOR_GLOBAL_SWAP(MusicKey)
00196 
00197 } // namespace Resources
00198 
00200 
00201 } // namespace thor
00202 
00203 #endif // THOR_AUDIOKEYS_HPP