Added dependency checking to wrapper. Wrapper will now throw an exception if an object depends on another object which has not been wrapped. Tests for dependency checking added. Moved geometry.h to tests folder.
parent
f9ef0e479c
commit
56818da224
|
@ -209,7 +209,6 @@ void Module::matlab_code(const string& toolboxPath,
|
|||
const string& mexExt,
|
||||
const string& mexFlags)
|
||||
{
|
||||
try {
|
||||
string installCmd = "install -d " + toolboxPath;
|
||||
system(installCmd.c_str());
|
||||
|
||||
|
@ -238,12 +237,27 @@ void Module::matlab_code(const string& toolboxPath,
|
|||
make_ofs << "MEXENDING = " << mexExt << "\n";
|
||||
make_ofs << "mex_flags = " << mexFlags << "\n\n";
|
||||
|
||||
//Dependency check list
|
||||
std::vector<string> validArgs;
|
||||
validArgs.push_back("string");
|
||||
validArgs.push_back("int");
|
||||
validArgs.push_back("bool");
|
||||
validArgs.push_back("size_t");
|
||||
validArgs.push_back("double");
|
||||
validArgs.push_back("Vector");
|
||||
validArgs.push_back("Matrix");
|
||||
|
||||
// add 'all' to Makefile
|
||||
make_ofs << "all: ";
|
||||
BOOST_FOREACH(Class cls, classes)
|
||||
BOOST_FOREACH(Class cls, classes) {
|
||||
make_ofs << cls.name << " ";
|
||||
//Create a list of parsed classes for dependency checking
|
||||
validArgs.push_back(cls.name);
|
||||
}
|
||||
make_ofs << "\n\n";
|
||||
|
||||
|
||||
|
||||
// generate proxy classes and wrappers
|
||||
BOOST_FOREACH(Class cls, classes) {
|
||||
// create directory if needed
|
||||
|
@ -256,8 +270,31 @@ void Module::matlab_code(const string& toolboxPath,
|
|||
cls.matlab_proxy(classFile);
|
||||
|
||||
// create constructor and method wrappers
|
||||
BOOST_FOREACH(Constructor con, cls.constructors) {
|
||||
BOOST_FOREACH(Argument arg, con.args) {
|
||||
if(std::find(validArgs.begin(), validArgs.end(), arg.type)
|
||||
== validArgs.end())
|
||||
throw DependencyMissing(arg.type, cls.name);
|
||||
}
|
||||
}
|
||||
cls.matlab_constructors(toolboxPath,nameSpace);
|
||||
|
||||
BOOST_FOREACH(StaticMethod stMth, cls.static_methods) {
|
||||
BOOST_FOREACH(Argument arg, stMth.args) {
|
||||
if(std::find(validArgs.begin(), validArgs.end(), arg.type)
|
||||
== validArgs.end())
|
||||
throw DependencyMissing(arg.type, stMth.name);
|
||||
}
|
||||
}
|
||||
cls.matlab_static_methods(toolboxPath,nameSpace);
|
||||
|
||||
BOOST_FOREACH(Method mth, cls.methods) {
|
||||
BOOST_FOREACH(Argument arg, mth.args_) {
|
||||
if(std::find(validArgs.begin(), validArgs.end(), arg.type)
|
||||
== validArgs.end())
|
||||
throw DependencyMissing(arg.type, mth.name_);
|
||||
}
|
||||
}
|
||||
cls.matlab_methods(classPath,nameSpace);
|
||||
|
||||
// add lines to make m-file
|
||||
|
@ -285,10 +322,5 @@ void Module::matlab_code(const string& toolboxPath,
|
|||
make_ofs << "\n" << endl;
|
||||
make_ofs.close();
|
||||
}
|
||||
catch(exception &e) {
|
||||
cerr << "generate_matlab_toolbox failed because " << e.what() << endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
|
|
|
@ -48,14 +48,22 @@ TEST( wrap, ArgumentList ) {
|
|||
TEST( wrap, check_exception ) {
|
||||
THROWS_EXCEPTION(Module("/notarealpath", "geometry",enable_verbose));
|
||||
CHECK_EXCEPTION(Module("/alsonotarealpath", "geometry",enable_verbose), CantOpenFile);
|
||||
|
||||
string path = topdir + "/wrap/tests";
|
||||
Module module(path.c_str(), "testWrap1",enable_verbose);
|
||||
THROWS_EXCEPTION(throw DependencyMissing("a", "b"));
|
||||
CHECK_EXCEPTION(module.matlab_code("actual", "", "mexa64", "-O5"), DependencyMissing);
|
||||
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
TEST( wrap, parse ) {
|
||||
string path = topdir + "/wrap";
|
||||
string path = topdir + "/wrap/tests";
|
||||
|
||||
Module module(path.c_str(), "geometry",enable_verbose);
|
||||
CHECK(module.classes.size()==3);
|
||||
//Hack to solve issues with instantiating Modules
|
||||
path = topdir + "/wrap";
|
||||
|
||||
// check second class, Point3
|
||||
Class cls = *(++module.classes.begin());
|
||||
|
@ -98,8 +106,9 @@ TEST( wrap, parse ) {
|
|||
/* ************************************************************************* */
|
||||
TEST( wrap, matlab_code ) {
|
||||
// Parse into class object
|
||||
string path = topdir + "/wrap";
|
||||
string path = topdir + "/wrap/tests";
|
||||
Module module(path,"geometry",enable_verbose);
|
||||
path = topdir + "/wrap";
|
||||
|
||||
// emit MATLAB code
|
||||
// make_geometry will not compile, use make testwrap to generate real make
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
//Header file to test dependency checking
|
||||
//
|
||||
class Pose3 {
|
||||
Pose3();
|
||||
Pose3(const Rot3& r, const Point3& t);//What is Rot3? Throw here
|
||||
Pose3(Vector v);
|
||||
Pose3(Matrix t);
|
||||
static Pose3 Expmap(Vector v);
|
||||
static Vector Logmap(const Pose3& p);
|
||||
static Rot3 testStaticDep(Rot3& r);//What is Rot3? Throw here
|
||||
void print(string s) const;
|
||||
bool equals(const Pose3& pose, double tol) const;
|
||||
double x() const;
|
||||
double y() const;
|
||||
double z() const;
|
||||
Matrix matrix() const;
|
||||
Matrix adjointMap() const;
|
||||
Pose3 compose(const Pose3& p2);
|
||||
Pose3 between(const Pose3& p2);
|
||||
Pose3 retract(Vector v);
|
||||
Point3 translation() const;
|
||||
Rot3 rotation() const; //What is Rot3? Throw here
|
||||
};
|
|
@ -46,6 +46,22 @@ class ParseFailed : public std::exception {
|
|||
}
|
||||
};
|
||||
|
||||
class DependencyMissing : public std::exception {
|
||||
private:
|
||||
std::string dependency_;
|
||||
std::string location_;
|
||||
public:
|
||||
DependencyMissing(const std::string& dep, const std::string& loc) {
|
||||
dependency_ = dep;
|
||||
location_ = loc;
|
||||
}
|
||||
~DependencyMissing() throw() {}
|
||||
virtual const char* what() const throw() {
|
||||
return ("Missing dependency " + dependency_ + " in " + location_).c_str();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* read contents of a file into a std::string
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue