content/xul/templates/src/nsTemplateMap.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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 nsTemplateMap_h__
     7 #define nsTemplateMap_h__
     9 #include "pldhash.h"
    10 #include "nsXULElement.h"
    12 class nsTemplateMap {
    13 protected:
    14     struct Entry {
    15         PLDHashEntryHdr mHdr;
    16         nsIContent*     mContent;
    17         nsIContent*     mTemplate;
    18     };
    20     PLDHashTable mTable;
    22     void
    23     Init() { PL_DHashTableInit(&mTable, PL_DHashGetStubOps(), nullptr, sizeof(Entry), PL_DHASH_MIN_SIZE); }
    25     void
    26     Finish() { PL_DHashTableFinish(&mTable); }
    28 public:
    29     nsTemplateMap() { Init(); }
    31     ~nsTemplateMap() { Finish(); }
    33     void
    34     Put(nsIContent* aContent, nsIContent* aTemplate) {
    35         NS_ASSERTION(PL_DHASH_ENTRY_IS_FREE(PL_DHashTableOperate(&mTable, aContent, PL_DHASH_LOOKUP)),
    36                      "aContent already in map");
    38         Entry* entry =
    39             reinterpret_cast<Entry*>(PL_DHashTableOperate(&mTable, aContent, PL_DHASH_ADD));
    41         if (entry) {
    42             entry->mContent = aContent;
    43             entry->mTemplate = aTemplate;
    44         }
    45     }
    47     void
    48     Remove(nsIContent* aContent) {
    49         PL_DHashTableOperate(&mTable, aContent, PL_DHASH_REMOVE);
    51         for (nsIContent* child = aContent->GetFirstChild();
    52              child;
    53              child = child->GetNextSibling()) {
    54             Remove(child);
    55         }
    56     }
    59     void
    60     GetTemplateFor(nsIContent* aContent, nsIContent** aResult) {
    61         Entry* entry =
    62             reinterpret_cast<Entry*>(PL_DHashTableOperate(&mTable, aContent, PL_DHASH_LOOKUP));
    64         if (PL_DHASH_ENTRY_IS_BUSY(&entry->mHdr))
    65             NS_IF_ADDREF(*aResult = entry->mTemplate);
    66         else
    67             *aResult = nullptr;
    68     }
    70     void
    71     Clear() { Finish(); Init(); }
    72 };
    74 #endif // nsTemplateMap_h__

mercurial