LibreOffice Module xmloff (master)  1
xmltkmap.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <rtl/ustring.hxx>
21 #include <xmloff/xmltkmap.hxx>
22 #include <xmloff/xmltoken.hxx>
23 #include <boost/functional/hash.hpp>
24 
25 #include <unordered_map>
26 #include <utility>
27 
28 using namespace ::xmloff::token;
29 
31 {
32 private:
33  struct PairHash
34  {
35  std::size_t operator()(const std::pair<sal_uInt16,OUString> &pair) const
36  {
37  std::size_t seed = 0;
38  boost::hash_combine(seed, pair.first);
39  boost::hash_combine(seed, pair.second.hashCode());
40  return seed;
41  }
42  };
43  std::unordered_map< std::pair<sal_uInt16, OUString>,
45  std::unordered_map< sal_Int32, sal_uInt16> m_aFastTokenToTokenMap;
46 
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;
51 };
52 
54 {
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 )
60  {
61  bool inserted2 = m_aFastTokenToTokenMap.insert( std::make_pair( rEntry.nFastToken, rEntry.nToken ) ).second;
62  assert(inserted2 && "duplicate token");
63  (void)inserted2;
64  }
65 }
66 
67 sal_uInt16 SvXMLTokenMap_Impl::get( sal_uInt16 nKeyPrefix, const OUString& rLName ) const
68 {
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;
74 }
75 
76 sal_uInt16 SvXMLTokenMap_Impl::get( sal_Int32 nFastTok ) const
77 {
78  auto aIter( m_aFastTokenToTokenMap.find( nFastTok ) );
79  if ( aIter != m_aFastTokenToTokenMap.end() )
80  return (*aIter).second;
81  else
82  return XML_TOK_UNKNOWN;
83 }
84 
87 {
88  while( pMap->eLocalName != XML_TOKEN_INVALID )
89  {
90  m_pImpl->insert( *pMap );
91  pMap++;
92  }
93 }
94 
96 {
97 }
98 
99 sal_uInt16 SvXMLTokenMap::Get( sal_uInt16 nKeyPrefix,
100  const OUString& rLName ) const
101 {
102  return m_pImpl->get( nKeyPrefix, rLName );
103 }
104 
105 sal_uInt16 SvXMLTokenMap::Get( sal_Int32 nFastTok ) const
106 {
107  return m_pImpl->get( nFastTok );
108 }
109 
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 get(sal_uInt16 nKeyPrefix, const OUString &rLName) const
Definition: xmltkmap.cxx:67
#define XML_TOK_UNKNOWN
Definition: xmltkmap.hxx:32
std::unordered_map< std::pair< sal_uInt16, OUString >, sal_uInt16, PairHash > m_aPrefixAndNameToTokenMap
Definition: xmltkmap.cxx:44
sal_Int32 nFastToken
Definition: xmltkmap.hxx:38
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
sal_uInt16 nPrefixKey
Definition: xmltkmap.hxx:39
sal_uInt16 nToken
Definition: xmltkmap.hxx:40
DECL_LISTENERMULTIPLEXER_END void SAL_CALL inserted(::sal_Int32 ID) override
void insert(const SvXMLTokenMapEntry &rEntry)
Definition: xmltkmap.cxx:53
sal_uInt16 Get(sal_uInt16 nPrefix, const OUString &rLName) const
Definition: xmltkmap.cxx:99
SvXMLTokenMap(const SvXMLTokenMapEntry *pMap)
Definition: xmltkmap.cxx:85
std::unique_ptr< SvXMLTokenMap_Impl > m_pImpl
Definition: xmltkmap.hxx:55
std::unordered_map< sal_Int32, sal_uInt16 > m_aFastTokenToTokenMap
Definition: xmltkmap.cxx:45
enum xmloff::token::XMLTokenEnum eLocalName
Definition: xmltkmap.hxx:37
std::size_t operator()(const std::pair< sal_uInt16, OUString > &pair) const
Definition: xmltkmap.cxx:35
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Definition: xmltoken.cxx:3378
Handling of tokens in XML:
::std::unique_ptr< XmlIdRegistry_Impl > m_pImpl
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo