summaryrefslogtreecommitdiffstats
path: root/libshiboken
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-08-23 11:35:07 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2011-12-09 20:28:06 -0300
commitcda2c514084ef0ac688e3770cc63c6449da892d5 (patch)
tree209858b8f5578ca03350539d66f1ec37529179f0 /libshiboken
parent11eda546a3bc3133ab180c6be5723f10a2abcf22 (diff)
downloadshiboken-cda2c514084ef0ac688e3770cc63c6449da892d5.tar.gz
shiboken-cda2c514084ef0ac688e3770cc63c6449da892d5.tar.xz
shiboken-cda2c514084ef0ac688e3770cc63c6449da892d5.zip
Converter can be registered and retrieved for string representations of types.
Diffstat (limited to 'libshiboken')
-rw-r--r--libshiboken/sbkconverter.cpp43
-rw-r--r--libshiboken/sbkconverter.h6
2 files changed, 48 insertions, 1 deletions
diff --git a/libshiboken/sbkconverter.cpp b/libshiboken/sbkconverter.cpp
index 34705d9e..185fd2ad 100644
--- a/libshiboken/sbkconverter.cpp
+++ b/libshiboken/sbkconverter.cpp
@@ -23,11 +23,14 @@
#include "sbkconverter.h"
#include "sbkconverter_p.h"
#include "basewrapper_p.h"
-
+#include "google/dense_hash_map"
#include "sbkdbg.h"
static SbkConverter** PrimitiveTypeConverters;
+typedef google::dense_hash_map<std::string, SbkConverter*> ConvertersMap;
+static ConvertersMap converters;
+
namespace Shiboken {
namespace Conversions {
@@ -53,6 +56,27 @@ void init()
Primitive<void*>::createConverter()
};
PrimitiveTypeConverters = primitiveTypeConverters;
+
+ assert(converters.empty());
+ converters.set_empty_key("");
+ converters.set_deleted_key("?");
+ converters["PY_LONG_LONG"] = primitiveTypeConverters[SBK_PY_LONG_LONG_IDX];
+ converters["bool"] = primitiveTypeConverters[SBK_BOOL_IDX];
+ converters["char"] = primitiveTypeConverters[SBK_CHAR_IDX];
+ converters["const char *"] = primitiveTypeConverters[SBK_CONSTCHARPTR_IDX];
+ converters["double"] = primitiveTypeConverters[SBK_DOUBLE_IDX];
+ converters["float"] = primitiveTypeConverters[SBK_FLOAT_IDX];
+ converters["int"] = primitiveTypeConverters[SBK_INT_IDX];
+ converters["long"] = primitiveTypeConverters[SBK_LONG_IDX];
+ converters["short"] = primitiveTypeConverters[SBK_SHORT_IDX];
+ converters["signed char"] = primitiveTypeConverters[SBK_SIGNEDCHAR_IDX];
+ converters["std::string"] = primitiveTypeConverters[SBK_STD_STRING_IDX];
+ converters["unsigned PY_LONG_LONG"] = primitiveTypeConverters[SBK_UNSIGNEDPY_LONG_LONG_IDX];
+ converters["unsigned char"] = primitiveTypeConverters[SBK_UNSIGNEDCHAR_IDX];
+ converters["unsigned int"] = primitiveTypeConverters[SBK_UNSIGNEDINT_IDX];
+ converters["unsigned long"] = primitiveTypeConverters[SBK_UNSIGNEDLONG_IDX];
+ converters["unsigned short"] = primitiveTypeConverters[SBK_UNSIGNEDSHORT_IDX];
+ converters["void*"] = primitiveTypeConverters[SBK_VOIDPTR_IDX];
}
static SbkConverter* createConverterObject(PyTypeObject* type,
@@ -253,6 +277,23 @@ bool isImplicitConversion(SbkObjectType* type, PythonToCppFunc toCppFunc)
return toCppFunc != (*conv).second;
}
+void registerConverterName(SbkConverter* converter , const char* typeName)
+{
+ ConvertersMap::iterator iter = converters.find(typeName);
+ if (iter == converters.end())
+ converters.insert(std::make_pair(typeName, converter));
+}
+
+SbkConverter* getConverter(const char* typeName)
+{
+ ConvertersMap::const_iterator it = converters.find(typeName);
+ if (it != converters.end())
+ return it->second;
+ if (Py_VerboseFlag > 0)
+ SbkDbg() << "Can't find type resolver for type '" << typeName << "'.";
+ return 0;
+}
+
SbkConverter* primitiveTypeConverter(int index)
{
return PrimitiveTypeConverters[index];
diff --git a/libshiboken/sbkconverter.h b/libshiboken/sbkconverter.h
index 6c10df2a..1fddf5a9 100644
--- a/libshiboken/sbkconverter.h
+++ b/libshiboken/sbkconverter.h
@@ -212,6 +212,12 @@ LIBSHIBOKEN_API void nonePythonToCppNullPtr(PyObject*, void* cppOut);
*/
LIBSHIBOKEN_API bool isImplicitConversion(SbkObjectType* type, PythonToCppFunc toCpp);
+/// Registers a converter with a type name that may be used to retrieve the converter.
+LIBSHIBOKEN_API void registerConverterName(SbkConverter* converter, const char* typeName);
+
+/// Returns the converter for a given type name, or NULL if it wasn't registered before.
+LIBSHIBOKEN_API SbkConverter* getConverter(const char* typeName);
+
/// Returns the converter for a primitive type.
LIBSHIBOKEN_API SbkConverter* primitiveTypeConverter(int index);