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