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