examples/Base/ArraysAndLists/linkedlist/sgllist/src/sgllist.cpp

Go to the documentation of this file.
00001 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
00002 // All rights reserved.
00003 // This component and the accompanying materials are made available
00004 // under the terms of "Eclipse Public License v1.0"
00005 // which accompanies this distribution, and is available
00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00007 //
00008 // Initial Contributors:
00009 // Nokia Corporation - initial contribution.
00010 //
00011 // Contributors:
00012 //
00013 // Description:
00014 // Contains the E32Main() function, which executes the example.
00015 // The example demonstrates the use of the TSglQue class, which represents
00016 // a singly linked list.
00017 // The user enters a long number, which is stored as linked list of digits
00018 // of the number. The user can edit this number by adding digits to the list
00019 // or removing digits from the list.
00020 // The example displays the sum of all digits of this number on the console.
00021 //
00022 
00023 
00024 
00029 #include "adder.h"
00030 
00031 LOCAL_D CConsoleBase* console;
00032 
00033 LOCAL_C void DoStartL();
00034 LOCAL_C void CallExampleL();
00035 
00036 LOCAL_C void DoStartL()
00037         {
00038         // Create and install the active scheduler.
00039         CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
00040         CleanupStack::PushL(scheduler);
00041         CActiveScheduler::Install(scheduler);
00042 
00043         // Create an object of the CLongNumber class.
00044         CLongNumber* number = CLongNumber::NewL(console);
00045         CleanupStack::PushL(number);
00046 
00047         // Read the number from the user.
00048         _LIT(KTextEnterNumber,"Singly linked list example.\nEnter the digits of a number...\n");
00049         console->Printf(KTextEnterNumber);
00050         // Generate an asynchronous read request.
00051         number->ReadNumber();
00052 
00053         // Start the active scheduler.
00054         CActiveScheduler::Start();
00055 
00056         // Create an object of the CAdder class.
00057         CAdder* adder = CAdder::NewL(number);
00058         // Add all the digits of the number and print the sum.
00059         _LIT(KTextSum,"Sum of all digits of the number : %d\n");
00060         console->Printf(KTextSum,adder->Add());
00061         delete adder;
00062 
00063         // Destroy the objects in the cleanup stack.
00064         CleanupStack::PopAndDestroy(2,scheduler); // number, scheduler.
00065         }
00066 
00067 GLDEF_C TInt E32Main() // main function called by E32
00068     {
00069         __UHEAP_MARK;
00070         CTrapCleanup* cleanup=CTrapCleanup::New(); // get clean-up stack
00071         TRAPD(error, CallExampleL()); // more initialization, then do example
00072         delete cleanup; // destroy clean-up stack
00073         __ASSERT_ALWAYS(!error, User::Panic(KTxtEPOC32EX, error));
00074         __UHEAP_MARKEND;
00075         return 0; // and return
00076     }
00077 
00078 LOCAL_C void CallExampleL() // initialize and call example code under cleanup stack
00079     {
00080         console=Console::NewL(KTxtExampleCode, TSize(KConsFullScreen, KConsFullScreen));
00081         CleanupStack::PushL(console);
00082         TRAPD(error, DoStartL()); // perform example function
00083         if (error)
00084                 console->Printf(KFormatFailed, error);
00085         else
00086                 console->Printf(KTxtOK);
00087         console->Printf(KTextPressAnyKey);
00088         console->Getch(); // get and ignore character
00089         CleanupStack::PopAndDestroy(); // close console
00090     }

Generated by  doxygen 1.6.2