xref: /trunk/main/xmloff/source/core/i18nmap.cxx (revision 63bba73c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 #include <rtl/ustring.hxx>
27 #include <tools/debug.hxx>
28 #include <svl/svarray.hxx>
29 #include "xmloff/i18nmap.hxx"
30 
31 using namespace rtl;
32 
33 class SvI18NMapEntry_Impl
34 {
35 	sal_uInt16			nKind;
36 	OUString		aName;
37 	OUString		aNewName;
38 
39 public:
40 
GetNewName() const41 	const OUString& GetNewName() const { return aNewName; }
42 
SvI18NMapEntry_Impl(sal_uInt16 nKnd,const OUString & rName,const OUString & rNewName)43 	SvI18NMapEntry_Impl( sal_uInt16 nKnd, const OUString& rName,
44 						 const OUString& rNewName ) :
45 		nKind( nKnd ),
46 		aName( rName ),
47 		aNewName( rNewName )
48 	{}
49 
SvI18NMapEntry_Impl(sal_uInt16 nKnd,const OUString & rName)50 	SvI18NMapEntry_Impl( sal_uInt16 nKnd, const OUString& rName ) :
51 		nKind( nKnd ),
52 		aName( rName )
53 	{}
54 
operator ==(const SvI18NMapEntry_Impl & r) const55 	sal_Bool operator==( const SvI18NMapEntry_Impl& r ) const
56 	{
57 		return nKind == r.nKind &&
58 			   aName == r.aName;
59 	}
60 
operator <(const SvI18NMapEntry_Impl & r) const61 	sal_Bool operator<( const SvI18NMapEntry_Impl& r ) const
62 	{
63 		return nKind < r.nKind ||
64 			   ( nKind == r.nKind &&
65 				 aName < r.aName);
66 	}
67 };
68 
69 typedef SvI18NMapEntry_Impl *SvI18NMapEntry_ImplPtr;
70 SV_DECL_PTRARR_SORT_DEL( SvI18NMap_Impl, SvI18NMapEntry_ImplPtr, 20, 5 )
SV_IMPL_OP_PTRARR_SORT(SvI18NMap_Impl,SvI18NMapEntry_ImplPtr)71 SV_IMPL_OP_PTRARR_SORT( SvI18NMap_Impl, SvI18NMapEntry_ImplPtr )
72 
73 // ---------------------------------------------------------------------
74 
75 SvI18NMapEntry_Impl *SvI18NMap::_Find( sal_uInt16 nKind,
76 									 const OUString& rName ) const
77 {
78 	SvI18NMapEntry_Impl *pRet = 0;
79 	SvI18NMapEntry_Impl aTst( nKind, rName );
80 
81 	sal_uInt16 nPos;
82 	if( pImpl->Seek_Entry( &aTst, &nPos ) )
83 	{
84 		pRet = (*pImpl)[nPos];
85 	}
86 
87 	return pRet;
88 }
89 
SvI18NMap()90 SvI18NMap::SvI18NMap() :
91 	pImpl( 0 )
92 {
93 	pImpl = new SvI18NMap_Impl;
94 }
95 
~SvI18NMap()96 SvI18NMap::~SvI18NMap()
97 {
98 	delete pImpl;
99 }
100 
Add(sal_uInt16 nKind,const OUString & rName,const OUString & rNewName)101 void SvI18NMap::Add( sal_uInt16 nKind, const OUString& rName,
102 					 const OUString& rNewName )
103 {
104 	SvI18NMapEntry_Impl *pEntry = _Find( nKind, rName );
105 	DBG_ASSERT( !pEntry, "SvI18NMap::Add: item registered already" );
106 	if( !pEntry )
107 	{
108 		pEntry = new SvI18NMapEntry_Impl( nKind, rName, rNewName );
109 		pImpl->Insert( pEntry );
110 	}
111 }
112 
Get(sal_uInt16 nKind,const OUString & rName) const113 const OUString& SvI18NMap::Get( sal_uInt16 nKind, const OUString& rName ) const
114 {
115 	SvI18NMapEntry_Impl *pEntry = _Find( nKind, rName );
116 	if( pEntry )
117 		return pEntry->GetNewName();
118 	else
119 		return rName;
120 }
121 
122 
123