Lua: Don't lua_error() out of context with pending dtors
[lsnes.git] / src / library / streamcompress.cpp
blob0a3279a8b4e3a9ee2f2bbfe0b2a5a07f6befd23a
1 #include "streamcompress.hpp"
2 #include "string.hpp"
3 #include <stdexcept>
5 namespace streamcompress
7 namespace
9 std::map<std::string, std::function<base*(const std::string&)>>& compressors()
11 static std::map<std::string, std::function<base*(const std::string&)>> x;
12 return x;
16 base::~base()
20 std::set<std::string> base::get_compressors()
22 std::set<std::string> r;
23 for(auto& i : compressors())
24 r.insert(i.first);
25 return r;
28 base* base::create_compressor(const std::string& name,
29 const std::string& args)
31 if(!compressors().count(name))
32 throw std::runtime_error("No such compressor");
33 return compressors()[name](args);
36 void base::do_register(const std::string& name,
37 std::function<base*(const std::string&)> ctor)
39 compressors()[name] = ctor;
42 void base::do_unregister(const std::string& name)
44 compressors().erase(name);
47 std::map<std::string, std::string> parse_attributes(const std::string& val)
49 std::map<std::string, std::string> r;
50 std::string v = val;
51 while(v != "") {
52 auto x = regex("([^=]+)=([^,]+)(,(.*)|$)", v);
53 r[x[1]] = x[2];
54 v = x[4];
56 return r;