Line data Source code
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/ptr_container/ptr_set.hpp>
24 :
25 : using namespace ::xmloff::token;
26 :
27 :
28 179701 : class SvXMLTokenMapEntry_Impl
29 : {
30 : sal_uInt16 nPrefixKey;
31 : OUString sLocalName;
32 : sal_uInt16 nToken;
33 :
34 : public:
35 :
36 62709 : sal_uInt16 GetToken() const { return nToken; }
37 :
38 67818 : SvXMLTokenMapEntry_Impl( sal_uInt16 nPrefix, const OUString& rLName,
39 : sal_uInt16 nTok=XML_TOK_UNKNOWN ) :
40 : nPrefixKey( nPrefix ),
41 : sLocalName( rLName ),
42 67818 : nToken( nTok )
43 67818 : {}
44 :
45 111883 : SvXMLTokenMapEntry_Impl( const SvXMLTokenMapEntry& rEntry ) :
46 : nPrefixKey( rEntry.nPrefixKey ),
47 111883 : sLocalName( GetXMLToken( rEntry.eLocalName ) ),
48 223766 : nToken( rEntry.nToken )
49 111883 : {}
50 :
51 : sal_Bool operator==( const SvXMLTokenMapEntry_Impl& r ) const
52 : {
53 : return nPrefixKey == r.nPrefixKey &&
54 : sLocalName == r.sLocalName;
55 : }
56 :
57 843696 : sal_Bool operator<( const SvXMLTokenMapEntry_Impl& r ) const
58 : {
59 2023417 : return nPrefixKey < r.nPrefixKey ||
60 1404961 : ( nPrefixKey == r.nPrefixKey &&
61 1498018 : sLocalName < r.sLocalName);
62 : }
63 : };
64 :
65 16716 : class SvXMLTokenMap_Impl : public boost::ptr_set<SvXMLTokenMapEntry_Impl> {};
66 :
67 : // ---------------------------------------------------------------------
68 :
69 67818 : SvXMLTokenMapEntry_Impl *SvXMLTokenMap::_Find( sal_uInt16 nKeyPrefix,
70 : const OUString& rLName ) const
71 : {
72 67818 : SvXMLTokenMapEntry_Impl *pRet = 0;
73 67818 : SvXMLTokenMapEntry_Impl aTst( nKeyPrefix, rLName );
74 :
75 67818 : SvXMLTokenMap_Impl::iterator it = pImpl->find( aTst );
76 67818 : if( it != pImpl->end() )
77 : {
78 62709 : pRet = &*it;
79 : }
80 :
81 67818 : return pRet;
82 : }
83 :
84 8358 : SvXMLTokenMap::SvXMLTokenMap( const SvXMLTokenMapEntry *pMap ) :
85 8358 : pImpl( new SvXMLTokenMap_Impl )
86 : {
87 128599 : while( pMap->eLocalName != XML_TOKEN_INVALID )
88 : {
89 111883 : pImpl->insert( new SvXMLTokenMapEntry_Impl( *pMap ) );
90 111883 : pMap++;
91 : }
92 8358 : }
93 :
94 8358 : SvXMLTokenMap::~SvXMLTokenMap()
95 : {
96 8358 : delete pImpl;
97 8358 : }
98 :
99 67818 : sal_uInt16 SvXMLTokenMap::Get( sal_uInt16 nKeyPrefix,
100 : const OUString& rLName ) const
101 : {
102 67818 : SvXMLTokenMapEntry_Impl *pEntry = _Find( nKeyPrefix, rLName );
103 67818 : if( pEntry )
104 62709 : return pEntry->GetToken();
105 : else
106 5109 : return XML_TOK_UNKNOWN;
107 : }
108 :
109 :
110 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|