idlehomescreen/xmluirendering/dom/src/xndomdepthiterator.cpp
changeset 0 f72a12da539e
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     1 /*
       
     2 * Copyright (c) 2005,2006 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:  Depth iterator walks the dom tree using depth first principle.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "xndomdepthiterator.h"
       
    22 #include    "xndomlist.h"
       
    23 #include    "xndomnode.h"
       
    24 
       
    25 
       
    26 // Queue granularity value
       
    27 /**
       
    28 */
       
    29 const TInt KMemoryAloc = 64;
       
    30 
       
    31 // ============================ LOCAL FUNCTIONS ===============================
       
    32 
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CXnDomDepthIterator::CXnDomDepthIterator
       
    37 // C++ default constructor can NOT contain any code, that
       
    38 // might leave.
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CXnDomDepthIterator::CXnDomDepthIterator( CXnDomNode* aRootNode ):
       
    42     iStack( KMemoryAloc ), iStart( aRootNode ), iCurrent( aRootNode )
       
    43     {
       
    44     }
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CXnDomDepthIterator::ConstructL
       
    48 // Symbian 2nd phase constructor can leave.
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 void CXnDomDepthIterator::ConstructL()
       
    52     {
       
    53       iStack.AppendL( iStart );
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CXnDomDepthIterator::NewL
       
    58 // Two-phased constructor.
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 EXPORT_C CXnDomDepthIterator* CXnDomDepthIterator::NewL( CXnDomNode& aRootNode )
       
    62     {
       
    63     CXnDomDepthIterator* self = new( ELeave ) CXnDomDepthIterator( &aRootNode );
       
    64     CleanupStack::PushL( self );
       
    65     self->ConstructL();
       
    66     CleanupStack::Pop();
       
    67     return self;
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CXnDomDepthIterator::~CXnDomDepthIterator()
       
    72 // C++ default destructor.
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 EXPORT_C CXnDomDepthIterator::~CXnDomDepthIterator()
       
    76     {
       
    77      iStack.Close();
       
    78     }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CXnDomDepthIterator::First
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 EXPORT_C CXnDomNode* CXnDomDepthIterator::First()
       
    85     {
       
    86     return iStart;
       
    87     }
       
    88     
       
    89 // -----------------------------------------------------------------------------
       
    90 // CXnDomDepthIterator::Next
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 EXPORT_C CXnDomNode* CXnDomDepthIterator::NextL()
       
    94     {
       
    95     if( iStack.Count() )
       
    96         {
       
    97         // Pop
       
    98         TInt topIndex( iStack.Count() - 1 );
       
    99         iCurrent = iStack[topIndex];
       
   100         iStack.Remove( topIndex );
       
   101         
       
   102         CXnDomList& currentChildNodes( iCurrent->ChildNodes() );
       
   103         TInt currentChildCount( currentChildNodes.Length() );
       
   104        
       
   105         // Push left most child to top
       
   106         for( TInt i = currentChildCount - 1; i >= 0; --i )
       
   107             {
       
   108             iStack.AppendL( static_cast< CXnDomNode* >(
       
   109                     currentChildNodes.Item( i ) ) );
       
   110             }
       
   111         }
       
   112     else
       
   113         {
       
   114         iCurrent = NULL;
       
   115         iStack.Reset();
       
   116         iStack.AppendL( iStart );
       
   117         }
       
   118     return iCurrent;
       
   119     }
       
   120 
       
   121 /*
       
   122 // -----------------------------------------------------------------------------
       
   123 // CXnDomDepthIterator::PushL
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 void CXnDomDepthIterator::PushL( CXnDomNode& aNode )
       
   127     {
       
   128     iDepthLevel.AppendL( &aNode );
       
   129     }
       
   130 */
       
   131 // -----------------------------------------------------------------------------
       
   132 // CXnDomDepthIterator::Pop
       
   133 // -----------------------------------------------------------------------------
       
   134 //
       
   135 /*
       
   136 CXnDomNode* CXnDomDepthIterator::Pop()
       
   137     {
       
   138     CXnDomNode* pop = NULL;
       
   139     TInt count( iDepthLevel.Count() );
       
   140     if ( count )
       
   141         {
       
   142         pop = iDepthLevel[ count-1 ];
       
   143         iDepthLevel.Remove( count-1 );
       
   144         }
       
   145     return pop;    
       
   146     }
       
   147 */     
       
   148     
       
   149 //  End of File