activityfw/activitydatabase/s60/src/hsserializer.cpp
author hgs
Wed, 24 Mar 2010 13:06:03 +0200
changeset 90 0e41c72311af
parent 89 activitymanager/activitydatabase/s60/src/hsserializer.cpp@1e87eb3b400f
child 92 782e3408c2ab
permissions -rw-r--r--
201011_02
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
89
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description: 
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
#include "hsserializer.h"
hgs
parents:
diff changeset
    18
hgs
parents:
diff changeset
    19
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    20
//
hgs
parents:
diff changeset
    21
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    22
//
hgs
parents:
diff changeset
    23
RBuf8& operator <<(RBuf8& dst, const QVariantHash& src)
hgs
parents:
diff changeset
    24
{
hgs
parents:
diff changeset
    25
    QByteArray buffer;
hgs
parents:
diff changeset
    26
    QDataStream stream(&buffer, QIODevice::WriteOnly);
hgs
parents:
diff changeset
    27
    
hgs
parents:
diff changeset
    28
    QT_TRYCATCH_LEAVING(stream << src);
hgs
parents:
diff changeset
    29
    const int dataLength(buffer.length());
hgs
parents:
diff changeset
    30
    const unsigned char* dataPtr(reinterpret_cast<const unsigned char*>(buffer.constData()));
hgs
parents:
diff changeset
    31
    if( dst.MaxLength() < dataLength ) {
hgs
parents:
diff changeset
    32
        dst.ReAllocL(dataLength);
hgs
parents:
diff changeset
    33
    }
hgs
parents:
diff changeset
    34
    dst.Copy(dataPtr, dataLength);
hgs
parents:
diff changeset
    35
    return dst;
hgs
parents:
diff changeset
    36
}
hgs
parents:
diff changeset
    37
hgs
parents:
diff changeset
    38
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    39
//
hgs
parents:
diff changeset
    40
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    41
//
hgs
parents:
diff changeset
    42
QVariantHash& operator <<(QVariantHash& dst, const TDesC8& src)
hgs
parents:
diff changeset
    43
{
hgs
parents:
diff changeset
    44
    QByteArray buffer( QByteArray::fromRawData(reinterpret_cast<const char*>(src.Ptr()), 
hgs
parents:
diff changeset
    45
                                               src.Length()) );
hgs
parents:
diff changeset
    46
    
hgs
parents:
diff changeset
    47
    QDataStream stream(&buffer, QIODevice::ReadOnly);
hgs
parents:
diff changeset
    48
    QT_TRYCATCH_LEAVING(stream >> dst);
hgs
parents:
diff changeset
    49
    return dst;
hgs
parents:
diff changeset
    50
}
hgs
parents:
diff changeset
    51
hgs
parents:
diff changeset
    52
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    53
//
hgs
parents:
diff changeset
    54
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    55
//
hgs
parents:
diff changeset
    56
RBuf8& operator <<(RBuf8& dst, const QList<QVariantHash>& src)
hgs
parents:
diff changeset
    57
{
hgs
parents:
diff changeset
    58
    QByteArray buffer;
hgs
parents:
diff changeset
    59
    QDataStream stream(&buffer, QIODevice::WriteOnly);
hgs
parents:
diff changeset
    60
    
hgs
parents:
diff changeset
    61
    QT_TRYCATCH_LEAVING(stream << src);
hgs
parents:
diff changeset
    62
    
hgs
parents:
diff changeset
    63
    if( dst.MaxLength() < buffer.length() ) {
hgs
parents:
diff changeset
    64
        dst.ReAllocL(buffer.length());
hgs
parents:
diff changeset
    65
    }
hgs
parents:
diff changeset
    66
    dst.Copy(reinterpret_cast<const TUint8*>(buffer.data()), buffer.length());
hgs
parents:
diff changeset
    67
    return dst;
hgs
parents:
diff changeset
    68
}
hgs
parents:
diff changeset
    69
hgs
parents:
diff changeset
    70
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    71
//
hgs
parents:
diff changeset
    72
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    73
//
hgs
parents:
diff changeset
    74
QList<QVariantHash>& operator <<(QList<QVariantHash>& dst, const TDesC8& src)
hgs
parents:
diff changeset
    75
{
hgs
parents:
diff changeset
    76
    QByteArray buffer(QByteArray::fromRawData(reinterpret_cast<const char*>(src.Ptr()), 
hgs
parents:
diff changeset
    77
                                              src.Length()));
hgs
parents:
diff changeset
    78
    
hgs
parents:
diff changeset
    79
    QDataStream stream(&buffer, QIODevice::ReadOnly);
hgs
parents:
diff changeset
    80
    QT_TRYCATCH_LEAVING(stream >> dst);
hgs
parents:
diff changeset
    81
    return dst;
hgs
parents:
diff changeset
    82
}