Commit 418d5775 authored by Wouter's avatar Wouter

Use QSharedPointers for union members

Saves writing proper copy constructors/assignment operators etc; now the
deletion is safe
parent de8023ce
......@@ -115,6 +115,7 @@ Config::Config(QObject* parent): QObject(parent)
m_globalTypeHeaderMap.insert("QVariant", "QtCore/QVariant");
m_globalTypeHeaderMap.insert("QVariantMap", "QtCore/QVariantMap");
m_globalTypeHeaderMap.insert("QList", "QtCore/QList");
m_globalTypeHeaderMap.insert("QSharedPointer", "QtCore/QSharedPointer");
// TODO Add more
// Generated by default templates
......@@ -137,6 +138,7 @@ Config::Config(QObject* parent): QObject(parent)
m_headerDependencies.insert("wrapper", "AbstractWrapper");
m_headerDependencies.insert("wrapper", "QVariant");
m_headerDependencies.insert("union", "QVariant");
m_headerDependencies.insert("union", "QSharedPointer");
}
QString Config::outputNamespace() const
......
......@@ -23,7 +23,7 @@ private:
int m_tag;
{% for variant in class.variants %}
{% ifnotequal variant.fullName "void" %}
{{ variant.fullName }}* m_{{ variant.className }};
QSharedPointer<{{ variant.fullName }}> m_{{ variant.className }};
{% endifnotequal %}
{% endfor %}
......@@ -42,9 +42,6 @@ public:
{% endifnotequal %}
{% endfor %}
// Destructor
virtual ~{{ class.className }}();
/**
* Construct a {{ class.className }} from QVariant data.
*
......
......@@ -13,41 +13,24 @@
{% endfor %}
{% if class.inheritance %},{% else %}:{% endif %}
{% evaltosplit %}
{% evalto initializersposttag %}
{% for variant in class.variants %}
{% ifnotequal variant.fullName "void" %}
, m_{{ variant.className }}(0)
{% endifnotequal %}
{% endfor %}
{% evaltosplit %}
// Default constructor
{{ class.fullName }}::{{ class.className }}()
{{ initializerspretag }} m_tag(-1) {{ initializersposttag }}
{{ initializerspretag }} m_tag(-1)
{
}
{% for variant in class.variants %}
{% ifnotequal variant.fullName "void" %}
{{ class.fullName }}::{{ class.className }}(const {{ variant.fullName }}& value)
{{ initializerspretag }} m_tag({{ forloop.counter }}) {{ initializersposttag }}
{{ initializerspretag }} m_tag({{ forloop.counter }})
{
m_{{ variant.className }} = new {{ variant.fullName }}(value);
m_{{ variant.className }}.reset(new {{ variant.fullName }}(value));
}
{% endifnotequal %}
{% endfor %}
{% endevalto %}
{% endevalto %}
{{ class.fullName }}::~{{ class.className }}()
{
{% for variant in class.variants %}
{% ifnotequal variant.fullName "void" %}
delete m_{{ variant.className }};
{% endifnotequal %}
{% endfor %}
}
{{ class.fullName }} {{ class.fullName }}::fromVariant(const QVariant &value, bool* ok)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment