diff --git a/wrap/Class.cpp b/wrap/Class.cpp index bb8051093..09433d616 100644 --- a/wrap/Class.cpp +++ b/wrap/Class.cpp @@ -43,7 +43,8 @@ void Class::assignParent(const Qualified& parent) { /* ************************************************************************* */ boost::optional Class::qualifiedParent() const { boost::optional result = boost::none; - if (parentClass) result = parentClass->qualifiedName("::"); + if (parentClass) + result = parentClass->qualifiedName("::"); return result; } @@ -61,7 +62,7 @@ Method& Class::mutableMethod(Str key) { try { return methods_.at(key); } catch (const out_of_range& oor) { - handleException(oor,methods_); + handleException(oor, methods_); throw runtime_error("Internal error in wrap"); } } @@ -71,7 +72,7 @@ const Method& Class::method(Str key) const { try { return methods_.at(key); } catch (const out_of_range& oor) { - handleException(oor,methods_); + handleException(oor, methods_); throw runtime_error("Internal error in wrap"); } } @@ -316,13 +317,13 @@ vector Class::expandTemplate(Str templateArg, /* ************************************************************************* */ void Class::addMethod(bool verbose, bool is_const, Str methodName, const ArgumentList& argumentList, const ReturnValue& returnValue, - Str templateArgName, const vector& templateArgValues) { + const Template& tmplate) { // Check if templated - if (!templateArgName.empty() && templateArgValues.size() > 0) { + if (!tmplate.argName.empty() && tmplate.argValues.size() > 0) { // Create method to expand // For all values of the template argument, create a new method - BOOST_FOREACH(const Qualified& instName, templateArgValues) { - const TemplateSubstitution ts(templateArgName, instName, *this); + BOOST_FOREACH(const Qualified& instName, tmplate.argValues) { + const TemplateSubstitution ts(tmplate.argName, instName, *this); // substitute template in arguments ArgumentList expandedArgs = argumentList.expandTemplate(ts); // do the same for return type diff --git a/wrap/Class.h b/wrap/Class.h index 449f3df4b..8faf7ab77 100644 --- a/wrap/Class.h +++ b/wrap/Class.h @@ -19,6 +19,7 @@ #pragma once +#include "Template.h" #include "Constructor.h" #include "Deconstructor.h" #include "Method.h" @@ -95,7 +96,7 @@ public: /// Add potentially overloaded, potentially templated method void addMethod(bool verbose, bool is_const, Str methodName, const ArgumentList& argumentList, const ReturnValue& returnValue, - Str templateArgName, const std::vector& templateArgValues); + const Template& tmplate); /// Post-process classes for serialization markers void erase_serialization(); // non-const ! diff --git a/wrap/Module.cpp b/wrap/Module.cpp index a94fb59b9..d7059d316 100644 --- a/wrap/Module.cpp +++ b/wrap/Module.cpp @@ -114,15 +114,6 @@ void Module::parseMarkup(const std::string& data) { // TODO, do we really need cls here? Non-local Class cls0(verbose),cls(verbose); - // template - string templateArgName; - vector templateArgValues; - TypeListGrammar<'{','}'> templateArgValues_g(templateArgValues); - Rule templateArgValues_p = - (str_p("template") >> - '<' >> basic.name_p[assign_a(templateArgName)] >> '=' >> - templateArgValues_g >> '>'); - // parse "gtsam::Pose2" and add to singleInstantiation.typeList TemplateInstantiationTypedef singleInstantiation, singleInstantiation0; TypeListGrammar<'<','>'> typelist_g(singleInstantiation.typeList); @@ -164,20 +155,24 @@ void Module::parseMarkup(const std::string& data) { Rule methodName_p = lexeme_d[(upper_p | lower_p) >> *(alnum_p | '_')]; + // template + Template methodTemplate; + TemplateGrammar methodTemplate_g(methodTemplate); + // gtsam::Values retract(const gtsam::VectorValues& delta) const; string methodName; bool isConst, isConst0 = false; Rule method_p = - !templateArgValues_p >> + !methodTemplate_g >> (returnValue_g >> methodName_p[assign_a(methodName)] >> argumentList_g >> !str_p("const")[assign_a(isConst,true)] >> ';' >> *basic.comments_p) [bl::bind(&Class::addMethod, bl::var(cls), verbose, bl::var(isConst), bl::var(methodName), bl::var(args), bl::var(retVal), - bl::var(templateArgName), bl::var(templateArgValues))] + bl::var(methodTemplate))] [assign_a(retVal,retVal0)] [clear_a(args)] - [clear_a(templateArgValues)] + [clear_a(methodTemplate)] [assign_a(isConst,isConst0)]; Rule staticMethodName_p = lexeme_d[(upper_p | lower_p) >> *(alnum_p | '_')]; @@ -193,17 +188,19 @@ void Module::parseMarkup(const std::string& data) { Rule functions_p = constructor_p | method_p | static_method_p; + // template + Template classTemplate; + TemplateGrammar classTemplate_g(classTemplate); + + // Parent class Qualified possibleParent; TypeGrammar classParent_p(possibleParent); // parse a full class - vector templateInstantiations; Rule class_p = eps_p[assign_a(cls,cls0)] - >> (!(templateArgValues_p - [push_back_a(cls.templateArgs, templateArgName)] - [assign_a(templateInstantiations,templateArgValues)] - [clear_a(templateArgValues)] + >> (!(classTemplate_g + [push_back_a(cls.templateArgs, classTemplate.argName)] | templateList_p) >> !(str_p("virtual")[assign_a(cls.isVirtual, true)]) >> str_p("class") @@ -219,8 +216,8 @@ void Module::parseMarkup(const std::string& data) { [assign_a(cls.namespaces_, namespaces)] [assign_a(cls.deconstructor.name,cls.name_)] [bl::bind(&handle_possible_template, bl::var(classes), bl::var(cls), - bl::var(templateInstantiations))] - [clear_a(templateInstantiations)] + bl::var(classTemplate.argValues))] + [clear_a(classTemplate)] [assign_a(constructor, constructor0)] [assign_a(cls,cls0)];