dom/xslt/base/txList.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef TRANSFRMX_LIST_H
     7 #define TRANSFRMX_LIST_H
     9 #include "txCore.h"
    11 class txListIterator;
    13 /**
    14  * Represents an ordered list of Object pointers. Modeled after a Java 2 List.
    15 **/
    16 class txList : public txObject {
    18 friend class txListIterator;
    20 public:
    22     /**
    23     * Creates an empty txList
    24     **/
    25     txList();
    27     /**
    28      * txList destructor, object references will not be deleted.
    29     **/
    30     ~txList();
    32     /**
    33      * Returns the number of items in this txList
    34     **/
    35     int32_t getLength();
    37     /**
    38      * Returns true if there are no items in this txList
    39      */
    40     inline bool isEmpty()
    41     {
    42         return itemCount == 0;
    43     }
    45     /**
    46      * Adds the given Object to the list
    47     **/
    48     nsresult add(void* objPtr);
    50     /*
    51      * Removes all the objects from the list
    52      */
    53     void clear();
    55 protected:
    57     struct ListItem {
    58         ListItem* nextItem;
    59         ListItem* prevItem;
    60         void* objPtr;
    61     };
    63     /**
    64      * Removes the given ListItem pointer from the list
    65     **/
    66     ListItem* remove(ListItem* sItem);
    68 private:
    69       txList(const txList& aOther); // not implemented
    71       ListItem* firstItem;
    72       ListItem* lastItem;
    73       int32_t itemCount;
    75       nsresult insertAfter(void* objPtr, ListItem* sItem);
    76       nsresult insertBefore(void* objPtr, ListItem* sItem);
    77 };
    81 /**
    82  * An Iterator for the txList Class
    83 **/
    84 class txListIterator {
    86 public:
    87     /**
    88      * Creates a new txListIterator for the given txList
    89      * @param list, the txList to create an Iterator for
    90     **/
    91     txListIterator(txList* list);
    93     /**
    94      * Adds the Object pointer to the txList pointed to by this txListIterator.
    95      * The Object pointer is inserted as the next item in the txList
    96      * based on the current position within the txList
    97      * @param objPtr the Object pointer to add to the list
    98     **/
    99     nsresult addAfter(void* objPtr);
   101     /**
   102      * Adds the Object pointer to the txList pointed to by this txListIterator.
   103      * The Object pointer is inserted as the previous item in the txList
   104      * based on the current position within the txList
   105      * @param objPtr the Object pointer to add to the list
   106     **/
   107     nsresult addBefore(void* objPtr);
   109     /**
   110      * Returns true if a successful call to the next() method can be made
   111      * @return true if a successful call to the next() method can be made,
   112      * otherwise false
   113     **/
   114     bool  hasNext();
   116     /**
   117      * Returns the next Object pointer from the list
   118     **/
   119     void* next();
   121     /**
   122      * Returns the previous Object pointer from the list
   123     **/
   124     void* previous();
   126     /**
   127      * Returns the current Object
   128     **/
   129     void* current();
   131     /**
   132      * Removes the Object last returned by the next() or previous() methods;
   133      * @return the removed Object pointer
   134     **/
   135     void* remove();
   137     /**
   138      * Resets the current location within the txList to the beginning of the txList
   139     **/
   140     void reset();
   142     /**
   143      * Resets the current location within the txList to the end of the txList
   144     **/
   145     void resetToEnd();
   147 private:
   149    //-- points to the current list item
   150    txList::ListItem* currentItem;
   152    //-- points to the list to iterator over
   153    txList* list;
   155    //-- we've moved off the end of the list
   156    bool atEndOfList;
   157 };
   159 typedef txList List;
   161 #endif

mercurial