/* ---------------------------------------------------------------------------- * 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 Constructor.ccp * @author Frank Dellaert * @author Andrew Melim **/ #include #include #include #include #include #include "utilities.h" #include "Constructor.h" using namespace std; using namespace wrap; /* ************************************************************************* */ string Constructor::matlab_wrapper_name(const string& className) const { string str = "new_" + className; return str; } /* ************************************************************************* */ void Constructor::proxy_fragment(FileWriter& file, const std::string& wrapperName, const string& className, const int id, const ArgumentList args) const { size_t nrArgs = args.size(); // check for number of arguments... file.oss << " elseif nargin == " << nrArgs; if (nrArgs>0) file.oss << " && "; // ...and their types bool first = true; for(size_t i=0;i& using_namespaces, const vector& includes, const ArgumentList& al) const { const string matlabName = matlab_wrapper_name(matlabClassName); const string wrapFunctionName = matlabClassName + "_constructor_" + boost::lexical_cast(id); file.oss << "void " << wrapFunctionName << "(int nargout, mxArray *out[], int nargin, const mxArray *in[])" << endl; file.oss << "{\n"; file.oss << " mexAtExit(&_deleteAllObjects);\n"; generateUsingNamespace(file, using_namespaces); //Typedef boost::shared_ptr file.oss << " typedef boost::shared_ptr<" << cppClassName << "> Shared;\n"; file.oss << "\n"; //Check to see if there will be any arguments and remove {} for consiseness if(al.size() > 0) al.matlab_unwrap(file); // unwrap arguments file.oss << " Shared *self = new Shared(new " << cppClassName << "(" << al.names() << "));" << endl; file.oss << " collector_" << matlabClassName << ".insert(self);\n"; if(verbose_) file.oss << " std::cout << \"constructed \" << self << \" << std::endl;" << endl; file.oss << " out[0] = mxCreateNumericMatrix(1, 1, mxUINT32OR64_CLASS, mxREAL);" << endl; file.oss << " *reinterpret_cast (mxGetData(out[0])) = self;" << endl; file.oss << "}" << endl; return wrapFunctionName; } /* ************************************************************************* */