aboutsummaryrefslogtreecommitdiffstats
path: root/libshiboken/sbkenum.cpp
diff options
context:
space:
mode:
authorRenato Filho <renato.filho@openbossa.org>2011-07-05 11:59:33 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:15:27 -0300
commit219ee31ce4cf9c45b9a53cd267df3e8e7b53b0f2 (patch)
tree5619e8d5e5f66dc8b5e234b1589e0ba35e556bdd /libshiboken/sbkenum.cpp
parent878c6c81a7469335e70856f77142473bb358051d (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/sbkenum.cpp')
-rw-r--r--libshiboken/sbkenum.cpp37
1 files changed, 30 insertions, 7 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 "";
}
}