diff options
author | Renato Filho <renato.filho@openbossa.org> | 2011-07-05 11:59:33 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:15:27 -0300 |
commit | 219ee31ce4cf9c45b9a53cd267df3e8e7b53b0f2 (patch) | |
tree | 5619e8d5e5f66dc8b5e234b1589e0ba35e556bdd /libshiboken | |
parent | 878c6c81a7469335e70856f77142473bb358051d (diff) |
Now the generated code stores the enum cpp name on the PyThon type.
This is necessary for finding out the enum name during the signal match
function.
Fixed the signal register function for signals with default values.
Fixes bug #903.
Reviewer: Marcelo Lira <marcelo.lira@openbossa.org>
Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'libshiboken')
-rw-r--r-- | libshiboken/sbkenum.cpp | 37 | ||||
-rw-r--r-- | libshiboken/sbkenum.h | 6 |
2 files changed, 35 insertions, 8 deletions
diff --git a/libshiboken/sbkenum.cpp b/libshiboken/sbkenum.cpp index 804f4480e..e128a059a 100644 --- a/libshiboken/sbkenum.cpp +++ b/libshiboken/sbkenum.cpp @@ -21,6 +21,7 @@ */ #include "sbkenum.h" +#include <string.h> #include <cstring> #include <list> #include "sbkdbg.h" @@ -147,11 +148,13 @@ public: DeclaredEnumTypes(); ~DeclaredEnumTypes(); static DeclaredEnumTypes& instance(); - void addEnumType(PyTypeObject* type); + void addEnumType(PyTypeObject* type, const char* cppName); + const char* getCppName(PyTypeObject* type); + private: DeclaredEnumTypes(const DeclaredEnumTypes&); DeclaredEnumTypes& operator=(const DeclaredEnumTypes&); - std::list<PyTypeObject*> m_enumTypes; + std::map<PyTypeObject*, std::string> m_enumTypes; }; namespace Enum { @@ -204,8 +207,14 @@ PyObject* newItem(PyTypeObject* enumType, long itemValue, const char* itemName) return reinterpret_cast<PyObject*>(enumObj); } + PyTypeObject* newType(const char* name) { + return newTypeWithName(name, ""); +} + +PyTypeObject* newTypeWithName(const char* name, const char* cppName) +{ PyTypeObject* type = new PyTypeObject; ::memset(type, 0, sizeof(PyTypeObject)); type->ob_type = &SbkEnumType_Type; @@ -219,10 +228,15 @@ PyTypeObject* newType(const char* name) type->tp_getset = SbkEnumGetSetList; type->tp_new = SbkEnum_tp_new; - DeclaredEnumTypes::instance().addEnumType(type); + DeclaredEnumTypes::instance().addEnumType(type, cppName); return type; } +const char* getCppName(PyTypeObject* enumType) +{ + return DeclaredEnumTypes::instance().getCppName(enumType); +} + long int getValue(PyObject* enumItem) { return reinterpret_cast<SbkEnumObject*>(enumItem)->ob_ival; @@ -242,15 +256,24 @@ DeclaredEnumTypes::DeclaredEnumTypes() DeclaredEnumTypes::~DeclaredEnumTypes() { - std::list<PyTypeObject*>::const_iterator it = m_enumTypes.begin(); + std::map<PyTypeObject*, std::string>::const_iterator it = m_enumTypes.begin(); for (; it != m_enumTypes.end(); ++it) - delete *it; + delete (*it).first; m_enumTypes.clear(); } -void DeclaredEnumTypes::addEnumType(PyTypeObject* type) +void DeclaredEnumTypes::addEnumType(PyTypeObject* type, const char* cppName) +{ + m_enumTypes[type] = cppName; +} + +const char* DeclaredEnumTypes::getCppName(PyTypeObject* type) { - m_enumTypes.push_back(type); + std::map<PyTypeObject*, std::string>::const_iterator it = m_enumTypes.find(type); + if (it != m_enumTypes.end()) + return it->second.c_str(); + else + return ""; } } diff --git a/libshiboken/sbkenum.h b/libshiboken/sbkenum.h index 95b500ca4..c61afed91 100644 --- a/libshiboken/sbkenum.h +++ b/libshiboken/sbkenum.h @@ -44,7 +44,11 @@ inline bool isShibokenEnum(PyObject* pyObj) namespace Enum { LIBSHIBOKEN_API PyObject* newItem(PyTypeObject* enumType, long itemValue, const char* itemName = 0); - LIBSHIBOKEN_API PyTypeObject* newType(const char* name); + + LIBSHIBOKEN_API PyTypeObject* newType(const char* name); //Deprecated use 'newTypeWithName' + LIBSHIBOKEN_API PyTypeObject* newTypeWithName(const char* name, const char* cppName); + LIBSHIBOKEN_API const char* getCppName(PyTypeObject* type); + LIBSHIBOKEN_API long getValue(PyObject* enumItem); LIBSHIBOKEN_API PyObject* getEnumItemFromValue(PyTypeObject* enumType, long itemValue); } |