15 #include "xrubywriter.h"
16 #include "xitemnode.h"
17 #include "xlistnode.h"
19 XRubyWriter::XRubyWriter(
const shared_ptr<XNode> &root, std::ofstream &ofs)
20 : m_root(root), m_ofs(ofs)
23 ofs <<
"# KAME2 measurement configuration file" << std::endl
24 <<
"# Automatically created. KAME version. " << VERSION << std::endl
25 <<
"# date: " << XTime::now().getTimeStr() << std::endl;
26 ofs <<
"x = Array.new" << std::endl;
28 XRubyWriter::~XRubyWriter()
35 XString name = m_root->getName();
36 name[0] = toupper(name[0]);
41 write(m_root, shot,
false, 0);
45 const shared_ptr<XNode> &node,
const Snapshot &shot,
46 bool ghost,
int level)
48 int size = shot.size(node);
49 ghost = ghost || shot[ *node].isRuntime();
53 for(
int j = 0; j < level; j++) m_ofs <<
"\t";
62 QString s(shot[ *vnode].to_str());
63 s.replace( QChar(
'\\'),
"\\\\");
64 s.replace( QChar(
'\n'),
"\\n");
65 s.replace( QChar(
'\r'),
"\\r");
66 s.replace( QChar(
'\t'),
"\\t");
68 << (
const char *)s.toUtf8().data()
73 if( ! size) {m_ofs << std::endl;}
76 bool write_typename =
false;
79 write_typename = (lnode->getTypename().find(
"XListNode") != 0);
81 if(lnode->getTypename().find(
"XAliasListNode") == 0) lnode.reset();
86 for(
auto it = list.begin(); it != list.end(); it++) {
87 shared_ptr<XNode> child = *it;
88 for(
int j = 0; j < level; j++) m_ofs <<
"\t";
91 int child_size = shot.size(child);
96 m_ofs <<
"x.last.create(";
97 if(write_typename || child->getName().length()) {
99 << (write_typename ? child->getTypename().c_str() :
"")
102 if(child->getName().length()) {
110 if(child->getName().length()) {
124 write(child, shot, ghost, level + 1);
126 for(
int j = 0; j < level; j++) m_ofs <<
"\t";