Resources/SfmlLoaders.hpp
Go to the documentation of this file.
00001 
00002 //
00003 // Thor C++ Library
00004 // Copyright (c) 2011-2015 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_SFMLLOADERS_HPP
00030 #define THOR_SFMLLOADERS_HPP
00031 
00032 #include <Thor/Resources/ResourceLoader.hpp>
00033 #include <Thor/Resources/Detail/ResourceLoaderHelpers.hpp>
00034 
00035 #include <Aurora/Meta/Templates.hpp>
00036 
00037 
00038 namespace thor
00039 {
00040 
00043 
00046 namespace Resources
00047 {
00048     // Make _1, _2 etc. known within this namespace
00049     using namespace std::placeholders;
00050 
00054     template <class R>
00055     ResourceLoader<R> fromFile(const std::string& filename)
00056     {
00057         return detail::makeResourceLoader<R>(
00058             [=] (R& resource) { return resource.loadFromFile(filename); },
00059             detail::Tagger("File") << filename);
00060     }
00061 
00066     template <class R, typename T>
00067     ResourceLoader<R> fromFile(const std::string& filename, T arg1)
00068     {
00069         return detail::makeResourceLoader<R>(
00070             [=] (R& resource) { return resource.loadFromFile(filename, arg1); },
00071             detail::Tagger("File") << filename << arg1);
00072     }
00073 
00078     template <class R, typename T, typename U>
00079     ResourceLoader<R> fromMemory(T arg1, U arg2)
00080     {
00081         return detail::makeResourceLoader<R>(
00082             [=] (R& resource) { return resource.loadFromMemory(arg1, arg2); },
00083             detail::Tagger("Memory") << arg1 << arg2);
00084     }
00085 
00091     template <class R, typename T, typename U, typename V>
00092     ResourceLoader<R> fromMemory(T arg1, U arg2, V arg3)
00093     {
00094         return detail::makeResourceLoader<R>(
00095             [=] (R& resource) { return resource.loadFromMemory(arg1, arg2, arg3); },
00096             detail::Tagger("Memory") << arg1 << arg2 << arg3);
00097     }
00098 
00102     template <class R>
00103     ResourceLoader<R> fromStream(sf::InputStream& stream)
00104     {
00105         return detail::makeResourceLoader<R>(
00106             [&] (R& resource) { return resource.loadFromStream(stream); },
00107             detail::Tagger("Stream") << &stream);
00108     }
00109 
00114     template <class R>
00115     ResourceLoader<R> fromStream(sf::InputStream& vertexShaderStream, sf::InputStream& fragmentShaderStream)
00116     {
00117         return detail::makeResourceLoader<R>(
00118             [&] (R& resource) { return resource.loadFromStream(vertexShaderStream, fragmentShaderStream); },
00119             detail::Tagger("Stream") << &vertexShaderStream << &fragmentShaderStream);
00120     }
00121 
00126     template <class R, typename T>
00127     ResourceLoader<R> fromStream(sf::InputStream& stream, T arg1
00128         AURORA_ENABLE_IF(!std::is_base_of<sf::InputStream, T>::value))
00129     {
00130         return detail::makeResourceLoader<R>(
00131             [&stream, arg1] (R& resource) { return resource.loadFromStream(stream, arg1); },
00132             detail::Tagger("Stream") << &stream << arg1);
00133     }
00134 
00141     template <class R>
00142     ResourceLoader<R> fromSamples(const sf::Int16* samples, std::size_t sampleCount, unsigned int channelCount, unsigned int sampleRate)
00143     {
00144         return detail::makeResourceLoader<R>(
00145             [=] (R& resource) { return resource.loadFromSamples(samples, sampleCount, channelCount, sampleRate); },
00146             detail::Tagger("Samples") << samples << sampleCount << channelCount << sampleRate);
00147     }
00148 
00153     template <class R>
00154     ResourceLoader<R> fromPixels(unsigned int width, unsigned int height, const sf::Uint8* pixels)
00155     {
00156         return detail::makeResourceLoader<R>(
00157             [=] (R& resource) -> bool
00158             {
00159                 resource.create(width, height, pixels);
00160                 return true;
00161             },
00162             detail::Tagger("Pixels") << width << height << pixels);
00163     }
00164 
00169     template <class R>
00170     ResourceLoader<R> fromColor(unsigned int width, unsigned int height, const sf::Color& color)
00171     {
00172         return detail::makeResourceLoader<R>(
00173             [=] (R& resource) -> bool
00174             {
00175                 resource.create(width, height, color);
00176                 return true;
00177             },
00178             detail::Tagger("Color") << width << height << color);
00179     }
00180 
00185     template <class R>
00186     ResourceLoader<R> fromImage(const sf::Image& image, const sf::IntRect area = sf::IntRect())
00187     {
00188         return detail::makeResourceLoader<R>(
00189             [&image, area] (R& resource) { return resource.loadFromImage(image, area); },
00190             detail::Tagger("Image") << &image << area);
00191     }
00192 
00193 } // namespace Resources
00194 
00196 
00197 } // namespace thor
00198 
00199 #endif // THOR_SFMLLOADERS_HPP