Bromeon
Resources/AudioKeys.hpp
Go to the documentation of this file.
00001 
00002 //
00003 // Thor C++ Library
00004 // Copyright (c) 2011 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/Detail/Swap.hpp>
00034 #include <Thor/Config.hpp>
00035 
00036 #include <SFML/Config.hpp>
00037 
00038 #include THOR_TR1_HEADER(functional)
00039 #include <string>
00040 
00041 
00042 namespace thor
00043 {
00044 
00047 
00050 namespace Resources
00051 {
00052 
00055     class THOR_API SoundBufferKey
00056     {
00057         // ---------------------------------------------------------------------------------------------------------------------------
00058         // Public member functions
00059         public:
00064             static SoundBufferKey       FromFile(const std::string& fileName, const std::string& tag = "");
00065 
00071             static SoundBufferKey       FromMemory(const void* data, std::size_t size, const std::string& tag = "");
00072 
00080             static SoundBufferKey       FromSamples(const sf::Int16* samples, std::size_t samplesCount,
00081                                             unsigned int channelsCount, unsigned int sampleRate, const std::string& tag = "");
00082 
00086             MovedPtr<sf::SoundBuffer>   Load() const;
00087 
00090             void                        Swap(SoundBufferKey& other);
00091 
00092 
00093         // ---------------------------------------------------------------------------------------------------------------------------
00094         // Private member functions
00095         private:
00096             // Make default constructor private
00097                                         SoundBufferKey();
00098 
00099         
00100         // ---------------------------------------------------------------------------------------------------------------------------
00101         // Private variables
00102         private:
00103             std::tr1::function<bool(sf::SoundBuffer&)>  mLoader;
00104             std::string                                 mKey;
00105 
00106     
00107         // ---------------------------------------------------------------------------------------------------------------------------
00108         // Friends
00109         friend struct detail::KeyInfoAccessor<true>;
00110     };
00111 
00112 
00119     class THOR_API MusicKey
00120     {
00121         // ---------------------------------------------------------------------------------------------------------------------------
00122         // Public member functions
00123         public:
00128             static MusicKey             FromFile(const std::string& fileName, const std::string& tag = "");
00129 
00135             static MusicKey             FromMemory(const void* data, std::size_t size, const std::string& tag = "");
00136 
00140             MovedPtr<sf::Music>         Load() const;
00141 
00144             void                        Swap(MusicKey& other);
00145 
00146 
00147         // ---------------------------------------------------------------------------------------------------------------------------
00148         // Private member functions
00149         private:
00150             // Make default constructor private
00151                                         MusicKey();
00152 
00153         
00154         // ---------------------------------------------------------------------------------------------------------------------------
00155         // Private variables
00156         private:
00157             std::tr1::function<bool(sf::Music&)>    mLoader;
00158             std::string                             mKey;
00159 
00160     
00161         // ---------------------------------------------------------------------------------------------------------------------------
00162         // Friends
00163         friend struct detail::KeyInfoAccessor<true>;
00164     };
00165 
00166 
00169     bool THOR_API               operator< (const SoundBufferKey& lhs, const SoundBufferKey& rhs);
00170     
00173     bool THOR_API               operator< (const MusicKey& lhs, const MusicKey& rhs);
00174 
00175 
00178     THOR_GLOBAL_SWAP(SoundBufferKey)
00179 
00180     
00181 
00182     THOR_GLOBAL_SWAP(MusicKey)
00183 
00184 } // namespace Resources
00185 
00187 
00188 } // namespace thor
00189 
00190 #endif // THOR_AUDIOKEYS_HPP