1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmltkmap.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include <tools/debug.hxx>
34 #include <rtl/ustring.hxx>
35 #include <svtools/svarray.hxx>
36 #include <xmloff/xmltkmap.hxx>
37 #include <xmloff/xmltoken.hxx>
40 using namespace ::xmloff::token
;
42 class SvXMLTokenMapEntry_Impl
44 sal_uInt16 nPrefixKey
;
50 sal_uInt16
GetToken() const { return nToken
; }
52 SvXMLTokenMapEntry_Impl( sal_uInt16 nPrefix
, const OUString
& rLName
,
53 sal_uInt16 nTok
=XML_TOK_UNKNOWN
) :
54 nPrefixKey( nPrefix
),
59 SvXMLTokenMapEntry_Impl( const SvXMLTokenMapEntry
& rEntry
) :
60 nPrefixKey( rEntry
.nPrefixKey
),
61 sLocalName( GetXMLToken( rEntry
.eLocalName
) ),
62 nToken( rEntry
.nToken
)
65 BOOL
operator==( const SvXMLTokenMapEntry_Impl
& r
) const
67 return nPrefixKey
== r
.nPrefixKey
&&
68 sLocalName
== r
.sLocalName
;
71 BOOL
operator<( const SvXMLTokenMapEntry_Impl
& r
) const
73 return nPrefixKey
< r
.nPrefixKey
||
74 ( nPrefixKey
== r
.nPrefixKey
&&
75 sLocalName
< r
.sLocalName
);
79 typedef SvXMLTokenMapEntry_Impl
*SvXMLTokenMapEntry_ImplPtr
;
80 SV_DECL_PTRARR_SORT_DEL( SvXMLTokenMap_Impl
, SvXMLTokenMapEntry_ImplPtr
, 5, 5 )
81 SV_IMPL_OP_PTRARR_SORT( SvXMLTokenMap_Impl
, SvXMLTokenMapEntry_ImplPtr
)
83 // ---------------------------------------------------------------------
85 SvXMLTokenMapEntry_Impl
*SvXMLTokenMap::_Find( sal_uInt16 nKeyPrefix
,
86 const OUString
& rLName
) const
88 SvXMLTokenMapEntry_Impl
*pRet
= 0;
89 SvXMLTokenMapEntry_Impl
aTst( nKeyPrefix
, rLName
);
92 if( pImpl
->Seek_Entry( &aTst
, &nPos
) )
94 pRet
= (*pImpl
)[nPos
];
100 SvXMLTokenMap::SvXMLTokenMap( const SvXMLTokenMapEntry
*pMap
) :
101 pImpl( new SvXMLTokenMap_Impl
)
103 while( pMap
->eLocalName
!= XML_TOKEN_INVALID
)
105 pImpl
->Insert( new SvXMLTokenMapEntry_Impl( *pMap
) );
110 SvXMLTokenMap::~SvXMLTokenMap()
115 sal_uInt16
SvXMLTokenMap::Get( sal_uInt16 nKeyPrefix
,
116 const OUString
& rLName
) const
118 SvXMLTokenMapEntry_Impl
*pEntry
= _Find( nKeyPrefix
, rLName
);
120 return pEntry
->GetToken();
122 return XML_TOK_UNKNOWN
;