Update ooo320-m1
[ooovba.git] / xmloff / source / core / i18nmap.cxx
blob5f5d1a60c04e83b252cd50fb3ee61a967ffad6ab
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: i18nmap.cxx,v $
10 * $Revision: 1.5 $
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 <rtl/ustring.hxx>
34 #include <tools/debug.hxx>
35 #include <svtools/svarray.hxx>
36 #include "i18nmap.hxx"
38 using namespace rtl;
40 class SvI18NMapEntry_Impl
42 USHORT nKind;
43 OUString aName;
44 OUString aNewName;
46 public:
48 const OUString& GetNewName() const { return aNewName; }
50 SvI18NMapEntry_Impl( USHORT nKnd, const OUString& rName,
51 const OUString& rNewName ) :
52 nKind( nKnd ),
53 aName( rName ),
54 aNewName( rNewName )
57 SvI18NMapEntry_Impl( USHORT nKnd, const OUString& rName ) :
58 nKind( nKnd ),
59 aName( rName )
62 BOOL operator==( const SvI18NMapEntry_Impl& r ) const
64 return nKind == r.nKind &&
65 aName == r.aName;
68 BOOL operator<( const SvI18NMapEntry_Impl& r ) const
70 return nKind < r.nKind ||
71 ( nKind == r.nKind &&
72 aName < r.aName);
76 typedef SvI18NMapEntry_Impl *SvI18NMapEntry_ImplPtr;
77 SV_DECL_PTRARR_SORT_DEL( SvI18NMap_Impl, SvI18NMapEntry_ImplPtr, 20, 5 )
78 SV_IMPL_OP_PTRARR_SORT( SvI18NMap_Impl, SvI18NMapEntry_ImplPtr )
80 // ---------------------------------------------------------------------
82 SvI18NMapEntry_Impl *SvI18NMap::_Find( USHORT nKind,
83 const OUString& rName ) const
85 SvI18NMapEntry_Impl *pRet = 0;
86 SvI18NMapEntry_Impl aTst( nKind, rName );
88 USHORT nPos;
89 if( pImpl->Seek_Entry( &aTst, &nPos ) )
91 pRet = (*pImpl)[nPos];
94 return pRet;
97 SvI18NMap::SvI18NMap() :
98 pImpl( 0 )
100 pImpl = new SvI18NMap_Impl;
103 SvI18NMap::~SvI18NMap()
105 delete pImpl;
108 void SvI18NMap::Add( USHORT nKind, const OUString& rName,
109 const OUString& rNewName )
111 SvI18NMapEntry_Impl *pEntry = _Find( nKind, rName );
112 DBG_ASSERT( !pEntry, "SvI18NMap::Add: item registered already" );
113 if( !pEntry )
115 pEntry = new SvI18NMapEntry_Impl( nKind, rName, rNewName );
116 pImpl->Insert( pEntry );
120 const OUString& SvI18NMap::Get( USHORT nKind, const OUString& rName ) const
122 SvI18NMapEntry_Impl *pEntry = _Find( nKind, rName );
123 if( pEntry )
124 return pEntry->GetNewName();
125 else
126 return rName;