More informative fail
parent
c68c21c187
commit
c609666ab9
|
@ -22,16 +22,35 @@
|
||||||
|
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
|
#include <boost/range/adaptor/map.hpp>
|
||||||
|
#include <boost/range/algorithm/copy.hpp>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <iterator> // std::ostream_iterator
|
||||||
|
|
||||||
//#include <cstdint> // on Linux GCC: fails with error regarding needing C++0x std flags
|
//#include <cstdint> // on Linux GCC: fails with error regarding needing C++0x std flags
|
||||||
//#include <cinttypes> // same failure as above
|
//#include <cinttypes> // same failure as above
|
||||||
#include <stdint.h> // works on Linux GCC
|
#include <stdint.h> // works on Linux GCC
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace wrap;
|
using namespace wrap;
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
Method& Class::method(Str key) {
|
||||||
|
try {
|
||||||
|
return methods_.at(key);
|
||||||
|
} catch (const out_of_range& oor) {
|
||||||
|
cerr << "Class::method: key not found: " << oor.what()
|
||||||
|
<< ", methods are:\n";
|
||||||
|
using boost::adaptors::map_keys;
|
||||||
|
ostream_iterator<string> out_it(cerr, "\n");
|
||||||
|
boost::copy(methods_ | map_keys, out_it);
|
||||||
|
throw runtime_error("Internal error in wrap");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void Class::matlab_proxy(Str toolboxPath, Str wrapperName,
|
void Class::matlab_proxy(Str toolboxPath, Str wrapperName,
|
||||||
const TypeAttributesTable& typeAttributes, FileWriter& wrapperFile,
|
const TypeAttributesTable& typeAttributes, FileWriter& wrapperFile,
|
||||||
|
@ -111,7 +130,7 @@ void Class::matlab_proxy(Str toolboxPath, Str wrapperName,
|
||||||
<< " function disp(obj), obj.display; end\n %DISP Calls print on the object\n";
|
<< " function disp(obj), obj.display; end\n %DISP Calls print on the object\n";
|
||||||
|
|
||||||
// Methods
|
// Methods
|
||||||
BOOST_FOREACH(const Methods::value_type& name_m, methods) {
|
BOOST_FOREACH(const Methods::value_type& name_m, methods_) {
|
||||||
const Method& m = name_m.second;
|
const Method& m = name_m.second;
|
||||||
m.proxy_wrapper_fragments(proxyFile, wrapperFile, cppName, matlabQualName,
|
m.proxy_wrapper_fragments(proxyFile, wrapperFile, cppName, matlabQualName,
|
||||||
matlabUniqueName, wrapperName, typeAttributes, functionNames);
|
matlabUniqueName, wrapperName, typeAttributes, functionNames);
|
||||||
|
@ -244,7 +263,7 @@ void Class::pointer_constructor_fragments(FileWriter& proxyFile,
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
Class Class::expandTemplate(const TemplateSubstitution& ts) const {
|
Class Class::expandTemplate(const TemplateSubstitution& ts) const {
|
||||||
Class inst = *this;
|
Class inst = *this;
|
||||||
inst.methods = expandMethodTemplate(methods, ts);
|
inst.methods_ = expandMethodTemplate(methods_, ts);
|
||||||
inst.static_methods = expandMethodTemplate(static_methods, ts);
|
inst.static_methods = expandMethodTemplate(static_methods, ts);
|
||||||
inst.constructor = constructor.expandTemplate(ts);
|
inst.constructor = constructor.expandTemplate(ts);
|
||||||
inst.deconstructor.name = inst.name;
|
inst.deconstructor.name = inst.name;
|
||||||
|
@ -286,36 +305,36 @@ void Class::addMethod(bool verbose, bool is_const, Str methodName,
|
||||||
// Now stick in new overload stack with expandedMethodName key
|
// Now stick in new overload stack with expandedMethodName key
|
||||||
// but note we use the same, unexpanded methodName in overload
|
// but note we use the same, unexpanded methodName in overload
|
||||||
string expandedMethodName = methodName + instName.name;
|
string expandedMethodName = methodName + instName.name;
|
||||||
methods[expandedMethodName].addOverload(methodName, expandedArgs,
|
methods_[expandedMethodName].addOverload(methodName, expandedArgs,
|
||||||
expandedRetVal, is_const, instName, verbose);
|
expandedRetVal, is_const, instName, verbose);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
// just add overload
|
// just add overload
|
||||||
methods[methodName].addOverload(methodName, argumentList, returnValue,
|
methods_[methodName].addOverload(methodName, argumentList, returnValue,
|
||||||
is_const, Qualified(), verbose);
|
is_const, Qualified(), verbose);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void Class::erase_serialization() {
|
void Class::erase_serialization() {
|
||||||
Methods::iterator it = methods.find("serializable");
|
Methods::iterator it = methods_.find("serializable");
|
||||||
if (it != methods.end()) {
|
if (it != methods_.end()) {
|
||||||
#ifndef WRAP_DISABLE_SERIALIZE
|
#ifndef WRAP_DISABLE_SERIALIZE
|
||||||
isSerializable = true;
|
isSerializable = true;
|
||||||
#else
|
#else
|
||||||
// cout << "Ignoring serializable() flag in class " << name << endl;
|
// cout << "Ignoring serializable() flag in class " << name << endl;
|
||||||
#endif
|
#endif
|
||||||
methods.erase(it);
|
methods_.erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
it = methods.find("serialize");
|
it = methods_.find("serialize");
|
||||||
if (it != methods.end()) {
|
if (it != methods_.end()) {
|
||||||
#ifndef WRAP_DISABLE_SERIALIZE
|
#ifndef WRAP_DISABLE_SERIALIZE
|
||||||
isSerializable = true;
|
isSerializable = true;
|
||||||
hasSerialization = true;
|
hasSerialization = true;
|
||||||
#else
|
#else
|
||||||
// cout << "Ignoring serialize() flag in class " << name << endl;
|
// cout << "Ignoring serialize() flag in class " << name << endl;
|
||||||
#endif
|
#endif
|
||||||
methods.erase(it);
|
methods_.erase(it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,11 +346,11 @@ void Class::verifyAll(vector<string>& validTypes, bool& hasSerialiable) const {
|
||||||
// verify all of the function arguments
|
// verify all of the function arguments
|
||||||
//TODO:verifyArguments<ArgumentList>(validTypes, constructor.args_list);
|
//TODO:verifyArguments<ArgumentList>(validTypes, constructor.args_list);
|
||||||
verifyArguments<StaticMethod>(validTypes, static_methods);
|
verifyArguments<StaticMethod>(validTypes, static_methods);
|
||||||
verifyArguments<Method>(validTypes, methods);
|
verifyArguments<Method>(validTypes, methods_);
|
||||||
|
|
||||||
// verify function return types
|
// verify function return types
|
||||||
verifyReturnTypes<StaticMethod>(validTypes, static_methods);
|
verifyReturnTypes<StaticMethod>(validTypes, static_methods);
|
||||||
verifyReturnTypes<Method>(validTypes, methods);
|
verifyReturnTypes<Method>(validTypes, methods_);
|
||||||
|
|
||||||
// verify parents
|
// verify parents
|
||||||
if (!qualifiedParent.empty()
|
if (!qualifiedParent.empty()
|
||||||
|
@ -351,7 +370,7 @@ void Class::appendInheritedMethods(const Class& cls,
|
||||||
BOOST_FOREACH(const Class& parent, classes) {
|
BOOST_FOREACH(const Class& parent, classes) {
|
||||||
// We found a parent class for our parent, TODO improve !
|
// We found a parent class for our parent, TODO improve !
|
||||||
if (parent.name == cls.qualifiedParent.name) {
|
if (parent.name == cls.qualifiedParent.name) {
|
||||||
methods.insert(parent.methods.begin(), parent.methods.end());
|
methods_.insert(parent.methods_.begin(), parent.methods_.end());
|
||||||
appendInheritedMethods(parent, classes);
|
appendInheritedMethods(parent, classes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -379,9 +398,9 @@ void Class::comment_fragment(FileWriter& proxyFile) const {
|
||||||
|
|
||||||
constructor.comment_fragment(proxyFile);
|
constructor.comment_fragment(proxyFile);
|
||||||
|
|
||||||
if (!methods.empty())
|
if (!methods_.empty())
|
||||||
proxyFile.oss << "%\n%-------Methods-------\n";
|
proxyFile.oss << "%\n%-------Methods-------\n";
|
||||||
BOOST_FOREACH(const Methods::value_type& name_m, methods)
|
BOOST_FOREACH(const Methods::value_type& name_m, methods_)
|
||||||
name_m.second.comment_fragment(proxyFile);
|
name_m.second.comment_fragment(proxyFile);
|
||||||
|
|
||||||
if (!static_methods.empty())
|
if (!static_methods.empty())
|
||||||
|
@ -590,7 +609,7 @@ void Class::python_wrapper(FileWriter& wrapperFile) const {
|
||||||
constructor.python_wrapper(wrapperFile, name);
|
constructor.python_wrapper(wrapperFile, name);
|
||||||
BOOST_FOREACH(const StaticMethod& m, static_methods | boost::adaptors::map_values)
|
BOOST_FOREACH(const StaticMethod& m, static_methods | boost::adaptors::map_values)
|
||||||
m.python_wrapper(wrapperFile, name);
|
m.python_wrapper(wrapperFile, name);
|
||||||
BOOST_FOREACH(const Method& m, methods | boost::adaptors::map_values)
|
BOOST_FOREACH(const Method& m, methods_ | boost::adaptors::map_values)
|
||||||
m.python_wrapper(wrapperFile, name);
|
m.python_wrapper(wrapperFile, name);
|
||||||
wrapperFile.oss << ";\n\n";
|
wrapperFile.oss << ";\n\n";
|
||||||
}
|
}
|
||||||
|
|
20
wrap/Class.h
20
wrap/Class.h
|
@ -36,13 +36,16 @@ namespace wrap {
|
||||||
/// Class has name, constructors, methods
|
/// Class has name, constructors, methods
|
||||||
class Class: public Qualified {
|
class Class: public Qualified {
|
||||||
|
|
||||||
|
typedef const std::string& Str;
|
||||||
|
|
||||||
typedef std::map<std::string, Method> Methods;
|
typedef std::map<std::string, Method> Methods;
|
||||||
Methods methods; ///< Class methods
|
Methods methods_; ///< Class methods
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef const std::string& Str;
|
|
||||||
typedef std::map<std::string, StaticMethod> StaticMethods;
|
typedef std::map<std::string, StaticMethod> StaticMethods;
|
||||||
|
StaticMethods static_methods; ///< Static methods
|
||||||
|
|
||||||
// Then the instance variables are set directly by the Module constructor
|
// Then the instance variables are set directly by the Module constructor
|
||||||
std::vector<std::string> templateArgs; ///< Template arguments
|
std::vector<std::string> templateArgs; ///< Template arguments
|
||||||
|
@ -51,7 +54,6 @@ public:
|
||||||
bool isSerializable; ///< Whether we can use boost.serialization to serialize the class - creates exports
|
bool isSerializable; ///< Whether we can use boost.serialization to serialize the class - creates exports
|
||||||
bool hasSerialization; ///< Whether we should create the serialization functions
|
bool hasSerialization; ///< Whether we should create the serialization functions
|
||||||
Qualified qualifiedParent; ///< The *single* parent
|
Qualified qualifiedParent; ///< The *single* parent
|
||||||
StaticMethods static_methods; ///< Static methods
|
|
||||||
Constructor constructor; ///< Class constructors
|
Constructor constructor; ///< Class constructors
|
||||||
Deconstructor deconstructor; ///< Deconstructor to deallocate C++ object
|
Deconstructor deconstructor; ///< Deconstructor to deallocate C++ object
|
||||||
bool verbose_; ///< verbose flag
|
bool verbose_; ///< verbose flag
|
||||||
|
@ -63,13 +65,13 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t nrMethods() const {
|
size_t nrMethods() const {
|
||||||
return methods.size();
|
return methods_.size();
|
||||||
}
|
|
||||||
Method& method(Str name) {
|
|
||||||
return methods.at(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Method& method(Str key);
|
||||||
|
|
||||||
bool exists(Str name) const {
|
bool exists(Str name) const {
|
||||||
return methods.find(name) != methods.end();
|
return methods_.find(name) != methods_.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
// And finally MATLAB code is emitted, methods below called by Module::matlab_code
|
// And finally MATLAB code is emitted, methods below called by Module::matlab_code
|
||||||
|
@ -119,7 +121,7 @@ public:
|
||||||
os << cls.constructor << ";\n";
|
os << cls.constructor << ";\n";
|
||||||
BOOST_FOREACH(const StaticMethod& m, cls.static_methods | boost::adaptors::map_values)
|
BOOST_FOREACH(const StaticMethod& m, cls.static_methods | boost::adaptors::map_values)
|
||||||
os << m << ";\n";
|
os << m << ";\n";
|
||||||
BOOST_FOREACH(const Method& m, cls.methods | boost::adaptors::map_values)
|
BOOST_FOREACH(const Method& m, cls.methods_ | boost::adaptors::map_values)
|
||||||
os << m << ";\n";
|
os << m << ";\n";
|
||||||
os << "};" << std::endl;
|
os << "};" << std::endl;
|
||||||
return os;
|
return os;
|
||||||
|
|
Loading…
Reference in New Issue