From 95b85e8494671aea570a18816858e440cea98d5b Mon Sep 17 00:00:00 2001 From: dellaert Date: Sun, 25 May 2014 13:22:10 -0400 Subject: [PATCH] Now using ArgumentList::emit_prototype everywhere, for non copy/paste code --- wrap/Class.cpp | 30 ++++++---------------------- wrap/Method.cpp | 46 ++++++++++++++++++------------------------- wrap/Method.h | 7 +++---- wrap/StaticMethod.cpp | 38 +++++++++++------------------------ wrap/StaticMethod.h | 7 +++---- 5 files changed, 43 insertions(+), 85 deletions(-) diff --git a/wrap/Class.cpp b/wrap/Class.cpp index e8b26efb2..075c98811 100644 --- a/wrap/Class.cpp +++ b/wrap/Class.cpp @@ -29,7 +29,6 @@ //#include // on Linux GCC: fails with error regarding needing C++0x std flags //#include // same failure as above #include // works on Linux GCC - using namespace std; using namespace wrap; @@ -389,17 +388,9 @@ void Class::comment_fragment(FileWriter& proxyFile) const { if (!constructor.args_list.empty()) proxyFile.oss << "%\n%-------Constructors-------\n"; BOOST_FOREACH(ArgumentList argList, constructor.args_list) { - string up_name = boost::to_upper_copy(name); - proxyFile.oss << "%" << name << "("; - unsigned int i = 0; - BOOST_FOREACH(const Argument& arg, argList) { - if (i != argList.size() - 1) - proxyFile.oss << arg.type << " " << arg.name << ", "; - else - proxyFile.oss << arg.type << " " << arg.name; - i++; - } - proxyFile.oss << ")\n"; + proxyFile.oss << "%"; + argList.emit_prototype(proxyFile, name); + proxyFile.oss << "\n"; } if (!methods.empty()) @@ -419,18 +410,9 @@ void Class::comment_fragment(FileWriter& proxyFile) const { BOOST_FOREACH(const StaticMethods::value_type& name_m, static_methods) { const StaticMethod& m = name_m.second; BOOST_FOREACH(ArgumentList argList, m.argLists) { - string up_name = boost::to_upper_copy(m.name); - proxyFile.oss << "%" << m.name << "("; - unsigned int i = 0; - BOOST_FOREACH(const Argument& arg, argList) { - if (i != argList.size() - 1) - proxyFile.oss << arg.type << " " << arg.name << ", "; - else - proxyFile.oss << arg.type << " " << arg.name; - i++; - } - - proxyFile.oss << ") : returns " + proxyFile.oss << "%"; + argList.emit_prototype(proxyFile, m.name); + proxyFile.oss << " : returns " << m.returnVals[0].return_type(false, m.returnVals[0].pair) << endl; } } diff --git a/wrap/Method.cpp b/wrap/Method.cpp index 3fbf6a9c0..edfb80268 100644 --- a/wrap/Method.cpp +++ b/wrap/Method.cpp @@ -15,14 +15,15 @@ * @author Richard Roberts **/ -#include -#include +#include "Method.h" +#include "utilities.h" #include #include +#include -#include "Method.h" -#include "utilities.h" +#include +#include using namespace std; using namespace wrap; @@ -44,47 +45,38 @@ void Method::proxy_wrapper_fragments(FileWriter& proxyFile, const string& wrapperName, const TypeAttributesTable& typeAttributes, vector& functionNames) const { + // Create function header proxyFile.oss << " function varargout = " << name << "(this, varargin)\n"; - //Comments for documentation + + // Emit comments for documentation string up_name = boost::to_upper_copy(name); - proxyFile.oss << " % " << up_name << " usage:"; + proxyFile.oss << " % " << up_name << " usage: "; unsigned int argLCount = 0; BOOST_FOREACH(ArgumentList argList, argLists) { - proxyFile.oss << " " << name << "("; - unsigned int i = 0; - BOOST_FOREACH(const Argument& arg, argList) { - if (i != argList.size() - 1) - proxyFile.oss << arg.type << " " << arg.name << ", "; - else - proxyFile.oss << arg.type << " " << arg.name; - i++; - } + argList.emit_prototype(proxyFile, name); if (argLCount != argLists.size() - 1) - proxyFile.oss << "), "; + proxyFile.oss << ", "; else - proxyFile.oss << ") : returns " + proxyFile.oss << " : returns " << returnVals[0].return_type(false, returnVals[0].pair) << endl; argLCount++; } + // Emit URL to Doxygen page proxyFile.oss << " % " << "Doxygen can be found at http://research.cc.gatech.edu/borg/sites/edu.borg/html/index.html" << endl; + + // Document all overloads, if any proxyFile.oss << " % " << "" << endl; proxyFile.oss << " % " << "Method Overloads" << endl; BOOST_FOREACH(ArgumentList argList, argLists) { - proxyFile.oss << " % " << name << "("; - unsigned int i = 0; - BOOST_FOREACH(const Argument& arg, argList) { - if (i != argList.size() - 1) - proxyFile.oss << arg.type << " " << arg.name << ", "; - else - proxyFile.oss << arg.type << " " << arg.name; - i++; - } - proxyFile.oss << ")" << endl; + proxyFile.oss << " % "; + argList.emit_prototype(proxyFile, name); + proxyFile.oss << endl; } + // For all overloads, check the number of arguments for (size_t overload = 0; overload < argLists.size(); ++overload) { const ArgumentList& args = argLists[overload]; const ReturnValue& returnVal = returnVals[overload]; diff --git a/wrap/Method.h b/wrap/Method.h index f2a7ed190..9926a5179 100644 --- a/wrap/Method.h +++ b/wrap/Method.h @@ -18,13 +18,12 @@ #pragma once -#include -#include - #include "Argument.h" #include "ReturnValue.h" #include "TypeAttributesTable.h" -#include + +#include +#include namespace wrap { diff --git a/wrap/StaticMethod.cpp b/wrap/StaticMethod.cpp index 8c84030e7..29b3b12df 100644 --- a/wrap/StaticMethod.cpp +++ b/wrap/StaticMethod.cpp @@ -16,14 +16,15 @@ * @author Richard Roberts **/ -#include -#include +#include "StaticMethod.h" +#include "utilities.h" #include #include +#include -#include "StaticMethod.h" -#include "utilities.h" +#include +#include using namespace std; using namespace wrap; @@ -50,22 +51,14 @@ void StaticMethod::proxy_wrapper_fragments(FileWriter& proxyFile, proxyFile.oss << " function varargout = " << upperName << "(varargin)\n"; //Comments for documentation string up_name = boost::to_upper_copy(name); - proxyFile.oss << " % " << up_name << " usage:"; + proxyFile.oss << " % " << up_name << " usage: "; unsigned int argLCount = 0; BOOST_FOREACH(ArgumentList argList, argLists) { - proxyFile.oss << " " << name << "("; - unsigned int i = 0; - BOOST_FOREACH(const Argument& arg, argList) { - if (i != argList.size() - 1) - proxyFile.oss << arg.type << " " << arg.name << ", "; - else - proxyFile.oss << arg.type << " " << arg.name; - i++; - } + argList.emit_prototype(proxyFile, name); if (argLCount != argLists.size() - 1) - proxyFile.oss << "), "; + proxyFile.oss << ", "; else - proxyFile.oss << ") : returns " + proxyFile.oss << " : returns " << returnVals[0].return_type(false, returnVals[0].pair) << endl; argLCount++; } @@ -76,16 +69,9 @@ void StaticMethod::proxy_wrapper_fragments(FileWriter& proxyFile, proxyFile.oss << " % " << "" << endl; proxyFile.oss << " % " << "Usage" << endl; BOOST_FOREACH(ArgumentList argList, argLists) { - proxyFile.oss << " % " << up_name << "("; - unsigned int i = 0; - BOOST_FOREACH(const Argument& arg, argList) { - if (i != argList.size() - 1) - proxyFile.oss << arg.type << " " << arg.name << ", "; - else - proxyFile.oss << arg.type << " " << arg.name; - i++; - } - proxyFile.oss << ")" << endl; + proxyFile.oss << " % "; + argList.emit_prototype(proxyFile, up_name); + proxyFile.oss << endl; } for (size_t overload = 0; overload < argLists.size(); ++overload) { diff --git a/wrap/StaticMethod.h b/wrap/StaticMethod.h index 3e8dc08cf..576232346 100644 --- a/wrap/StaticMethod.h +++ b/wrap/StaticMethod.h @@ -19,13 +19,12 @@ #pragma once -#include -#include - #include "Argument.h" #include "ReturnValue.h" #include "TypeAttributesTable.h" -#include + +#include +#include namespace wrap {