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