return ret;
}
+struct Arg
+{
+ std::string name;
+ type_info type;
+ std::string defaultArg;
+};
+
struct t2n_procedure
{
- typedef std::list<std::pair<std::string, type_info> > Args;
+ typedef std::list<Arg> Args;
type_info ret_type;
std::string name;
for (t2n_procedure::Args::const_iterator it=args.begin();it!=args.end();++it)
{
if (it!=args.begin()) o << ", ";
- o << it->second << " " << it->first;
+ o << it->type << " " << it->name;
+
+ if (!it->defaultArg.empty())
+ o << "=" << it->defaultArg;
}
return o;
}
const xmlpp::Element* arg = dynamic_cast<const xmlpp::Element*>(*iter);
if ( arg )
{
+ struct Arg a;
+
assert(arg->get_name() == "Argument");
+
assert(arg->get_attribute("name"));
+ a.name=arg->get_attribute("name")->get_value();
+
assert(arg->get_attribute("type"));
- f.args.push_back(std::pair<std::string, type_info>(arg->get_attribute("name")->get_value(), get_type(root, arg->get_attribute("type")->get_value())));
+ a.type=get_type(root, arg->get_attribute("type")->get_value());
+
+ if(arg->get_attribute("default"))
+ a.defaultArg=arg->get_attribute("default")->get_value();
+
// todo: ugly - could be any other error
- if (f.args.back().second.name.empty())
+ if (a.type.name.empty())
{
assert(element->get_attribute("file"));
assert(element->get_attribute("line"));
std::pair<std::string, unsigned> file_and_line(get_file_and_line(root, element));
throw parse_error(file_and_line.first,
file_and_line.second,
- std::string("type of parameter `")+f.args.back().first+"' not (yet?) supported");
+ std::string("type of parameter '")+a.name+"' not (yet?) supported");
}
+
+ f.args.push_back(a);
}
}
std::cerr << get_file_and_line_as_string(root, element) << ":\texport procedure: " << f << std::endl;
<< "private:\n";
for (t2n_procedure::Args::const_iterator ait=it->args.begin();ait!=it->args.end();++ait)
{
- o << " " << ait->second.noref() << " " << ait->first << ";\n";
+ o << " " << ait->type.noref() << " " << ait->name << ";\n";
}
o << " friend class boost::serialization::access;\n"
<< " template<class Archive>\n"
<< " ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(" << groupClass(group) << ");\n";
for (t2n_procedure::Args::const_iterator ait=it->args.begin();ait!=it->args.end();++ait)
{
- o << " ar & BOOST_SERIALIZATION_NVP(" << ait->first << ");\n";
+ o << " ar & BOOST_SERIALIZATION_NVP(" << ait->name << ");\n";
}
// default constructor
for (t2n_procedure::Args::const_iterator ait=it->args.begin();ait!=it->args.end();++ait)
{
if (ait!=it->args.begin()) o << ", ";
- o << ait->second << " _" << ait->first;
+ o << ait->type << " _" << ait->name;
}
o << ") : ";
for (t2n_procedure::Args::const_iterator ait=it->args.begin();ait!=it->args.end();++ait)
{
if (ait!=it->args.begin()) o << ", ";
// pointers are const pointers and must be dereferenced
- o << ait->first << "(" << ((ait->second.name.find_first_of('*')!=std::string::npos) ? "*" : "" ) << "_" << ait->first << ")";
+ o << ait->name << "(" << ((ait->type.name.find_first_of('*')!=std::string::npos) ? "*" : "" ) << "_" << ait->name << ")";
}
o << " {}\n";
}
for (std::list<t2n_procedure>::const_iterator pit=procs.begin();pit!=procs.end();++pit)
{
- o << pit->ret_type << " " << groupClass(group) << "_client::" << pit->name << "(" << pit->args << ")\n"
+ o << pit->ret_type << " " << groupClass(group) << "_client::" << pit->name << "(";
+
+ // we need to do this by hand here because we don't want default arguments within the cpp
+ for (t2n_procedure::Args::const_iterator xit=pit->args.begin();xit!=pit->args.end();++xit)
+ {
+ if (xit!=pit->args.begin())
+ o << ", ";
+ o << xit->type << " " << xit->name;
+ }
+
+ o << ")\n"
<< "{\n"
<< " libt2n::result_container rc;\n"
<< " send_command(new " << pit->cmd_classname() << "(";
for (t2n_procedure::Args::const_iterator ait=pit->args.begin();ait!=pit->args.end();++ait)
{
if (ait!=pit->args.begin()) o << ", ";
- o << ait->first;
+ o << ait->name;
}
o << "), rc);\n"
<< " " << pit->ret_classname() << "* res=dynamic_cast<" << pit->ret_classname() << "*>(rc.get_result());\n"
{
if (ait!=it->args.begin()) o << ", ";
// get pointer
- if (ait->second.name.find_first_of('*')!=std::string::npos)
+ if (ait->type.name.find_first_of('*')!=std::string::npos)
o << '&';
- o << ait->first;
+ o << ait->name;
}
if (it->hasReturn())