Core: Add ResourceSaver class

Former-commit-id: 3c7fb9868058d897f1db831b207e9544688922fe
This commit is contained in:
Lynix
2016-03-08 13:09:41 +01:00
parent 883f2eca39
commit 0ffc3c6557
2 changed files with 240 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_RESOURCESAVER_HPP
#define NAZARA_RESOURCESAVER_HPP
#include <Nazara/Core/Enums.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/String.hpp>
#include <list>
#include <tuple>
#include <type_traits>
namespace Nz
{
class Stream;
template<typename Type, typename Parameters>
class ResourceSaver
{
friend Type;
public:
using FormatQuerier = bool (*)(const String& format);
using FileSaver = bool (*)(const Type& resource, const String& filePath, const Parameters& parameters);
using StreamSaver = bool (*)(const Type& resource, const String& format, Stream& stream, const Parameters& parameters);
ResourceSaver() = delete;
~ResourceSaver() = delete;
static bool IsFormatSupported(const String& extension);
static bool SaveToFile(const Type& resource, const String& filePath, const Parameters& parameters = Parameters());
static bool SaveToStream(const Type& resource, Stream& stream, const String& format, const Parameters& parameters = Parameters());
static void RegisterSaver(FormatQuerier formatQuerier, StreamSaver streamSaver, FileSaver fileSaver = nullptr);
static void UnregisterSaver(FormatQuerier formatQuerier, StreamSaver streamSaver, FileSaver fileSaver = nullptr);
private:
using Saver = std::tuple<FormatQuerier, StreamSaver, FileSaver>;
using SaverList = std::list<Saver>;
};
}
#include <Nazara/Core/ResourceSaver.inl>
#endif // NAZARA_RESOURCESAVER_HPP