src/declarative/qml/qdeclarativedata_p.h
branchGCC_SURGE
changeset 31 5daf16870df6
parent 30 5dc02b23752f
equal deleted inserted replaced
27:93b982ccede2 31:5daf16870df6
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef QDECLARATIVEDATA_P_H
       
    43 #define QDECLARATIVEDATA_P_H
       
    44 
       
    45 //
       
    46 //  W A R N I N G
       
    47 //  -------------
       
    48 //
       
    49 // This file is not part of the Qt API.  It exists purely as an
       
    50 // implementation detail.  This header file may change from version to
       
    51 // version without notice, or even be removed.
       
    52 //
       
    53 // We mean it.
       
    54 //
       
    55 
       
    56 #include <QtScript/qscriptvalue.h>
       
    57 #include <private/qobject_p.h>
       
    58 #include "private/qdeclarativeguard_p.h"
       
    59 
       
    60 QT_BEGIN_NAMESPACE
       
    61 
       
    62 class QDeclarativeCompiledData;
       
    63 class QDeclarativeAbstractBinding;
       
    64 class QDeclarativeContext;
       
    65 class QDeclarativePropertyCache;
       
    66 class QDeclarativeContextData;
       
    67 // This class is structured in such a way, that simply zero'ing it is the
       
    68 // default state for elemental object allocations.  This is crucial in the
       
    69 // workings of the QDeclarativeInstruction::CreateSimpleObject instruction.
       
    70 // Don't change anything here without first considering that case!
       
    71 class Q_AUTOTEST_EXPORT QDeclarativeData : public QAbstractDeclarativeData
       
    72 {
       
    73 public:
       
    74     QDeclarativeData()
       
    75         : ownMemory(true), ownContext(false), indestructible(true), explicitIndestructibleSet(false), 
       
    76           context(0), outerContext(0), bindings(0), nextContextObject(0), prevContextObject(0), bindingBitsSize(0), 
       
    77           bindingBits(0), lineNumber(0), columnNumber(0), deferredComponent(0), deferredIdx(0), 
       
    78           attachedProperties(0), scriptValue(0), objectDataRefCount(0), propertyCache(0), guards(0) { 
       
    79           init(); 
       
    80       }
       
    81 
       
    82     static inline void init() {
       
    83         QAbstractDeclarativeData::destroyed = destroyed;
       
    84         QAbstractDeclarativeData::parentChanged = parentChanged;
       
    85     }
       
    86 
       
    87     static void destroyed(QAbstractDeclarativeData *, QObject *);
       
    88     static void parentChanged(QAbstractDeclarativeData *, QObject *, QObject *);
       
    89 
       
    90     void destroyed(QObject *);
       
    91     void parentChanged(QObject *, QObject *);
       
    92 
       
    93     void setImplicitDestructible() {
       
    94         if (!explicitIndestructibleSet) indestructible = false;
       
    95     }
       
    96 
       
    97     quint32 ownMemory:1;
       
    98     quint32 ownContext:1;
       
    99     quint32 indestructible:1;
       
   100     quint32 explicitIndestructibleSet:1;
       
   101     quint32 dummy:28;
       
   102 
       
   103     // The context that created the C++ object
       
   104     QDeclarativeContextData *context; 
       
   105     // The outermost context in which this object lives
       
   106     QDeclarativeContextData *outerContext;
       
   107 
       
   108     QDeclarativeAbstractBinding *bindings;
       
   109 
       
   110     // Linked list for QDeclarativeContext::contextObjects
       
   111     QDeclarativeData *nextContextObject;
       
   112     QDeclarativeData**prevContextObject;
       
   113 
       
   114     int bindingBitsSize;
       
   115     quint32 *bindingBits; 
       
   116     bool hasBindingBit(int) const;
       
   117     void clearBindingBit(int);
       
   118     void setBindingBit(QObject *obj, int);
       
   119 
       
   120     ushort lineNumber;
       
   121     ushort columnNumber;
       
   122 
       
   123     QDeclarativeCompiledData *deferredComponent; // Can't this be found from the context?
       
   124     unsigned int deferredIdx;
       
   125 
       
   126     QHash<int, QObject *> *attachedProperties;
       
   127 
       
   128     // ### Can we make this QScriptValuePrivate so we incur no additional allocation
       
   129     // cost?
       
   130     QScriptValue *scriptValue;
       
   131     quint32 objectDataRefCount;
       
   132     QDeclarativePropertyCache *propertyCache;
       
   133 
       
   134     QDeclarativeGuard<QObject> *guards;
       
   135 
       
   136     static QDeclarativeData *get(const QObject *object, bool create = false) {
       
   137         QObjectPrivate *priv = QObjectPrivate::get(const_cast<QObject *>(object));
       
   138         if (priv->wasDeleted) {
       
   139             Q_ASSERT(!create);
       
   140             return 0;
       
   141         } else if (priv->declarativeData) {
       
   142             return static_cast<QDeclarativeData *>(priv->declarativeData);
       
   143         } else if (create) {
       
   144             priv->declarativeData = new QDeclarativeData;
       
   145             return static_cast<QDeclarativeData *>(priv->declarativeData);
       
   146         } else {
       
   147             return 0;
       
   148         }
       
   149     }
       
   150 };
       
   151 
       
   152 template<class T>
       
   153 void QDeclarativeGuard<T>::addGuard()
       
   154 {
       
   155     Q_ASSERT(!prev);
       
   156 
       
   157     if (QObjectPrivate::get(o)->wasDeleted) 
       
   158         return;
       
   159 
       
   160     QDeclarativeData *data = QDeclarativeData::get(o, true);
       
   161     next = data->guards;
       
   162     if (next) reinterpret_cast<QDeclarativeGuard<T> *>(next)->prev = &next;
       
   163     data->guards = reinterpret_cast<QDeclarativeGuard<QObject> *>(this);
       
   164     prev = &data->guards;
       
   165 }
       
   166 
       
   167 template<class T>
       
   168 void QDeclarativeGuard<T>::remGuard()
       
   169 {
       
   170     Q_ASSERT(prev);
       
   171 
       
   172     if (next) reinterpret_cast<QDeclarativeGuard<T> *>(next)->prev = prev;
       
   173     *prev = next;
       
   174     next = 0;
       
   175     prev = 0;
       
   176 }
       
   177 
       
   178 QT_END_NAMESPACE
       
   179 
       
   180 #endif // QDECLARATIVEDATA_P_H