forked from ElektraInitiative/libelektra
-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.cpp
71 lines (54 loc) · 1.44 KB
/
action.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* @file
*
* @brief
*
* @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
*/
#include <keyset.hpp>
#include <fstream>
#include <iostream>
#include <iterator>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/support_istream_iterator.hpp>
#include <boost/bind.hpp>
#include "action.hpp"
#include <kdbease.h> // elektraKeyGetRelativeName
using namespace std;
namespace elektra
{
using namespace kdb;
void serialise (ostream & ofs, KeySet & output, Key & parent)
{
ofs << '{' << endl;
output.rewind ();
while (Key k = output.next ())
{
ofs << "\t{" << endl;
string const name = elektraKeyGetRelativeName (*k, *parent);
ofs << "\t\t" << name << " = " << k.getString () << endl;
k.rewindMeta ();
while (const Key m = k.nextMeta ())
{
ofs << "\t\t{" << endl;
ofs << "\t\t\t" << m.getName () << " = " << m.getString () << endl;
ofs << "\t\t}" << endl;
}
ofs << "\t}" << endl;
}
ofs << '}' << endl;
}
void unserialise (istream & in, KeySet & input, Key & parent)
{
namespace qi = boost::spirit::qi;
using boost::spirit::qi::space;
in.unsetf (std::ios::skipws);
boost::spirit::istream_iterator begin (in);
boost::spirit::istream_iterator end;
Action<boost::spirit::istream_iterator> p (input, parent);
if (!boost::spirit::qi::phrase_parse (begin, end, p, space))
{
throw std::runtime_error ("boost::spirit::qi::phrase_parse returned unsuccessfully");
}
}
} // namespace elektra