content/base/public/nsXMLNameSpaceMap.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/base/public/nsXMLNameSpaceMap.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,74 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsXMLNameSpaceMap_h_
    1.10 +#define nsXMLNameSpaceMap_h_
    1.11 +
    1.12 +#include "nsString.h"
    1.13 +#include "nsTArray.h"
    1.14 +#include "nsCOMPtr.h"
    1.15 +#include "nsIAtom.h"
    1.16 +
    1.17 +struct nsNameSpaceEntry
    1.18 +{
    1.19 +  nsNameSpaceEntry(nsIAtom *aPrefix)
    1.20 +    : prefix(aPrefix) {}
    1.21 +
    1.22 +  nsCOMPtr<nsIAtom> prefix;
    1.23 +  int32_t nameSpaceID;
    1.24 +};
    1.25 +
    1.26 +/**
    1.27 + * nsXMLNameSpaceMap contains a set of prefixes which are mapped onto
    1.28 + * namespaces.  It allows the set to be searched by prefix or by namespace ID.
    1.29 + */
    1.30 +class nsXMLNameSpaceMap
    1.31 +{
    1.32 +public:
    1.33 +  /**
    1.34 +   * Allocates a new nsXMLNameSpaceMap (with new()) and if aForXML is
    1.35 +   * true initializes it with the xmlns and xml namespaces.
    1.36 +   */
    1.37 +  static NS_HIDDEN_(nsXMLNameSpaceMap*) Create(bool aForXML);
    1.38 +
    1.39 +  /**
    1.40 +   * Add a prefix and its corresponding namespace ID to the map.
    1.41 +   * Passing a null |aPrefix| corresponds to the default namespace, which may
    1.42 +   * be set to something other than kNameSpaceID_None.
    1.43 +   */
    1.44 +  NS_HIDDEN_(nsresult) AddPrefix(nsIAtom *aPrefix, int32_t aNameSpaceID);
    1.45 +
    1.46 +  /**
    1.47 +   * Add a prefix and a namespace URI to the map.  The URI will be converted
    1.48 +   * to its corresponding namespace ID.
    1.49 +   */
    1.50 +  NS_HIDDEN_(nsresult) AddPrefix(nsIAtom *aPrefix, nsString &aURI);
    1.51 +
    1.52 +  /*
    1.53 +   * Returns the namespace ID for the given prefix, if it is in the map.
    1.54 +   * If |aPrefix| is null and is not in the map, then a null namespace
    1.55 +   * (kNameSpaceID_None) is returned.  If |aPrefix| is non-null and is not in
    1.56 +   * the map, then kNameSpaceID_Unknown is returned.
    1.57 +   */
    1.58 +  NS_HIDDEN_(int32_t) FindNameSpaceID(nsIAtom *aPrefix) const;
    1.59 +
    1.60 +  /**
    1.61 +   * If the given namespace ID is in the map, then the first prefix which
    1.62 +   * maps to that namespace is returned.  Otherwise, null is returned.
    1.63 +   */
    1.64 +  NS_HIDDEN_(nsIAtom*) FindPrefix(int32_t aNameSpaceID) const;
    1.65 +
    1.66 +  /* Removes all prefix mappings. */
    1.67 +  NS_HIDDEN_(void) Clear();
    1.68 +
    1.69 +  ~nsXMLNameSpaceMap() { Clear(); }
    1.70 +
    1.71 +private:
    1.72 +  nsXMLNameSpaceMap() NS_HIDDEN;  // use Create() to create new instances
    1.73 +
    1.74 +  nsTArray<nsNameSpaceEntry> mNameSpaces;
    1.75 +};
    1.76 +
    1.77 +#endif

mercurial