/* ---------------------------------------------------------------------------- * GTSAM Copyright 2010, Georgia Tech Research Corporation, * Atlanta, Georgia 30332-0415 * All Rights Reserved * Authors: Frank Dellaert, et al. (see THANKS for the full author list) * See LICENSE for the license information * -------------------------------------------------------------------------- */ /** * @file StaticMethod.ccp * @author Frank Dellaert * @author Andrew Melim * @author Richard Roberts **/ #include #include #include #include #include "StaticMethod.h" #include "utilities.h" using namespace std; using namespace wrap; /* ************************************************************************* */ void StaticMethod::addOverload(bool verbose, const std::string& name, const ArgumentList& args, const ReturnValue& retVal) { this->verbose = verbose; this->name = name; this->argLists.push_back(args); this->returnVals.push_back(retVal); } void StaticMethod::proxy_wrapper_fragments(FileWriter& proxyFile, FileWriter& wrapperFile, const string& cppClassName, const string& matlabClassName, const string& wrapperName, const vector& using_namespaces, const TypeAttributesTable& typeAttributes, vector& functionNames) const { string upperName = name; upperName[0] = std::toupper(upperName[0], std::locale()); proxyFile.oss << " function varargout = " << upperName << "(varargin)\n"; for(size_t overload = 0; overload < argLists.size(); ++overload) { const ArgumentList& args = argLists[overload]; const ReturnValue& returnVal = returnVals[overload]; size_t nrArgs = args.size(); const int id = functionNames.size(); // Output proxy matlab code // check for number of arguments... proxyFile.oss << " " << (overload==0?"":"else") << "if length(varargin) == " << nrArgs; if (nrArgs>0) proxyFile.oss << " && "; // ...and their types bool first = true; for(size_t i=0;i& using_namespaces, const TypeAttributesTable& typeAttributes) const { // generate code const string wrapFunctionName = matlabClassName + "_" + name + "_" + boost::lexical_cast(id); const ArgumentList& args = argLists[overload]; const ReturnValue& returnVal = returnVals[overload]; // call file.oss << "void " << wrapFunctionName << "(int nargout, mxArray *out[], int nargin, const mxArray *in[])\n"; // start file.oss << "{\n"; generateUsingNamespace(file, using_namespaces); if(returnVal.isPair) { if(returnVal.category1 == ReturnValue::CLASS) file.oss << " typedef boost::shared_ptr<" << returnVal.qualifiedType1("::") << "> Shared" << returnVal.type1 << ";"<< endl; if(returnVal.category2 == ReturnValue::CLASS) file.oss << " typedef boost::shared_ptr<" << returnVal.qualifiedType2("::") << "> Shared" << returnVal.type2 << ";"<< endl; } else if(returnVal.category1 == ReturnValue::CLASS) file.oss << " typedef boost::shared_ptr<" << returnVal.qualifiedType1("::") << "> Shared" << returnVal.type1 << ";"<< endl; file.oss << " typedef boost::shared_ptr<" << cppClassName << "> Shared;" << endl; // check arguments // NOTE: for static functions, there is no object passed file.oss << " checkArguments(\"" << matlabClassName << "." << name << "\",nargout,nargin," << args.size() << ");\n"; // unwrap arguments, see Argument.cpp args.matlab_unwrap(file,0); // We start at 0 because there is no self object file.oss << " "; // call method with default type and wrap result if (returnVal.type1!="void") returnVal.wrap_result(cppClassName+"::"+name+"("+args.names()+")", file, typeAttributes); else file.oss << cppClassName+"::"+name+"("+args.names()+");\n"; // finish file.oss << "}\n"; return wrapFunctionName; } /* ************************************************************************* */