rdf/base/src/nsNameSpaceMap.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/rdf/base/src/nsNameSpaceMap.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,98 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + *
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef nsNameSpaceMap_h__
    1.11 +#define nsNameSpaceMap_h__
    1.12 +
    1.13 +#include "nsCOMPtr.h"
    1.14 +#include "nsString.h"
    1.15 +#include "nsIAtom.h"
    1.16 +
    1.17 +class nsNameSpaceMap
    1.18 +{
    1.19 +public:
    1.20 +    class Entry {
    1.21 +    public:
    1.22 +        Entry(const nsCSubstring& aURI, nsIAtom* aPrefix)
    1.23 +            : mURI(aURI), mPrefix(aPrefix), mNext(nullptr) {
    1.24 +            MOZ_COUNT_CTOR(nsNameSpaceMap::Entry); }
    1.25 +
    1.26 +        ~Entry() { MOZ_COUNT_DTOR(nsNameSpaceMap::Entry); }
    1.27 +        
    1.28 +        nsCString mURI;
    1.29 +        nsCOMPtr<nsIAtom> mPrefix; 
    1.30 +
    1.31 +        Entry* mNext;
    1.32 +    };
    1.33 +
    1.34 +    nsNameSpaceMap();
    1.35 +    ~nsNameSpaceMap();
    1.36 +
    1.37 +    nsresult
    1.38 +    Put(const nsAString& aURI, nsIAtom* aPrefix);
    1.39 +
    1.40 +    nsresult
    1.41 +    Put(const nsCSubstring& aURI, nsIAtom* aPrefix);
    1.42 +
    1.43 +    class const_iterator {
    1.44 +    protected:
    1.45 +        friend class nsNameSpaceMap;
    1.46 +
    1.47 +        const_iterator(const Entry* aCurrent)
    1.48 +            : mCurrent(aCurrent) {}
    1.49 +
    1.50 +        const Entry* mCurrent;
    1.51 +
    1.52 +    public:
    1.53 +        const_iterator()
    1.54 +            : mCurrent(nullptr) {}
    1.55 +
    1.56 +        const_iterator(const const_iterator& iter)
    1.57 +            : mCurrent(iter.mCurrent) {}
    1.58 +
    1.59 +        const_iterator&
    1.60 +        operator=(const const_iterator& iter) {
    1.61 +            mCurrent = iter.mCurrent;
    1.62 +            return *this; }
    1.63 +
    1.64 +        const_iterator&
    1.65 +        operator++() {
    1.66 +            mCurrent = mCurrent->mNext;
    1.67 +            return *this; }
    1.68 +
    1.69 +        const_iterator
    1.70 +        operator++(int) {
    1.71 +            const_iterator tmp(*this);
    1.72 +            mCurrent = mCurrent->mNext;
    1.73 +            return tmp; }
    1.74 +
    1.75 +        const Entry* operator->() const { return mCurrent; }
    1.76 +
    1.77 +        const Entry& operator*() const { return *mCurrent; }
    1.78 +
    1.79 +        bool
    1.80 +        operator==(const const_iterator& iter) const {
    1.81 +            return mCurrent == iter.mCurrent; }
    1.82 +
    1.83 +        bool
    1.84 +        operator!=(const const_iterator& iter) const {
    1.85 +            return ! iter.operator==(*this); }
    1.86 +    };
    1.87 +
    1.88 +    const_iterator first() const {
    1.89 +        return const_iterator(mEntries); }
    1.90 +
    1.91 +    const_iterator last() const {
    1.92 +        return const_iterator(nullptr); }
    1.93 +
    1.94 +    const_iterator GetNameSpaceOf(const nsCSubstring& aURI) const;
    1.95 +
    1.96 +protected:
    1.97 +    Entry* mEntries;
    1.98 +};
    1.99 +
   1.100 +
   1.101 +#endif // nsNameSpaceMap_h__

mercurial