Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / xmloff / source / core / xmltkmap.cxx
blob1b5810fc4fb0d045038e402fab963032c114e80d
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>
24 #include <set>
26 using namespace ::xmloff::token;
28 class SvXMLTokenMapEntry_Impl
30 sal_uInt16 nPrefixKey;
31 OUString sLocalName;
32 sal_uInt16 nToken;
34 public:
36 sal_uInt16 GetToken() const { return nToken; }
38 SvXMLTokenMapEntry_Impl( sal_uInt16 nPrefix, const OUString& rLName,
39 sal_uInt16 nTok=XML_TOK_UNKNOWN ) :
40 nPrefixKey( nPrefix ),
41 sLocalName( rLName ),
42 nToken( nTok )
45 explicit SvXMLTokenMapEntry_Impl( const SvXMLTokenMapEntry& rEntry ) :
46 nPrefixKey( rEntry.nPrefixKey ),
47 sLocalName( GetXMLToken( rEntry.eLocalName ) ),
48 nToken( rEntry.nToken )
51 bool operator<( const SvXMLTokenMapEntry_Impl& r ) const
53 return nPrefixKey < r.nPrefixKey ||
54 ( nPrefixKey == r.nPrefixKey &&
55 sLocalName < r.sLocalName);
59 class SvXMLTokenMap_Impl : public std::set<SvXMLTokenMapEntry_Impl> {};
61 SvXMLTokenMap::SvXMLTokenMap( const SvXMLTokenMapEntry *pMap )
62 : m_pImpl( new SvXMLTokenMap_Impl )
64 while( pMap->eLocalName != XML_TOKEN_INVALID )
66 m_pImpl->insert(SvXMLTokenMapEntry_Impl( *pMap ));
67 pMap++;
71 SvXMLTokenMap::~SvXMLTokenMap()
75 sal_uInt16 SvXMLTokenMap::Get( sal_uInt16 nKeyPrefix,
76 const OUString& rLName ) const
78 SvXMLTokenMapEntry_Impl const* pEntry = nullptr;
79 SvXMLTokenMapEntry_Impl aTst( nKeyPrefix, rLName );
81 SvXMLTokenMap_Impl::iterator it = m_pImpl->find( aTst );
82 if (it != m_pImpl->end())
84 pEntry = &*it;
87 if( pEntry )
88 return pEntry->GetToken();
89 else
90 return XML_TOK_UNKNOWN;
93 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */