LCOV - code coverage report
Current view: top level - src/plugins/tcl - action.cpp (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 21 22 95.5 %
Date: 2019-09-12 12:28:41 Functions: 3 3 100.0 %

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

Generated by: LCOV version 1.13