summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2010-12-01 18:05:33 -0200
committerHugo Parente Lima <hugo.pl@gmail.com>2010-12-01 18:05:33 -0200
commit4954a2e8c95df27168b65519a8b61ce30b8ab0d6 (patch)
tree64c45ae087ee4b8ec158d9f65cba93d27c6a47f2
parentaebf1341686e1a694a5ad9b24e384ee494683af8 (diff)
downloadshiboken-4954a2e8c95df27168b65519a8b61ce30b8ab0d6.tar.gz
shiboken-4954a2e8c95df27168b65519a8b61ce30b8ab0d6.tar.xz
shiboken-4954a2e8c95df27168b65519a8b61ce30b8ab0d6.zip
Removed useless stuff from TypeResolver.
-rw-r--r--libshiboken/typeresolver.cpp41
-rw-r--r--libshiboken/typeresolver.h10
2 files changed, 17 insertions, 34 deletions
diff --git a/libshiboken/typeresolver.cpp b/libshiboken/typeresolver.cpp
index 8d3ce7a9..e776b49f 100644
--- a/libshiboken/typeresolver.cpp
+++ b/libshiboken/typeresolver.cpp
@@ -33,10 +33,8 @@ static TypeResolverMap typeResolverMap;
struct TypeResolver::TypeResolverPrivate
{
- const char* typeName; // maybe this is not needed anymore
CppToPythonFunc cppToPython;
PythonToCppFunc pythonToCpp;
- DeleteObjectFunc deleteObject;
PyTypeObject* pyType;
};
@@ -55,25 +53,23 @@ void Shiboken::initTypeResolver()
std::atexit(deinitTypeResolver);
}
-static void registerTypeResolver(TypeResolver* resolver)
+TypeResolver::TypeResolver() : m_d(new TypeResolverPrivate)
{
- TypeResolver*& v = typeResolverMap[resolver->typeName()];
- if (!v)
- v = resolver;
- else
- delete resolver; // Discard type resolvers already registered
}
-TypeResolver::TypeResolver(const char* typeName, TypeResolver::CppToPythonFunc cppToPy, TypeResolver::PythonToCppFunc pyToCpp, PyTypeObject* pyType, TypeResolver::DeleteObjectFunc deleter)
+TypeResolver* TypeResolver::createTypeResolver(const char* typeName,
+ CppToPythonFunc cppToPy,
+ PythonToCppFunc pyToCpp,
+ PyTypeObject* pyType)
{
- m_d = new TypeResolverPrivate;
- m_d->typeName = typeName;
- m_d->cppToPython = cppToPy;
- m_d->pythonToCpp = pyToCpp;
- m_d->deleteObject = deleter;
- m_d->pyType = pyType;
-
- registerTypeResolver(this);
+ TypeResolver*& tr = typeResolverMap[typeName];
+ if (!tr) {
+ tr = new TypeResolver;
+ tr->m_d->cppToPython = cppToPy;
+ tr->m_d->pythonToCpp = pyToCpp;
+ tr->m_d->pyType = pyType;
+ }
+ return tr;
}
TypeResolver::~TypeResolver()
@@ -92,22 +88,11 @@ TypeResolver* TypeResolver::get(const char* typeName)
}
}
-const char* TypeResolver::typeName() const
-{
- return m_d->typeName;
-}
-
void TypeResolver::toCpp(PyObject* pyObj, void** place)
{
m_d->pythonToCpp(pyObj, place);
}
-void TypeResolver::deleteObject(void* object)
-{
- if (m_d->deleteObject)
- m_d->deleteObject(object);
-}
-
PyObject* TypeResolver::toPython(void* cppObj)
{
return m_d->cppToPython(cppObj);
diff --git a/libshiboken/typeresolver.h b/libshiboken/typeresolver.h
index d53d313f..cdd379bc 100644
--- a/libshiboken/typeresolver.h
+++ b/libshiboken/typeresolver.h
@@ -66,40 +66,38 @@ public:
typedef PyObject* (*CppToPythonFunc)(void*);
typedef void (*PythonToCppFunc)(PyObject*, void**);
- typedef void (*DeleteObjectFunc)(void*);
~TypeResolver();
template<typename T>
static TypeResolver* createValueTypeResolver(const char* typeName)
{
- return new TypeResolver(typeName, &Shiboken::Converter<T>::toPython, &pythonToValueType<T>, SbkType<T>(), &callCppDestructor<T>);
+ return createTypeResolver(typeName, &Shiboken::Converter<T>::toPython, &pythonToValueType<T>, SbkType<T>());
}
template<typename T>
static TypeResolver* createObjectTypeResolver(const char* typeName)
{
- return new TypeResolver(typeName, &objectTypeToPython<T>, &pythonToObjectType<T>, SbkType<T>());
+ return createTypeResolver(typeName, &objectTypeToPython<T>, &pythonToObjectType<T>, SbkType<T>());
}
static Type getType(const char* name);
static TypeResolver* get(const char* typeName);
- const char* typeName() const;
PyObject* toPython(void* cppObj);
void toCpp(PyObject* pyObj, void** place);
- void deleteObject(void* object);
PyTypeObject* pythonType();
private:
struct TypeResolverPrivate;
TypeResolverPrivate* m_d;
+ TypeResolver();
// disable object copy
TypeResolver(const TypeResolver&);
TypeResolver& operator=(const TypeResolver&);
- TypeResolver(const char* typeName, CppToPythonFunc cppToPy, PythonToCppFunc pyToCpp, PyTypeObject* pyType, DeleteObjectFunc deleter = 0);
+ static TypeResolver* createTypeResolver(const char* typeName, CppToPythonFunc cppToPy, PythonToCppFunc pyToCpp, PyTypeObject* pyType);
};
}