lsnes rr2-β24
[lsnes.git] / src / library / streamcompress.cpp
blobba750f0af33fd14103c1c993d7b2df98deeef33b
1 #include "streamcompress.hpp"
2 #include "string.hpp"
3 #include <functional>
4 #include <stdexcept>
6 namespace streamcompress
8 namespace
10 std::map<std::string, std::function<base*(const std::string&)>>& compressors()
12 static std::map<std::string, std::function<base*(const std::string&)>> x;
13 return x;
17 base::~base()
21 std::set<std::string> base::get_compressors()
23 std::set<std::string> r;
24 for(auto& i : compressors())
25 r.insert(i.first);
26 return r;
29 base* base::create_compressor(const std::string& name,
30 const std::string& args)
32 if(!compressors().count(name))
33 throw std::runtime_error("No such compressor");
34 return compressors()[name](args);
37 void base::do_register(const std::string& name,
38 std::function<base*(const std::string&)> ctor)
40 compressors()[name] = ctor;
43 void base::do_unregister(const std::string& name)
45 compressors().erase(name);
48 std::map<std::string, std::string> parse_attributes(const std::string& val)
50 std::map<std::string, std::string> r;
51 std::string v = val;
52 while(v != "") {
53 auto x = regex("([^=]+)=([^,]+)(,(.*)|$)", v);
54 r[x[1]] = x[2];
55 v = x[4];
57 return r;