Commit 33973159 authored by Stefan Westerfeld's avatar Stefan Westerfeld

TSReader/TSWriter: implement generic key/value store.

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent e7cc04f2
......@@ -24,6 +24,7 @@
using std::string;
using std::vector;
using std::map;
using std::regex;
class TSPacket
......@@ -167,6 +168,23 @@ TSWriter::append_file (const string& name, const string& filename)
return Error::Code::NONE;
}
void
TSWriter::append_vars (const string& name, const map<string, string>& vars)
{
vector<unsigned char> data;
for (auto kv : vars)
{
for (auto k : kv.first)
data.push_back (k);
data.push_back ('=');
for (auto v : kv.second)
data.push_back (v);
data.push_back (0);
}
entries.push_back ({name, data});
}
Error
TSWriter::process (const string& inname, const string& outname)
{
......@@ -312,6 +330,41 @@ TSReader::entries()
return m_entries;
}
map<string, string>
TSReader::parse_vars (const string& name)
{
map<string, string> vars;
for (auto entry : m_entries)
{
if (entry.filename == name)
{
enum { KEY, VALUE } mode = KEY;
string s;
string key;
for (auto c : entry.data)
{
if (c == '=' && mode == KEY)
{
key = s;
s.clear();
mode = VALUE;
}
else if (c == '\0' && mode == VALUE)
{
vars[key] = s;
s.clear();
mode = KEY;
}
else
{
s += c;
}
}
}
}
return vars;
}
int
pcr (const string& filename, const string& outname, double d)
......
......@@ -37,6 +37,7 @@ private:
public:
Error load (const std::string& inname);
const std::vector<Entry>& entries();
std::map<std::string, std::string> parse_vars (const std::string& name);
};
class TSWriter
......@@ -49,6 +50,7 @@ class TSWriter
std::vector<Entry> entries;
public:
Error append_file (const std::string& name, const std::string& filename);
void append_vars (const std::string& name, const std::map<std::string, std::string>& vars);
Error process (const std::string& in_name, const std::string& out_name);
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment