LCOV - code coverage report
Current view: directory - content/xul/templates/src - nsContentSupportMap.h (source / functions) Found Hit Coverage
Test: app.info Lines: 23 0 0.0 %
Date: 2012-06-02 Functions: 5 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       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 Communicator client 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                 :  *   Chris Waterson <waterson@netscape.com>
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      27                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 : #ifndef nsContentSupportMap_h__
      40                 : #define nsContentSupportMap_h__
      41                 : 
      42                 : #include "pldhash.h"
      43                 : #include "nsFixedSizeAllocator.h"
      44                 : #include "nsTemplateMatch.h"
      45                 : 
      46                 : /**
      47                 :  * The nsContentSupportMap maintains a mapping from a "resource element"
      48                 :  * in the content tree to the nsTemplateMatch that was used to instantiate it. This
      49                 :  * is necessary to allow the XUL content to be built lazily. Specifically,
      50                 :  * when building "resumes" on a partially-built content element, the builder
      51                 :  * will walk upwards in the content tree to find the first element with an
      52                 :  * 'id' attribute. This element is assumed to be the "resource element",
      53                 :  * and allows the content builder to access the nsTemplateMatch (variable assignments
      54                 :  * and rule information).
      55                 :  */
      56                 : class nsContentSupportMap {
      57                 : public:
      58               0 :     nsContentSupportMap() { Init(); }
      59               0 :     ~nsContentSupportMap() { Finish(); }
      60                 : 
      61               0 :     nsresult Put(nsIContent* aElement, nsTemplateMatch* aMatch) {
      62               0 :         if (!mMap.ops)
      63               0 :             return NS_ERROR_NOT_INITIALIZED;
      64                 : 
      65               0 :         PLDHashEntryHdr* hdr = PL_DHashTableOperate(&mMap, aElement, PL_DHASH_ADD);
      66               0 :         if (!hdr)
      67               0 :             return NS_ERROR_OUT_OF_MEMORY;
      68                 : 
      69               0 :         Entry* entry = reinterpret_cast<Entry*>(hdr);
      70               0 :         NS_ASSERTION(entry->mMatch == nsnull, "over-writing entry");
      71               0 :         entry->mContent = aElement;
      72               0 :         entry->mMatch   = aMatch;
      73               0 :         return NS_OK; }
      74                 : 
      75               0 :     bool Get(nsIContent* aElement, nsTemplateMatch** aMatch) {
      76               0 :         if (!mMap.ops)
      77               0 :             return false;
      78                 : 
      79               0 :         PLDHashEntryHdr* hdr = PL_DHashTableOperate(&mMap, aElement, PL_DHASH_LOOKUP);
      80               0 :         if (PL_DHASH_ENTRY_IS_FREE(hdr))
      81               0 :             return false;
      82                 : 
      83               0 :         Entry* entry = reinterpret_cast<Entry*>(hdr);
      84               0 :         *aMatch = entry->mMatch;
      85               0 :         return true; }
      86                 : 
      87                 :     nsresult Remove(nsIContent* aElement);
      88                 : 
      89               0 :     void Clear() { Finish(); Init(); }
      90                 : 
      91                 : protected:
      92                 :     PLDHashTable mMap;
      93                 : 
      94                 :     void Init();
      95                 :     void Finish();
      96                 : 
      97                 :     struct Entry {
      98                 :         PLDHashEntryHdr  mHdr;
      99                 :         nsIContent*      mContent;
     100                 :         nsTemplateMatch* mMatch;
     101                 :     };
     102                 : };
     103                 : 
     104                 : #endif

Generated by: LCOV version 1.7