collect typedefs of basic (non-class) types to treat them as basic types
parent
709417b36d
commit
d38c51b533
|
@ -372,8 +372,12 @@ void Module::emit_cython_pyx(FileWriter& pyxFile) const {
|
||||||
string pxdHeader = name + "_wrapper";
|
string pxdHeader = name + "_wrapper";
|
||||||
pyxFile.oss << "cimport numpy as np\n"
|
pyxFile.oss << "cimport numpy as np\n"
|
||||||
"cimport " << pxdHeader << " as " << name << "\n"
|
"cimport " << pxdHeader << " as " << name << "\n"
|
||||||
"from "<< pxdHeader << " cimport shared_ptr\n"
|
"from "<< pxdHeader << " cimport shared_ptr\n";
|
||||||
"from eigency.core cimport *\n"
|
// import all typedefs, e.g. from gtsam cimport Key, so we don't need to say gtsam.Key
|
||||||
|
for(const Qualified& q: Qualified::BasicTypedefs) {
|
||||||
|
pyxFile.oss << "from " << pxdHeader << " cimport " << q.cythonClass() << "\n";
|
||||||
|
}
|
||||||
|
pyxFile.oss << "from eigency.core cimport *\n"
|
||||||
"from libcpp cimport bool\n\n"
|
"from libcpp cimport bool\n\n"
|
||||||
"from libcpp.pair cimport pair\n"
|
"from libcpp.pair cimport pair\n"
|
||||||
"from libcpp.string cimport string\n"
|
"from libcpp.string cimport string\n"
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
#include <wrap/Qualified.h>
|
||||||
|
|
||||||
|
namespace wrap {
|
||||||
|
std::vector<Qualified> Qualified::BasicTypedefs;
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
|
|
||||||
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
|
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
|
||||||
* Atlanta, Georgia 30332-0415
|
* Atlanta, Georgia 30332-0415
|
||||||
* All Rights Reserved
|
* All Rights Reserved
|
||||||
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
|
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
|
||||||
|
@ -22,7 +22,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace wrap {
|
namespace wrap {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,6 +35,7 @@ public:
|
||||||
|
|
||||||
std::vector<std::string> namespaces_; ///< Stack of namespaces
|
std::vector<std::string> namespaces_; ///< Stack of namespaces
|
||||||
std::string name_; ///< type name
|
std::string name_; ///< type name
|
||||||
|
static std::vector<Qualified> BasicTypedefs;
|
||||||
|
|
||||||
friend struct TypeGrammar;
|
friend struct TypeGrammar;
|
||||||
friend class TemplateSubstitution;
|
friend class TemplateSubstitution;
|
||||||
|
@ -128,8 +129,15 @@ public:
|
||||||
return name() == "Vector" || name() == "Matrix";
|
return name() == "Vector" || name() == "Matrix";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isBasicTypedef() const {
|
||||||
|
return std::find(Qualified::BasicTypedefs.begin(),
|
||||||
|
Qualified::BasicTypedefs.end(),
|
||||||
|
*this) != Qualified::BasicTypedefs.end();
|
||||||
|
}
|
||||||
|
|
||||||
bool isNonBasicType() const {
|
bool isNonBasicType() const {
|
||||||
return !isString() && !isScalar() && !isEigen() && !isVoid();
|
return !isString() && !isScalar() && !isEigen() && !isVoid() &&
|
||||||
|
!isBasicTypedef();
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -219,7 +227,6 @@ public:
|
||||||
os << q.qualifiedName("::");
|
os << q.qualifiedName("::");
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
|
@ -8,9 +8,15 @@ struct TypedefPair {
|
||||||
std::string includeFile;
|
std::string includeFile;
|
||||||
|
|
||||||
TypedefPair() {}
|
TypedefPair() {}
|
||||||
TypedefPair(const Qualified& oldType, const Qualified& newType,
|
TypedefPair(const Qualified& _oldType, const Qualified& _newType,
|
||||||
const std::string& includeFile)
|
const std::string& includeFile)
|
||||||
: oldType(oldType), newType(newType), includeFile(includeFile) {}
|
: oldType(_oldType), newType(_newType), includeFile(includeFile) {
|
||||||
|
if (!oldType.isNonBasicType() &&
|
||||||
|
std::find(Qualified::BasicTypedefs.begin(),
|
||||||
|
Qualified::BasicTypedefs.end(),
|
||||||
|
newType) == Qualified::BasicTypedefs.end())
|
||||||
|
Qualified::BasicTypedefs.push_back(newType);
|
||||||
|
}
|
||||||
|
|
||||||
void emit_cython_pxd(FileWriter& file) const {
|
void emit_cython_pxd(FileWriter& file) const {
|
||||||
file.oss << "cdef extern from \"" << includeFile << "\" namespace \""
|
file.oss << "cdef extern from \"" << includeFile << "\" namespace \""
|
||||||
|
@ -19,4 +25,4 @@ struct TypedefPair {
|
||||||
<< newType.cythonClass() << "\n";
|
<< newType.cythonClass() << "\n";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue