extras/calcsoft/src/CalcHistory.cpp
branchRCL_3
changeset 23 41b775cdc0c8
parent 22 0f21a5ec0db7
child 24 10c6e6d6e4d9
equal deleted inserted replaced
22:0f21a5ec0db7 23:41b775cdc0c8
     1 /*
       
     2 * Copyright (c) 2002 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:  Define CCalcHistory class. This class is handled historical 
       
    15 *                line of the calculator. 
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "CalcEditline.h" 
       
    23 #include "CalcHistory.h" 
       
    24 
       
    25 //  LOCAL CONSTANTS AND MACROS  
       
    26 
       
    27 
       
    28 // ================= MEMBER FUNCTIONS =======================
       
    29 
       
    30 // C++ default constructor can NOT contain any code, that
       
    31 // might leave.
       
    32 //
       
    33 CCalcHistory::CCalcHistory():
       
    34               iNewestIndex(KCalcMaxHistoryLines - 1)
       
    35     {
       
    36     iHistory[iNewestIndex].AllClear();
       
    37     }
       
    38 
       
    39 // Destructor
       
    40 CCalcHistory::~CCalcHistory()
       
    41     {
       
    42     }
       
    43 
       
    44 
       
    45 
       
    46 // Assignment operator
       
    47 // This inplementation depends on how to have history data. 
       
    48 // Refer to description of member data, CCalcHistory.h 
       
    49 // 
       
    50 const TCalcEditLine& CCalcHistory::operator[]
       
    51                        (TInt aIndex) // Get (aIndex + 1)th latest history line 
       
    52     {
       
    53     TInt lineIndex(iNewestIndex - aIndex);
       
    54     
       
    55     if ( lineIndex < 0 )
       
    56         {
       
    57         lineIndex += KCalcMaxHistoryLines;
       
    58         }
       
    59         
       
    60     return iHistory[lineIndex];      
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------
       
    64 // CCalcHistory::Count
       
    65 // Return count of histoical lines.
       
    66 // (other items were commented in a header).
       
    67 // ---------------------------------------------------------
       
    68 //
       
    69 TInt CCalcHistory::Count() const     
       
    70     {
       
    71     return iCount;
       
    72     }
       
    73 
       
    74 // ---------------------------------------------------------
       
    75 // CCalcHistory::Add
       
    76 // This inplementation depends on how to have history data. 
       
    77 // Refer to description of member data, CCalcHistory.h 
       
    78 // (other items were commented in a header).
       
    79 // ---------------------------------------------------------
       
    80 //
       
    81 void CCalcHistory::Add
       
    82                 (const TCalcEditLine aLine) 
       
    83     {
       
    84     if ( iNewestIndex == (KCalcMaxHistoryLines - 1) )
       
    85         {
       
    86         iNewestIndex = 0;
       
    87         }
       
    88     else
       
    89         {
       
    90         iNewestIndex++;
       
    91         }
       
    92     
       
    93     if ( iCount < KCalcMaxHistoryLines )
       
    94         {
       
    95         iCount++;
       
    96         }
       
    97     
       
    98     iHistory[iNewestIndex] = aLine;
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------
       
   102 // CCalcHistory::ClearHistory
       
   103 // Clear calculation history.
       
   104 // (other items were commented in a header).
       
   105 // ---------------------------------------------------------
       
   106 //
       
   107 void CCalcHistory::ClearHistory()
       
   108     {
       
   109     iCount = 0;
       
   110     iNewestIndex = KCalcMaxHistoryLines - 1;
       
   111     for (TInt cnt(0); cnt < KCalcMaxHistoryLines; cnt++)
       
   112         {
       
   113         iHistory[cnt].AllClear();
       
   114         }
       
   115     }
       
   116 
       
   117 
       
   118 // ---------------------------------------------------------
       
   119 // CCalcHistory::NotifyChangeDecimal
       
   120 // Call when decimal separator is changed.
       
   121 // (other items were commented in a header).
       
   122 // ---------------------------------------------------------
       
   123 //
       
   124 void CCalcHistory::NotifyChangeDecimal(TChar aOld, TChar aNew)
       
   125     {
       
   126     for (TInt cnt(0); cnt < iCount; cnt++)
       
   127         {
       
   128         iHistory[cnt].ChangeDecimal(aOld, aNew);
       
   129         }
       
   130     }
       
   131         
       
   132 
       
   133 
       
   134 // End of File