Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <rtl/ustring.hxx>
30 : : #include <xmloff/xmltkmap.hxx>
31 : : #include <xmloff/xmltoken.hxx>
32 : : #include <boost/ptr_container/ptr_set.hpp>
33 : :
34 : : using namespace ::xmloff::token;
35 : :
36 : : using ::rtl::OUString;
37 : :
38 : 332634 : class SvXMLTokenMapEntry_Impl
39 : : {
40 : : sal_uInt16 nPrefixKey;
41 : : OUString sLocalName;
42 : : sal_uInt16 nToken;
43 : :
44 : : public:
45 : :
46 : 134908 : sal_uInt16 GetToken() const { return nToken; }
47 : :
48 : 144550 : SvXMLTokenMapEntry_Impl( sal_uInt16 nPrefix, const OUString& rLName,
49 : : sal_uInt16 nTok=XML_TOK_UNKNOWN ) :
50 : : nPrefixKey( nPrefix ),
51 : : sLocalName( rLName ),
52 : 144550 : nToken( nTok )
53 : 144550 : {}
54 : :
55 : 188084 : SvXMLTokenMapEntry_Impl( const SvXMLTokenMapEntry& rEntry ) :
56 : : nPrefixKey( rEntry.nPrefixKey ),
57 : 188084 : sLocalName( GetXMLToken( rEntry.eLocalName ) ),
58 : 188084 : nToken( rEntry.nToken )
59 : 188084 : {}
60 : :
61 : : sal_Bool operator==( const SvXMLTokenMapEntry_Impl& r ) const
62 : : {
63 : : return nPrefixKey == r.nPrefixKey &&
64 : : sLocalName == r.sLocalName;
65 : : }
66 : :
67 : 1550674 : sal_Bool operator<( const SvXMLTokenMapEntry_Impl& r ) const
68 : : {
69 : : return nPrefixKey < r.nPrefixKey ||
70 : : ( nPrefixKey == r.nPrefixKey &&
71 [ + + ][ + + ]: 1550674 : sLocalName < r.sLocalName);
[ + + ]
72 : : }
73 : : };
74 : :
75 : 27976 : class SvXMLTokenMap_Impl : public boost::ptr_set<SvXMLTokenMapEntry_Impl> {};
76 : :
77 : : // ---------------------------------------------------------------------
78 : :
79 : 144550 : SvXMLTokenMapEntry_Impl *SvXMLTokenMap::_Find( sal_uInt16 nKeyPrefix,
80 : : const OUString& rLName ) const
81 : : {
82 : 144550 : SvXMLTokenMapEntry_Impl *pRet = 0;
83 : 144550 : SvXMLTokenMapEntry_Impl aTst( nKeyPrefix, rLName );
84 : :
85 [ + - ]: 144550 : SvXMLTokenMap_Impl::iterator it = pImpl->find( aTst );
86 [ + - ][ + - ]: 144550 : if( it != pImpl->end() )
[ + + ]
87 : : {
88 [ + - ]: 134908 : pRet = &*it;
89 : : }
90 : :
91 : 144550 : return pRet;
92 : : }
93 : :
94 : 13988 : SvXMLTokenMap::SvXMLTokenMap( const SvXMLTokenMapEntry *pMap ) :
95 [ + - ]: 13988 : pImpl( new SvXMLTokenMap_Impl )
96 : : {
97 [ + + ]: 202072 : while( pMap->eLocalName != XML_TOKEN_INVALID )
98 : : {
99 [ + - ]: 188084 : pImpl->insert( new SvXMLTokenMapEntry_Impl( *pMap ) );
100 : 188084 : pMap++;
101 : : }
102 : 13988 : }
103 : :
104 : 13988 : SvXMLTokenMap::~SvXMLTokenMap()
105 : : {
106 [ + - ]: 13988 : delete pImpl;
107 : 13988 : }
108 : :
109 : 144550 : sal_uInt16 SvXMLTokenMap::Get( sal_uInt16 nKeyPrefix,
110 : : const OUString& rLName ) const
111 : : {
112 : 144550 : SvXMLTokenMapEntry_Impl *pEntry = _Find( nKeyPrefix, rLName );
113 [ + + ]: 144550 : if( pEntry )
114 : 134908 : return pEntry->GetToken();
115 : : else
116 : 144550 : return XML_TOK_UNKNOWN;
117 : : }
118 : :
119 : :
120 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|