From 1df4385d847294b7902d7d17f596e77861cc12bf Mon Sep 17 00:00:00 2001 From: Richard Roberts Date: Tue, 23 Feb 2010 17:04:49 +0000 Subject: [PATCH] Added 'verbose' flag, making unit tests silent --- wrap/Class.cpp | 2 +- wrap/Class.h | 3 +++ wrap/Constructor.cpp | 4 ++-- wrap/Constructor.h | 3 +++ wrap/Method.cpp | 4 ++-- wrap/Method.h | 3 ++- wrap/Module.cpp | 13 ++++++------- wrap/Module.h | 7 ++++--- wrap/testWrap.cpp | 6 +++--- wrap/wrap.cpp | 4 ++-- 10 files changed, 28 insertions(+), 21 deletions(-) diff --git a/wrap/Class.cpp b/wrap/Class.cpp index b11357fc9..aa81c6d76 100644 --- a/wrap/Class.cpp +++ b/wrap/Class.cpp @@ -18,7 +18,7 @@ void Class::matlab_proxy(const string& classFile) { // open destination classFile ofstream ofs(classFile.c_str()); if(!ofs) throw CantOpenFile(classFile); - cerr << "generating " << classFile << endl; + if(verbose_) cerr << "generating " << classFile << endl; // emit class proxy code emit_header_comment(ofs,"%"); diff --git a/wrap/Class.h b/wrap/Class.h index 4aac1c0a4..d1c08c2f8 100644 --- a/wrap/Class.h +++ b/wrap/Class.h @@ -17,6 +17,9 @@ struct Class { std::string name; std::list constructors; std::list methods; + bool verbose_; + + Class(bool verbose=true) : verbose_(verbose) {} // MATLAB code generation: void matlab_proxy(const std::string& classFile); // proxy class diff --git a/wrap/Constructor.cpp b/wrap/Constructor.cpp index e4b54f680..8d19d65a5 100644 --- a/wrap/Constructor.cpp +++ b/wrap/Constructor.cpp @@ -41,7 +41,7 @@ void Constructor::matlab_mfile(const string& toolboxPath, const string& classNam string wrapperFile = toolboxPath + "/" + name + ".m"; ofstream ofs(wrapperFile.c_str()); if(!ofs) throw CantOpenFile(wrapperFile); - cerr << "generating " << wrapperFile << endl; + if(verbose_) cerr << "generating " << wrapperFile << endl; // generate code emit_header_comment(ofs, "%"); @@ -67,7 +67,7 @@ void Constructor::matlab_wrapper(const string& toolboxPath, string wrapperFile = toolboxPath + "/" + name + ".cpp"; ofstream ofs(wrapperFile.c_str()); if(!ofs) throw CantOpenFile(wrapperFile); - cerr << "generating " << wrapperFile << endl; + if(verbose_) cerr << "generating " << wrapperFile << endl; // generate code emit_header_comment(ofs, "//"); diff --git a/wrap/Constructor.h b/wrap/Constructor.h index 1a7236868..1605f15a2 100644 --- a/wrap/Constructor.h +++ b/wrap/Constructor.h @@ -14,6 +14,9 @@ // Constructor class struct Constructor { ArgumentList args; + bool verbose_; + + Constructor(bool verbose=true) : verbose_(verbose) {} // MATLAB code generation // toolboxPath is main toolbox directory, e.g., ../matlab diff --git a/wrap/Method.cpp b/wrap/Method.cpp index 469634381..d0bd36506 100644 --- a/wrap/Method.cpp +++ b/wrap/Method.cpp @@ -41,7 +41,7 @@ void Method::matlab_mfile(const string& classPath) { string wrapperFile = classPath + "/" + name + ".m"; ofstream ofs(wrapperFile.c_str()); if(!ofs) throw CantOpenFile(wrapperFile); - cerr << "generating " << wrapperFile << endl; + if(verbose_) cerr << "generating " << wrapperFile << endl; // generate code emit_header_comment(ofs, "%"); @@ -66,7 +66,7 @@ void Method::matlab_wrapper(const string& classPath, string wrapperFile = classPath + "/" + name + ".cpp"; ofstream ofs(wrapperFile.c_str()); if(!ofs) throw CantOpenFile(wrapperFile); - cerr << "generating " << wrapperFile << endl; + if(verbose_) cerr << "generating " << wrapperFile << endl; // generate code diff --git a/wrap/Method.h b/wrap/Method.h index 590feadbf..572b19683 100644 --- a/wrap/Method.h +++ b/wrap/Method.h @@ -17,8 +17,9 @@ struct Method { ArgumentList args; std::string returns, returns2, name; bool returns_ptr, returns_ptr2, returns_pair; + bool verbose_; -Method() : returns_ptr(false), returns_ptr2(false), returns_pair(false) {} + Method(bool verbose=true) : returns_ptr(false), returns_ptr2(false), returns_pair(false), verbose_(verbose) {} enum pairing {arg1, arg2, pair}; std::string return_type(bool add_ptr, pairing p); diff --git a/wrap/Module.cpp b/wrap/Module.cpp index 4606b1b57..7a98ec1ba 100644 --- a/wrap/Module.cpp +++ b/wrap/Module.cpp @@ -27,15 +27,15 @@ typedef rule Rule; /* ************************************************************************* */ Module::Module(const string& interfacePath, - const string& moduleName) : name(moduleName) + const string& moduleName, bool verbose) : name(moduleName), verbose_(verbose) { // these variables will be imperatively updated to gradually build [cls] // The one with postfix 0 are used to reset the variables after parse. Argument arg0, arg; ArgumentList args0, args; - Constructor constructor0, constructor; - Method method0, method; - Class cls0,cls; + Constructor constructor0(verbose), constructor(verbose); + Method method0(verbose), method(verbose); + Class cls0(verbose),cls(verbose); //---------------------------------------------------------------------------- // Grammar with actions that build the Class object. Actions are @@ -166,8 +166,7 @@ Module::Module(const string& interfacePath, /* ************************************************************************* */ void Module::matlab_code(const string& toolboxPath, const string& nameSpace, - const string& mexFlags, - bool verbose) + const string& mexFlags) { try { string installCmd = "install -d " + toolboxPath; @@ -178,7 +177,7 @@ void Module::matlab_code(const string& toolboxPath, ofstream ofs(makeFile.c_str()); if(!ofs) throw CantOpenFile(makeFile); - if (verbose) cerr << "generating " << makeFile << endl; + if (verbose_) cerr << "generating " << makeFile << endl; emit_header_comment(ofs,"%"); ofs << "echo on" << endl << endl; ofs << "toolboxpath = pwd" << endl; diff --git a/wrap/Module.h b/wrap/Module.h index 9699cf6cb..adc5c3bb8 100644 --- a/wrap/Module.h +++ b/wrap/Module.h @@ -15,19 +15,20 @@ struct Module { std::string name; std::list classes; + bool verbose_; /** * constructor that parses interface file */ Module(const std::string& interfacePath, - const std::string& moduleName); + const std::string& moduleName, + bool verbose=true); /** * MATLAB code generation: */ void matlab_code(const std::string& path, const std::string& nameSpace, - const std::string& mexFlags, - bool verbose); + const std::string& mexFlags); }; diff --git a/wrap/testWrap.cpp b/wrap/testWrap.cpp index 586cbd25a..5c2727447 100644 --- a/wrap/testWrap.cpp +++ b/wrap/testWrap.cpp @@ -28,7 +28,7 @@ TEST( wrap, ArgumentList ) { /* ************************************************************************* */ TEST( wrap, parse ) { - Module module(".", "geometry"); + Module module(".", "geometry",false); CHECK(module.classes.size()==3); // check second class, Point3 @@ -59,11 +59,11 @@ TEST( wrap, parse ) { /* ************************************************************************* */ TEST( wrap, matlab_code ) { // Parse into class object - Module module(".","geometry"); + Module module(".","geometry",false); // emit MATLAB code // make_geometry will not compile, use make testwrap to generate real make - module.matlab_code("actual", "", "-O5", verbose); + module.matlab_code("actual", "", "-O5"); CHECK(files_equal("expected/@Point2/Point2.m" , "actual/@Point2/Point2.m" )); CHECK(files_equal("expected/@Point2/x.cpp" , "actual/@Point2/x.cpp" )); diff --git a/wrap/wrap.cpp b/wrap/wrap.cpp index 60ee3264e..2ce5cac1a 100644 --- a/wrap/wrap.cpp +++ b/wrap/wrap.cpp @@ -22,10 +22,10 @@ void generate_matlab_toolbox(const string& interfacePath, const string& mexFlags) { // Parse into class object - Module module(interfacePath, moduleName); + Module module(interfacePath, moduleName, false); // emit MATLAB code - module.matlab_code(toolboxPath,nameSpace,mexFlags,true); + module.matlab_code(toolboxPath,nameSpace,mexFlags); } /* ************************************************************************* */