예제 #1
0
static void
dump_tmpl_proc_2 (const str &arg, const str &res, const str &fn,
		  const str &spc, const str &rpc,
		  const str &cli, const str &cli_tmpl, const str &ret, 
		  bool call)
{
  dump_tmpl_proc_1 (arg, res, fn, spc, true, rpc, cli, cli_tmpl, ret, call);
  if (arg)
    dump_tmpl_proc_1 (arg, res, fn, spc, false, rpc, cli, cli_tmpl, ret, call);
}
예제 #2
0
static void
dump_tmpl_class (const str &arg, const str &res, const str &c, const str& fn,
                 const str& rpc, const str &spc)
{
  aout << spc << "template<class S>\n"
       << spc << "class " << c << " {\n"
       << spc << "public:\n"
       << spc << "  " << c << "(S *s) : _replied (false), _sbp (s) {}\n";
  if (arg) {
    str dcol = is_builtin (arg) ? "" : "::";
    aout << spc << "  " << "const " << dcol << arg << "* getarg() const { "
	 << " return static_cast<" << arg << "*> (_sbp->getvoidarg ()); }\n";
    aout << spc << "  " << dcol << arg << "* getarg() { "
	 << " return static_cast<" << arg << "*> (_sbp->getvoidarg ()); }\n";
  }
  if (res) {
    str dcol = is_builtin (res) ? "" : "::";
    aout << spc << "  " << "void reply (const " << dcol << res << " *r) "
	 << "{ check_reply (); _sbp->reply (r); }\n";
    aout << spc << "  " << "void reply (const " << dcol << res << " &r) "
	 << "{ check_reply (); _sbp->replyref (r); }\n";
    aout << spc << "  " << "void reply (ptr< " << dcol << res << "> r) "
	 << "{ check_reply (); _sbp->reply (r); }\n";

    aout << spc << "  " 
	 << "ptr<" << res << "> alloc_res () "
	 << " { return New refcounted<" << res << "> (); }\n";
    aout << spc << "  template<class T> " 
	 << "ptr<" << res << ">\n"
	 << spc << "  alloc_res (const T &t) "
	 << " { return New refcounted<" << res << "> (t); }\n";
  } else {
    aout << spc << "  " << "void reply () "
	 << "{ check_reply (); _sbp->reply (NULL); }\n";
  }
  aout << spc << "  " << "S *sbp () { return _sbp; }\n";
  aout << spc << "  " << "const S *sbp () const { return _sbp; }\n";

  aout << spc << "  " << "void reject (auth_stat s) "
       << "{ check_reply (); _sbp->reject (s); }\n"
       << spc << "  " << "void reject (accept_stat s) "
       << "{ check_reply (); _sbp->reject (s); }\n"
       << spc << "  " << "void reject () "
       << "{ check_reply (); _sbp->reject (); }\n\n";

  // MM: Generate typedefs for types, if they don't exist mark them void
  aout << spc << "  typedef " << (arg ? arg : str("void")) << " arg_ty;\n\n";
  aout << spc << "  typedef " << (res ? res : str("void")) << " res_ty;\n\n";

  // MM: Call with standard amount of arguments
  str argstr="void", resstr="void";
  if (arg) argstr = arg;
  if (res) resstr = res;
  dump_tmpl_proc_1(argstr, resstr, "call_full", spc << "  ", true, rpc,
                 "C", "C", NULL, true);

  // MM: Call that mirrors the ones generated before this class
  argstr = ""; resstr = "";
  if (arg) argstr = "const " << arg << "* arg,";
  if (res) resstr = " " << res << "* res,";
  aout << spc << "  template<class C, class E>\n";
  aout << spc << "  void call(C c, " << argstr
       << resstr << " E cb)\n";
  argstr=""; resstr="";
  if (arg) argstr = "arg, ";
  if (res) resstr = "res,";
  aout << spc << "  { " << fn << "(c, " << argstr << resstr << " cb); }\n\n";

  aout << spc << "private:\n"
       << spc << "  void check_reply () "
       << "{ assert (!_replied); _replied = true; }\n"
       << spc << "  bool _replied;\n"
       << spc << "  S *_sbp;\n"
       << spc << "};\n\n";
}