diff --git a/libwccl/ops/parsedexpression.h b/libwccl/ops/parsedexpression.h index b3b007a63ae124f7b17cbb3a9b57b4fc01faf3a5..5a41d0c8d2ce31e2ea4d7190ace451761b3efe0f 100644 --- a/libwccl/ops/parsedexpression.h +++ b/libwccl/ops/parsedexpression.h @@ -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 diff --git a/wcclparser/main.cpp b/wcclparser/main.cpp index fdd2e40b5162ac2a8edf467e9987189f834f6ecb..2f3412a85a7c46de89e11bcb3b6ff51954a5cf8d 100644 --- a/wcclparser/main.cpp +++ b/wcclparser/main.cpp @@ -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 -- "