inc/BitStream.inl
changeset 0 95b198f216e5
equal deleted inserted replaced
-1:000000000000 0:95b198f216e5
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // -----------------------------------------------------------------------------
       
    20 // TBitStream::
       
    21 // 
       
    22 // -----------------------------------------------------------------------------
       
    23 //
       
    24 template<TInt S>
       
    25 void TBitStream<S>::Clear()
       
    26     {
       
    27     iData.SetLength(iData.MaxLength());
       
    28     iData.FillZ();
       
    29     }
       
    30 
       
    31 template<TInt S>
       
    32 void TBitStream<S>::SetBit(
       
    33     const TInt aBit)
       
    34     {
       
    35     iData[aBit / 8] |= (1 << (7 - aBit % 8));
       
    36     }
       
    37     
       
    38 template<TInt S>
       
    39 void TBitStream<S>::ClearBit(
       
    40     const TInt aBit)
       
    41     {
       
    42     iData[aBit / 8] &= ~(1 << (7 - aBit % 8));
       
    43     }
       
    44     
       
    45 template<TInt S>
       
    46 void TBitStream<S>::SetBitValue(
       
    47     const TInt aBit,
       
    48     const TInt aValue)
       
    49     {
       
    50     if (aValue)
       
    51         {
       
    52         SetBit(aBit);
       
    53         }
       
    54     else
       
    55         {
       
    56         ClearBit(aBit);
       
    57         }
       
    58     }
       
    59     
       
    60 template<TInt S>
       
    61 TInt TBitStream<S>::GetBit(
       
    62     const TInt aBit) const
       
    63     {
       
    64     return (iData[aBit / 8] & (1 << (7 - aBit % 8))) ? 1 : 0;
       
    65     }
       
    66     
       
    67 template<TInt S>
       
    68 void TBitStream<S>::XorBit(
       
    69     const TInt aBit,
       
    70     const TInt aValue)
       
    71     {
       
    72     iData[aBit / 8] ^= (1 << (7 - aBit % 8));
       
    73     }
       
    74     
       
    75 template<TInt S>
       
    76 TPtrC8 TBitStream<S>::Des() const
       
    77     {
       
    78     return TPtrC8(iData.Ptr(), iData.Length());
       
    79     }
       
    80 
       
    81 template<TInt S>
       
    82 void TBitStream<S>::Set(
       
    83     const TDesC8& aInput)
       
    84     {
       
    85     TInt i;
       
    86     
       
    87     iData.SetLength(aInput.Length());
       
    88     for (i = 0; i < S / 8; i++)
       
    89         {
       
    90         iData[i] = aInput[i];
       
    91         }
       
    92     }
       
    93 
       
    94 template<TInt S>
       
    95 void TBitStream<S>::Copy(
       
    96     TBitStream<S> aBitStream)
       
    97     {
       
    98     iData.Copy(aBitStream.Des());
       
    99     }
       
   100     
       
   101 template<TInt S>
       
   102 void TBitStream<S>::Xor(
       
   103     TBitStream<S> aBitStream)
       
   104     {
       
   105     TPtrC8 des(aBitStream.Des());
       
   106     TInt i;
       
   107     
       
   108     for (i = 0; i < S / 8; i++)
       
   109         {
       
   110         iData[i] ^= des[i];
       
   111         }
       
   112     }
       
   113     
       
   114 template<TInt S>
       
   115 void TBitStream<S>::Or(
       
   116     TBitStream<S> aBitStream)
       
   117     {
       
   118     TPtrC8 des(aBitStream.Des());
       
   119     TInt i;
       
   120     
       
   121     for (i = 0; i < S / 8; i++)
       
   122         {
       
   123         iData[i] |= des[i];
       
   124         }
       
   125     }
       
   126     
       
   127 template<TInt S>
       
   128 void TBitStream<S>::And(
       
   129     TBitStream<S> aBitStream)
       
   130     {
       
   131     TPtrC8 des(aBitStream.Des());
       
   132     TInt i;
       
   133     
       
   134     for (i = 0; i < S / 8; i++)
       
   135         {
       
   136         iData[i] &= des[i];
       
   137         }
       
   138     }
       
   139     
       
   140 template<TInt S>
       
   141 void TBitStream<S>::Not()
       
   142     {
       
   143     TInt i;
       
   144     
       
   145     for (i = 0; i < S / 8; i++)
       
   146         {
       
   147         iData[i] = ~iData[i];
       
   148         }
       
   149     }
       
   150     
       
   151 template<TInt S>
       
   152 TInt TBitStream<S>::operator[](
       
   153     const TInt aBit) const
       
   154     {
       
   155     return GetBit(aBit);
       
   156     }
       
   157     
       
   158 //  End of File