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 <o3tl/hash_combine.hxx>
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  o3tl::hash_combine(seed, pair.first);
39  o3tl::hash_combine(seed, pair.second.hashCode());
40  return seed;
41  }
42  };
43  std::unordered_map< std::pair<sal_uInt16, OUString>,
45 
46 public:
47  void insert( const SvXMLTokenMapEntry& rEntry );
48  sal_uInt16 get( sal_uInt16 nKeyPrefix, const OUString& rLName ) const;
49 };
50 
52 {
53  bool inserted = m_aPrefixAndNameToTokenMap.insert( std::make_pair( std::make_pair( rEntry.nPrefixKey,
54  GetXMLToken( rEntry.eLocalName ) ), rEntry.nToken ) ).second;
55  assert(inserted && "duplicate token");
56  (void)inserted;
57 }
58 
59 sal_uInt16 SvXMLTokenMap_Impl::get( sal_uInt16 nKeyPrefix, const OUString& rLName ) const
60 {
61  auto aIter( m_aPrefixAndNameToTokenMap.find( std::make_pair( nKeyPrefix, rLName ) ) );
62  if ( aIter != m_aPrefixAndNameToTokenMap.end() )
63  return (*aIter).second;
64  else
65  return XML_TOK_UNKNOWN;
66 }
67 
70 {
71  while( pMap->eLocalName != XML_TOKEN_INVALID )
72  {
73  m_pImpl->insert( *pMap );
74  pMap++;
75  }
76 }
77 
79 {
80 }
81 
82 sal_uInt16 SvXMLTokenMap::Get( sal_uInt16 nKeyPrefix,
83  const OUString& rLName ) const
84 {
85  return m_pImpl->get( nKeyPrefix, rLName );
86 }
87 
88 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 get(sal_uInt16 nKeyPrefix, const OUString &rLName) const
Definition: xmltkmap.cxx:59
#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_uInt16 nPrefixKey
Definition: xmltkmap.hxx:38
sal_uInt16 nToken
Definition: xmltkmap.hxx:39
DECL_LISTENERMULTIPLEXER_END void SAL_CALL inserted(::sal_Int32 ID) override
void insert(const SvXMLTokenMapEntry &rEntry)
Definition: xmltkmap.cxx:51
sal_uInt16 Get(sal_uInt16 nPrefix, const OUString &rLName) const
Definition: xmltkmap.cxx:82
SvXMLTokenMap(const SvXMLTokenMapEntry *pMap)
Definition: xmltkmap.cxx:68
std::enable_if_t<(sizeof(N)==4)> hash_combine(N &nSeed, T const *pValue, size_t nCount)
std::unique_ptr< SvXMLTokenMap_Impl > m_pImpl
Definition: xmltkmap.hxx:53
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:3455
Handling of tokens in XML:
::std::unique_ptr< XmlIdRegistry_Impl > m_pImpl
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo