VegaPrime Code Example 2

 
How Display and Iterate through vsSwitch Nodes and Masks

 

     

    This example function illustrates how to :

     

    • How define vsSwitch::const_iterator_mask iterator to traverse through vsSwitch Nodes Masks
    • How to get the name of a vsSwitch node
    • How to display the address of a vsSwitch node
    • How vsSwitch node masks are stored as an stl::pair
    • How to retrieve the name of a vsSwitch node masks
    • How to retrieve the number of active children of a vsSwitch node mask
    • How to retrieve the vuVector of active children from vsSwitch::Mask
    • How to iterate through the vuVector of active children
    • How to retrieve and display the indices of the active children
    • How to use begin and end iterator more efficently
    • To use ++Val as pre-increment rather than Val++ post-increment

     

Code :

--

 

 

void

printSwitchDetails( vsSwitch *switchNode ){

// ---------------------------------------------------------

// Public Function                   

//

//  Quick and simple function to display switch node state

//

//  Assumes that switchNode is a valid vsSwitch Node

//

// ---------------------------------------------------------

 

    //

    // Sanity check we need a node

    //

    if( switchNode == NULL )

        return;

     

     

    //

    // For clarity grab the iterator's for start and end of the list

    //

    //

    // Note that getting the  'Start' and 'End ' iterator's outside  

    //       of the loop is generally considered more efficient than

    //       getting the iterators inside of the loops

    //

 

    vsSwitch::const_iterator_mask swIter = switchNode->begin_mask();

 

    vsSwitch::const_iterator_mask swEnd  = switchNode->end_mask();

 

     

    printf("Getting Masks for switch Node :  %s ( %p ) \n\n",  switchNode->getName(),  switchNode );

     

    //

    // Iterate through the Masks which a Vector containing a value pair

    //

    //     std::pair<vuString, vuVector<int> > where

    //      

    //     first  : is the name of the Mask if it has one

    //      

    //     second : is a vector of ints representing the active children

    //

    //

    // Firstly we step through the list of all the masks which is

    // vector of ( stl::pair<vuString, vuVector<int> > )

    //

    //

    // Note it is generally accepted that using the ++Iter (pre-increment)  

    //       with iterators is efficent that using iter++ (post-increment)

    //

 

    for (  ; swIter != swEnd; ++ swIter ) {

                    

        printf("   Mask : %s :  Number Active children = %d \n\n",

                      (*swIter).first.c_str(),

                      (*swIter).second.size() );

            

            

            //

            // The Second value of the pair is a Vector of Ints which represent

            // the active children for the mask

            //

            // So we need to grab and create some Interators of type vuVector<int>

            //    

 

            vuVector< int >::const_iterator  maskIt  =  (*swIter).second.begin();

 

 

            vuVector< int >::const_iterator  maskEnd =  (*swIter).second.end();

          

            //

            // Now step through and show the active childrend indices

            //

            for (  ; maskIt != maskEnd; ++ maskIt ) {      

                      

                printf( "       Child Index : = %d \n", *maskIt );

 

                }  

             

      }

 

} //  printSwitchDetails

 

 

 

 

starline3.gif

Copyright 2001-2005 Gordon Tomlinson  All Rights Reserved.

All logos, trademarks and copyrights in this site are property of their respective owner.