diff options
Diffstat (limited to 'project2/ice/slice2Rows.cpp')
-rw-r--r-- | project2/ice/slice2Rows.cpp | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/project2/ice/slice2Rows.cpp b/project2/ice/slice2Rows.cpp new file mode 100644 index 0000000..9646f17 --- /dev/null +++ b/project2/ice/slice2Rows.cpp @@ -0,0 +1,94 @@ +#include <pch.hpp> +#include "slice2Rows.h" +#include <boost/foreach.hpp> +#include <Slice/CPlusPlusUtil.h> + +Slice2Rows::Slice2Rows(FILE * c) : + code(c) +{ +} + +bool +Slice2Rows::visitModuleStart(const Slice::ModulePtr & m) +{ + module = m->name(); + fprintf(code, "namespace IceRowsWrappers {\n"); + fprintf(code, "\tnamespace %s {\n", m->name().c_str()); + return true; +} + +bool +Slice2Rows::visitClassDefStart(const Slice::ClassDefPtr & c) +{ + interface = c->name(); + fprintf(code, "\t\tnamespace %s {\n", c->name().c_str()); + return true; +} + +void +Slice2Rows::visitOperation(const Slice::OperationPtr & o) +{ + if (o->hasMetaData("project2:rows")) { + fprintf(code, "\t\t\tclass %s : public IceRows< ::%s::%sPrx > {\n", o->name().c_str(), module.c_str(), interface.c_str()); + fprintf(code, "\t\t\t\tpublic:\n"); + // Constructor + fprintf(code, "\t\t\t\t\t%s(ScriptNodePtr p) :\n", o->name().c_str()); + fprintf(code, "\t\t\t\t\t\tIceRows< ::%s::%sPrx >(p)", module.c_str(), interface.c_str()); + BOOST_FOREACH(const auto & p, o->parameters()) { + fprintf(code, ",\n\t\t\t\t\t\t%s(p, \"%s\")", p->name().c_str(), p->name().c_str()); + } + fprintf(code, "\n\t\t\t\t\t{\n"); + fprintf(code, "\t\t\t\t\t}\n\n"); + // Execute + fprintf(code, "\t\t\t\t\tvoid execute(const Glib::ustring &, const RowProcessorCallback & rp, ExecContext * ec) const\n"); + fprintf(code, "\t\t\t\t\t{\n"); + fprintf(code, "\t\t\t\t\t\tLogger()->messagebf(LOG_DEBUG, \"%%s: "); + BOOST_FOREACH(const auto & p, o->parameters()) { + fprintf(code, "%s = %%s, ", p->name().c_str()); + } + fprintf(code, "ice @ %%p\", \n"); + fprintf(code, "\t\t\t\t\t\t\t\t__PRETTY_FUNCTION__, "); + BOOST_FOREACH(const auto & p, o->parameters()) { + fprintf(code, "%s(ec).as<std::string>(), ", p->name().c_str()); + } + fprintf(code, "ice);\n"); + fprintf(code, "\t\t\t\t\t\tIce::Context ctx;\n"); + BOOST_FOREACH(const auto & p, o->parameters()) { + fprintf(code, "\t\t\t\t\t\tauto _%s = IceConvert< %s >::FromVariable(%s(ec));\n", + p->name().c_str(), + Slice::typeToString(p->type()).c_str(), + p->name().c_str()); + } + fprintf(code, "\t\t\t\t\t\tIceRowState<decltype(service->%s(", o->name().c_str()); + BOOST_FOREACH(const auto & p, o->parameters()) { + fprintf(code, "_%s, ", p->name().c_str()); + } + fprintf(code, "ctx))> irs;\n"); + fprintf(code, "\t\t\t\t\t\tirs.IterateOver(service->%s(", o->name().c_str()); + BOOST_FOREACH(const auto & p, o->parameters()) { + fprintf(code, "_%s, ", p->name().c_str()); + } + fprintf(code, "ctx), rp);\n"); + fprintf(code, "\t\t\t\t\t}\n\n"); + // Parameter variables + BOOST_FOREACH(const auto & p, o->parameters()) { + fprintf(code, "\t\t\t\t\tconst Variable %s;\n", p->name().c_str()); + } + fprintf(code, "\t\t\t};\n"); + fprintf(code, "\t\t\tDECLARE_LOADER(\"%s-%s-%s\", %s);\n\n", module.c_str(), interface.c_str(), o->name().c_str(), o->name().c_str()); + } +} + +void +Slice2Rows::visitClassDefEnd(const Slice::ClassDefPtr & c) +{ + fprintf(code, "\t\t} // namespace %s\n\n", c->name().c_str()); +} + +void +Slice2Rows::visitModuleEnd(const Slice::ModulePtr & m) +{ + fprintf(code, "\t}; // namespace %s\n", m->name().c_str()); + fprintf(code, "}; // namespace IceRowsWrappers\n\n"); +} + |