add image_reader abstraction layer to hanfle multiple image formats

(work-in-progress)
This commit is contained in:
artemp
2014-11-07 11:49:31 +00:00
committed by Leith Bade
parent 90480ee58c
commit ae2d4e740e
9 changed files with 884 additions and 113 deletions

View File

@@ -0,0 +1,50 @@
#ifndef MBGL_UTIL_FACTORY_HPP
#define MBGL_UTIL_FACTORY_HPP
#include "singleton.hpp"
// stl
#include <stdexcept>
#include <map>
namespace mbgl { namespace util {
template
<
typename product_type,
typename key_type,
typename ...Args >
class factory : public singleton<factory <product_type,
key_type,
Args...> >
{
private:
using product_creator = product_type* (*) (Args...);
using product_map = std::map<key_type,product_creator>;
product_map map_;
public:
bool register_product(key_type const& key, product_creator creator)
{
return map_.insert(typename product_map::value_type(key,creator)).second;
}
bool unregister_product(const key_type& key)
{
return map_.erase(key)==1;
}
product_type* create_object(key_type const& key, Args...args)
{
typename product_map::const_iterator pos=map_.find(key);
if (pos!=map_.end())
{
return (pos->second)(args...);
}
return 0;
}
};
}}
#endif