svgtopt/nvgdecoder/inc/NVGIconData.h
changeset 46 88edb906c587
equal deleted inserted replaced
-1:000000000000 46:88edb906c587
       
     1 /*
       
     2 * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  NVG Decoder header file
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CNVGICONDATA_H_
       
    20 #define CNVGICONDATA_H_
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <s32mem.h>
       
    24 
       
    25 
       
    26 /**
       
    27  * @class CNVGIconData
       
    28  *        This class is useful when you want to read nd write data from and to memory
       
    29  *        This class check for buffer overflow
       
    30  *        This is much faster than stream classes provided by symbian
       
    31  *        During the ETM traces we found that those classes are 3 FPS less than these utility classes
       
    32  *        This class will be checking for data alignment
       
    33  */
       
    34 class CNVGIconData : public CBase
       
    35     {
       
    36 private:
       
    37     CNVGIconData();
       
    38     void ConstructL(TUint aLength);
       
    39     void ConstructL(const TDesC8& aBuf);
       
    40     
       
    41 public:
       
    42     
       
    43     /**
       
    44      * Here the user should only read. Will Behave undefinitly if try to write.
       
    45      */
       
    46     static CNVGIconData * NewL(const TDesC8& aBuf);
       
    47 
       
    48     static CNVGIconData * NewL(TInt aLength = 0);
       
    49     
       
    50     static CNVGIconData * NewLC(const TDesC8& aBuf);
       
    51 
       
    52     static CNVGIconData * NewLC(TInt aLength = 0);
       
    53 
       
    54     static CNVGIconData * NewL(TUint8 * aBuf, TInt aLength);
       
    55 
       
    56     static CNVGIconData * NewLC(TUint8 * aBuf, TInt aLength);
       
    57 
       
    58     virtual ~CNVGIconData();
       
    59     
       
    60     void Set(const TDesC8& aBuf);
       
    61     
       
    62     void Set(TUint8 * aBuf, TInt aLength);
       
    63 
       
    64     TInt EncodeInt8(TUint8 aVal);
       
    65 
       
    66     TInt EncodeInt16(TUint16 aVal);
       
    67 
       
    68     TInt EncodeInt32(TUint32 aVal);
       
    69 
       
    70     TInt EncodeReal32(TReal32 aVal);
       
    71 
       
    72     TInt EncodeReal64(TReal64 aVal);
       
    73     
       
    74     TInt EncodeData(const TAny *aData, TUint aLength);
       
    75 
       
    76     void EncodeInt8L(TUint8 aVal);
       
    77 
       
    78     void EncodeInt16L(TUint16 aVal);
       
    79 
       
    80     void EncodeInt32L(TUint32 aVal);
       
    81 
       
    82     void EncodeReal32L(TReal32 aVal);
       
    83 
       
    84     void EncodeReal64L(TReal64 aVal);
       
    85     
       
    86     void EncodeDataL(const TAny *aData, TUint aLength);
       
    87     
       
    88     TInt ExpandEncodedData(TUint aNewLength);
       
    89 
       
    90     const HBufC8 * GetNVGData() const;
       
    91     
       
    92     const HBufC8 * GetNVGData();
       
    93     
       
    94     void BeginRead();
       
    95     void EndRead();
       
    96     
       
    97     TInt16 ReadInt16L();
       
    98     
       
    99     TInt32 ReadInt32L();
       
   100     
       
   101     TInt8 ReadInt8L();
       
   102     
       
   103     void ReadL(TDes8 &aDes, TInt aLength);
       
   104     
       
   105     void ReadL(TUint8 *aPtr, TInt aLength);
       
   106     
       
   107     TReal32 ReadReal32L();
       
   108     
       
   109     TReal64 ReadReal64L();
       
   110 
       
   111     void SkipL(TInt aLength);
       
   112     
       
   113     TInt ReadPos();
       
   114     
       
   115     TBool EOF();
       
   116     
       
   117     TInt DataLength();
       
   118             
       
   119 private:
       
   120     
       
   121     void CheckOutOfBoundL(TInt aLength);
       
   122     
       
   123     HBufC8 *            iNVGData;
       
   124     TPtr8               iNVGDataPtr;
       
   125     TInt                iTotalRead;
       
   126     TInt                iDataLength;
       
   127     TUint8 *            iReadStream;
       
   128     };
       
   129 
       
   130 /**
       
   131  * @class TDereferencer
       
   132  *        This class is useful when you want to dereference character data
       
   133  *        This class check for buffer overflow
       
   134  *        This is much faster than stream classes provided by symbian
       
   135  *        During the ETM traces we found that those classes are 3 FPS less than these utility classes
       
   136  *        This class won't be checking for data alignment.
       
   137  */
       
   138 class TDereferencer
       
   139     {
       
   140 public:
       
   141     
       
   142     TDereferencer(TUint8 * aBuf, TInt aLength);
       
   143     
       
   144     TDereferencer(const TDesC8& aBuf);
       
   145     
       
   146     /**
       
   147      *  @fn         SkipL
       
   148      *              Advances the read pointer with the given length
       
   149      */void SkipL(TInt aLength);
       
   150 
       
   151     /**
       
   152      * @fn          DerefInt16L
       
   153      *              Converts current position to TInt16 *. The caller should take care of alignment
       
   154      *              The advantage of this method is that you don't have to copy the data
       
   155      *              Bound check will happen
       
   156      * @param       aAt dereference from this position
       
   157      * @exception   Leaves if data size is not sufficient       
       
   158      */
       
   159     TInt16 DerefInt16L(TInt aAt = 0);
       
   160     operator TInt16();
       
   161     
       
   162     /**
       
   163      * @fn          DerefInt32L
       
   164      *              Converts current position to TInt32 *. The caller should take care of alignment
       
   165      *              The advantage of this method is that you don't have to copy the data
       
   166      *              Bound check will happen
       
   167      * @param       aAt dereference from this position
       
   168      * @exception   Leaves if data size is not sufficient       
       
   169      */
       
   170     TInt32 DerefInt32L(TInt aAt = 0);
       
   171     operator TInt32();
       
   172     
       
   173     /**
       
   174      * @fn          DerefInt8L
       
   175      *              Converts current position to TInt8 *. The caller should take care of alignment
       
   176      *              The advantage of this method is that you don't have to copy the data
       
   177      *              Bound check will happen
       
   178      * @param       aAt dereference from this position
       
   179      * @exception   Leaves if data size is not sufficient       
       
   180      */
       
   181     TInt8 DerefInt8L(TInt aAt = 0);
       
   182     operator TInt8();
       
   183 
       
   184     /**
       
   185      * @fn          DerefInt8ArrayL
       
   186      *              Converts current position to TUint8 *. The caller should take care of alignment
       
   187      *              The advantage of this method is that you don't have to copy the data
       
   188      *              Bound check will happen
       
   189      * @param       aLength making safe to dereference for this size
       
   190      * @param       aAt dereference from this position
       
   191      * @exception   Leaves if data size is not sufficient       
       
   192      */
       
   193     TUint8 * DerefInt8ArrayL(TInt aLength, TInt aAt = 0);
       
   194        
       
   195     /**
       
   196      * @fn          ReadReal32L
       
   197      *              Converts current position to TReal32 *. The caller should take care of alignment
       
   198      *              The advantage of this method is that you don't have to copy the data
       
   199      *              Bound check will happen
       
   200      * @param       aAt dereference from this position
       
   201      * @exception   Leaves if data size is not sufficient       
       
   202      */
       
   203     TReal32 DerefReal32L(TInt aAt = 0);
       
   204     operator TReal32();
       
   205     
       
   206     /**
       
   207      * @fn          ReadReal64L
       
   208      *              Converts current position to TReal64 *. The caller should take care of alignment
       
   209      *              The advantage of this method is that you don't have to copy the data
       
   210      *              Bound check will happen
       
   211      * @param       aAt dereference from this position
       
   212      * @exception   Leaves if data size is not sufficient
       
   213      */
       
   214     TReal64 DerefReal64L(TInt aAt = 0);
       
   215     operator TReal64();
       
   216 
       
   217     /**
       
   218      * @fn          IsSafeL
       
   219      *              Checks whether dereferencing is safe for the given length from the given offset
       
   220      * @param       aLength length for dereferencing
       
   221      * @param       aAt offset from where the dereferencing should start
       
   222      */
       
   223     void IsSafeL(TInt aLength, TInt aAt = 0);
       
   224 
       
   225     /**
       
   226      * @fn          GetPtr
       
   227      *              Retrieves the ptr to the data stream
       
   228      */
       
   229     TPtr8 GetPtr();
       
   230 
       
   231     /**
       
   232      * Retrieves the silze of the buffer
       
   233      */
       
   234     TInt GetLength();
       
   235     
       
   236     /**
       
   237      * Returns current reading position
       
   238      */
       
   239     TInt GetReadingPos();
       
   240 
       
   241 private:
       
   242     void CheckOutOfBoundL(TInt aLength);
       
   243 
       
   244     TInt                iTotalRead;
       
   245     TInt                iDataLength;
       
   246     TUint8 *            iReadStream;
       
   247     };
       
   248 
       
   249 #include "NVGIconData.inl"
       
   250 
       
   251 #endif