Skip to content
Snippets Groups Projects
Commit b587d7cc authored by Adam Wardynski's avatar Adam Wardynski
Browse files

Rework dumping variables a bit, plus add string version.

parent 52e2cc99
Branches
No related merge requests found
......@@ -139,18 +139,19 @@ public:
*/
boost::shared_ptr<ParsedExpression> clone_clean_ptr() const;
/**
* Dup all variables to error stream.
* @returns String with representation of all held variables,
* in form of "variable = value" pairs, each pair on one line.
*/
void dumpvariables(const Corpus2::Tagset& tagset)
{
typedef std::pair<std::string, boost::shared_ptr<Wccl::Value> > v_t;
std::string variables_string(const Corpus2::Tagset& tagset) const;
foreach (const v_t& v, variables_->get_all<Wccl::Value>()) {
std::cerr << v.second->make_var_repr(v.first) << "="
<< v.second->to_string(tagset) << "\n";
}
}
/**
* Dump all variables to an output stream, in form of
* "variable = value" pairs, each pair on another line.
* @returns Stream written to.
*/
std::ostream& dump_variables(std::ostream& ostream, const Corpus2::Tagset& tagset) const;
protected:
explicit ParsedExpression(const Variables& variables);
......@@ -231,6 +232,25 @@ boost::shared_ptr<ParsedExpression> ParsedExpression::clone_clean_ptr() const {
return copy;
}
inline
std::ostream& ParsedExpression::dump_variables(
std::ostream &ostream,
const Corpus2::Tagset &tagset) const {
typedef std::pair<std::string, boost::shared_ptr<Wccl::Value> > v_t;
foreach (const v_t& v, variables_->get_all<Wccl::Value>()) {
ostream << v.second->make_var_repr(v.first) << "="
<< v.second->to_string(tagset) << "\n";
}
return ostream;
}
inline
std::string ParsedExpression::variables_string(const Corpus2::Tagset &tagset) const {
std::ostringstream oss;
dump_variables(oss, tagset);
return oss.str();
}
} /* end ns Wccl */
#endif // LIBWCCL_OPS_PARSEDEXPRESSION_H
......@@ -126,7 +126,7 @@ bool process_line(const std::string& line, Wccl::Parser& parser,
<< retVal->to_string(parser.tagset())
<< std::endl;
if (dump_variables) {
retOp->dumpvariables(parser.tagset());
retOp->dump_variables(std::cerr, parser.tagset());
}
} else {
std::cerr << "Problem while parsing -- "
......
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