LCOV - code coverage report
Current view: directory - editor/txmgr/src - nsTransactionStack.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 39 28 71.8 %
Date: 2012-06-02 Functions: 9 8 88.9 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is mozilla.org code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Netscape Communications Corporation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 1998
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *
      24                 :  * Alternatively, the contents of this file may be used under the terms of
      25                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      26                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      27                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      28                 :  * of those above. If you wish to allow use of your version of this file only
      29                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      30                 :  * use your version of this file under the terms of the MPL, indicate your
      31                 :  * decision by deleting the provisions above and replace them with the notice
      32                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      33                 :  * the provisions above, a recipient may use your version of this file under
      34                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      35                 :  *
      36                 :  * ***** END LICENSE BLOCK ***** */
      37                 : 
      38                 : #include "nsITransaction.h"
      39                 : #include "nsTransactionItem.h"
      40                 : #include "nsTransactionStack.h"
      41                 : #include "nsCOMPtr.h"
      42                 : #include "nsAutoPtr.h"
      43                 : #include "nsCycleCollectionParticipant.h"
      44                 : #include "mozilla/Util.h"
      45                 : 
      46            3039 : nsTransactionStack::nsTransactionStack(nsTransactionStack::Type aType)
      47                 :   : mQue(0)
      48            3039 :   , mType(aType)
      49                 : {
      50            3039 : }
      51                 : 
      52            6078 : nsTransactionStack::~nsTransactionStack()
      53                 : {
      54            3039 :   Clear();
      55            3039 : }
      56                 : 
      57                 : void
      58           18563 : nsTransactionStack::Push(nsTransactionItem *aTransaction)
      59                 : {
      60           18563 :   if (!aTransaction) {
      61               0 :     return;
      62                 :   }
      63                 : 
      64                 :   /* nsDeque's Push() method adds new items at the back
      65                 :    * of the deque.
      66                 :    */
      67           18563 :   NS_ADDREF(aTransaction);
      68           18563 :   mQue.Push(aTransaction);
      69                 : }
      70                 : 
      71                 : already_AddRefed<nsTransactionItem>
      72           16988 : nsTransactionStack::Pop()
      73                 : {
      74                 :   /* nsDeque is a FIFO, so the top of our stack is actually
      75                 :    * the back of the deque.
      76                 :    */
      77           16988 :   return static_cast<nsTransactionItem*> (mQue.Pop());
      78                 : }
      79                 : 
      80                 : already_AddRefed<nsTransactionItem>
      81            5064 : nsTransactionStack::PopBottom()
      82                 : {
      83                 :   /* nsDeque is a FIFO, so the bottom of our stack is actually
      84                 :    * the front of the deque.
      85                 :    */
      86            5064 :   return static_cast<nsTransactionItem*> (mQue.PopFront());
      87                 : }
      88                 : 
      89                 : already_AddRefed<nsTransactionItem>
      90           15500 : nsTransactionStack::Peek()
      91                 : {
      92           15500 :   nsTransactionItem* transaction = nsnull;
      93           15500 :   if (mQue.GetSize()) {
      94           14364 :     NS_IF_ADDREF(transaction = static_cast<nsTransactionItem*>(mQue.Last()));
      95                 :   }
      96                 : 
      97           15500 :   return transaction;
      98                 : }
      99                 : 
     100                 : already_AddRefed<nsTransactionItem>
     101               0 : nsTransactionStack::GetItem(PRInt32 aIndex)
     102                 : {
     103               0 :   nsTransactionItem* transaction = nsnull;
     104               0 :   if (aIndex >= 0 && aIndex < mQue.GetSize()) {
     105               0 :     NS_IF_ADDREF(transaction =
     106               0 :                  static_cast<nsTransactionItem*>(mQue.ObjectAt(aIndex)));
     107                 :   }
     108                 : 
     109               0 :   return transaction;
     110                 : }
     111                 : 
     112                 : void
     113            3489 : nsTransactionStack::Clear()
     114                 : {
     115            6978 :   nsRefPtr<nsTransactionItem> tx;
     116                 : 
     117            7842 :   do {
     118            7842 :     tx = mType == FOR_UNDO ? Pop() : PopBottom();
     119            7842 :   } while (tx);
     120            3489 : }
     121                 : 
     122                 : void
     123               6 : nsTransactionStack::DoTraverse(nsCycleCollectionTraversalCallback &cb)
     124                 : {
     125               6 :   for (PRInt32 i = 0, qcount = mQue.GetSize(); i < qcount; ++i) {
     126                 :     nsTransactionItem *item =
     127               0 :       static_cast<nsTransactionItem*>(mQue.ObjectAt(i));
     128               0 :     if (item) {
     129               0 :       NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "transaction stack mQue[i]");
     130               0 :       cb.NoteNativeChild(item, &NS_CYCLE_COLLECTION_NAME(nsTransactionItem));
     131                 :     }
     132                 :   }
     133               6 : }

Generated by: LCOV version 1.7