nss: upgrade to release 3.73
[LibreOffice.git] / xmloff / source / core / xmltkmap.cxx
blobbf61a37488f47294a356151ce2f859697a4151e7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <rtl/ustring.hxx>
21 #include <xmloff/xmltkmap.hxx>
22 #include <xmloff/xmltoken.hxx>
23 #include <boost/functional/hash.hpp>
25 #include <unordered_map>
26 #include <utility>
28 using namespace ::xmloff::token;
30 class SvXMLTokenMap_Impl
32 private:
33 struct PairHash
35 std::size_t operator()(const std::pair<sal_uInt16,OUString> &pair) const
37 std::size_t seed = 0;
38 boost::hash_combine(seed, pair.first);
39 boost::hash_combine(seed, pair.second.hashCode());
40 return seed;
43 std::unordered_map< std::pair<sal_uInt16, OUString>,
44 sal_uInt16, PairHash> m_aPrefixAndNameToTokenMap;
45 std::unordered_map< sal_Int32, sal_uInt16> m_aFastTokenToTokenMap;
47 public:
48 void insert( const SvXMLTokenMapEntry& rEntry );
49 sal_uInt16 get( sal_uInt16 nKeyPrefix, const OUString& rLName ) const;
50 sal_uInt16 get( sal_Int32 nFastTok ) const;
53 void SvXMLTokenMap_Impl::insert( const SvXMLTokenMapEntry& rEntry )
55 bool inserted = m_aPrefixAndNameToTokenMap.insert( std::make_pair( std::make_pair( rEntry.nPrefixKey,
56 GetXMLToken( rEntry.eLocalName ) ), rEntry.nToken ) ).second;
57 assert(inserted && "duplicate token");
58 (void)inserted;
59 if( rEntry.nFastToken )
61 bool inserted2 = m_aFastTokenToTokenMap.insert( std::make_pair( rEntry.nFastToken, rEntry.nToken ) ).second;
62 assert(inserted2 && "duplicate token");
63 (void)inserted2;
67 sal_uInt16 SvXMLTokenMap_Impl::get( sal_uInt16 nKeyPrefix, const OUString& rLName ) const
69 auto aIter( m_aPrefixAndNameToTokenMap.find( std::make_pair( nKeyPrefix, rLName ) ) );
70 if ( aIter != m_aPrefixAndNameToTokenMap.end() )
71 return (*aIter).second;
72 else
73 return XML_TOK_UNKNOWN;
76 sal_uInt16 SvXMLTokenMap_Impl::get( sal_Int32 nFastTok ) const
78 auto aIter( m_aFastTokenToTokenMap.find( nFastTok ) );
79 if ( aIter != m_aFastTokenToTokenMap.end() )
80 return (*aIter).second;
81 else
82 return XML_TOK_UNKNOWN;
85 SvXMLTokenMap::SvXMLTokenMap( const SvXMLTokenMapEntry *pMap )
86 : m_pImpl( new SvXMLTokenMap_Impl )
88 while( pMap->eLocalName != XML_TOKEN_INVALID )
90 m_pImpl->insert( *pMap );
91 pMap++;
95 SvXMLTokenMap::~SvXMLTokenMap()
99 sal_uInt16 SvXMLTokenMap::Get( sal_uInt16 nKeyPrefix,
100 const OUString& rLName ) const
102 return m_pImpl->get( nKeyPrefix, rLName );
105 sal_uInt16 SvXMLTokenMap::Get( sal_Int32 nFastTok ) const
107 return m_pImpl->get( nFastTok );
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */