xref: /AOO41X/main/tools/source/ref/globname.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_tools.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <ctype.h>
32*cdf0e10cSrcweir #include <stdio.h>
33*cdf0e10cSrcweir #include <string.h>
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include <tools/stream.hxx>
36*cdf0e10cSrcweir #include <tools/globname.hxx>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir /************** class ImpSvGlobalName ************************************/
39*cdf0e10cSrcweir ImpSvGlobalName::ImpSvGlobalName( const ImpSvGlobalName & rObj )
40*cdf0e10cSrcweir {
41*cdf0e10cSrcweir 	nRefCount = 0;
42*cdf0e10cSrcweir 	memcpy( szData, rObj.szData, sizeof( szData ) );
43*cdf0e10cSrcweir }
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir /************** class ImpSvGlobalName ************************************/
46*cdf0e10cSrcweir ImpSvGlobalName::ImpSvGlobalName( int )
47*cdf0e10cSrcweir {
48*cdf0e10cSrcweir 	nRefCount = 1;
49*cdf0e10cSrcweir 	memset( szData, 0, sizeof( szData ) );
50*cdf0e10cSrcweir }
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir /*************************************************************************
53*cdf0e10cSrcweir |*	  ImpSvGlobalName::operator ==()
54*cdf0e10cSrcweir *************************************************************************/
55*cdf0e10cSrcweir sal_Bool ImpSvGlobalName::operator == ( const ImpSvGlobalName & rObj ) const
56*cdf0e10cSrcweir {
57*cdf0e10cSrcweir 	return !memcmp( szData, rObj.szData, sizeof( szData ) );
58*cdf0e10cSrcweir }
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir /*************************************************************************
61*cdf0e10cSrcweir |*	  SvGlobalName::SvGlobalName()
62*cdf0e10cSrcweir *************************************************************************/
63*cdf0e10cSrcweir SvGlobalName::SvGlobalName()
64*cdf0e10cSrcweir {
65*cdf0e10cSrcweir 	static ImpSvGlobalName aNoName( 0 );
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir 	pImp = &aNoName;
68*cdf0e10cSrcweir 	pImp->nRefCount++;
69*cdf0e10cSrcweir }
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir // locker die Struktur von Windows kopiert
72*cdf0e10cSrcweir #ifdef WNT
73*cdf0e10cSrcweir struct _GUID
74*cdf0e10cSrcweir #else
75*cdf0e10cSrcweir struct GUID
76*cdf0e10cSrcweir #endif
77*cdf0e10cSrcweir {
78*cdf0e10cSrcweir 	sal_uInt32 Data1;
79*cdf0e10cSrcweir 	sal_uInt16 Data2;
80*cdf0e10cSrcweir 	sal_uInt16 Data3;
81*cdf0e10cSrcweir 	sal_uInt8  Data4[8];
82*cdf0e10cSrcweir };
83*cdf0e10cSrcweir SvGlobalName::SvGlobalName( const CLSID & rId )
84*cdf0e10cSrcweir {
85*cdf0e10cSrcweir 	pImp = new ImpSvGlobalName();
86*cdf0e10cSrcweir 	pImp->nRefCount++;
87*cdf0e10cSrcweir 	memcpy( pImp->szData, &rId, sizeof( pImp->szData ) );
88*cdf0e10cSrcweir }
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir SvGlobalName::SvGlobalName( sal_uInt32 n1, sal_uInt16 n2, sal_uInt16 n3,
91*cdf0e10cSrcweir 							sal_uInt8 b8, sal_uInt8 b9, sal_uInt8 b10, sal_uInt8 b11,
92*cdf0e10cSrcweir 							sal_uInt8 b12, sal_uInt8 b13, sal_uInt8 b14, sal_uInt8 b15 )
93*cdf0e10cSrcweir {
94*cdf0e10cSrcweir 	pImp = new ImpSvGlobalName();
95*cdf0e10cSrcweir 	pImp->nRefCount++;
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir 	*(sal_uInt32 *)pImp->szData 	  = n1;
98*cdf0e10cSrcweir 	*(sal_uInt16 *)&pImp->szData[ 4 ] = n2;
99*cdf0e10cSrcweir 	*(sal_uInt16 *)&pImp->szData[ 6 ] = n3;
100*cdf0e10cSrcweir 	pImp->szData[ 8  ] = b8;
101*cdf0e10cSrcweir 	pImp->szData[ 9  ] = b9;
102*cdf0e10cSrcweir 	pImp->szData[ 10 ] = b10;
103*cdf0e10cSrcweir 	pImp->szData[ 11 ] = b11;
104*cdf0e10cSrcweir 	pImp->szData[ 12 ] = b12;
105*cdf0e10cSrcweir 	pImp->szData[ 13 ] = b13;
106*cdf0e10cSrcweir 	pImp->szData[ 14 ] = b14;
107*cdf0e10cSrcweir 	pImp->szData[ 15 ] = b15;
108*cdf0e10cSrcweir }
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir /*************************************************************************
111*cdf0e10cSrcweir |*	  SvGlobalName::~SvGlobalName()
112*cdf0e10cSrcweir *************************************************************************/
113*cdf0e10cSrcweir SvGlobalName::~SvGlobalName()
114*cdf0e10cSrcweir {
115*cdf0e10cSrcweir 	pImp->nRefCount--;
116*cdf0e10cSrcweir 	if( !pImp->nRefCount )
117*cdf0e10cSrcweir 		delete pImp;
118*cdf0e10cSrcweir }
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir /*************************************************************************
121*cdf0e10cSrcweir |*	  SvGlobalName::operator = ()
122*cdf0e10cSrcweir *************************************************************************/
123*cdf0e10cSrcweir SvGlobalName & SvGlobalName::operator = ( const SvGlobalName & rObj )
124*cdf0e10cSrcweir {
125*cdf0e10cSrcweir 	rObj.pImp->nRefCount++;
126*cdf0e10cSrcweir 	pImp->nRefCount--;
127*cdf0e10cSrcweir 	if( !pImp->nRefCount )
128*cdf0e10cSrcweir 		delete pImp;
129*cdf0e10cSrcweir 	pImp = rObj.pImp;
130*cdf0e10cSrcweir 	return *this;
131*cdf0e10cSrcweir }
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir /*************************************************************************
134*cdf0e10cSrcweir |*	  SvGlobalName::NewImp()
135*cdf0e10cSrcweir *************************************************************************/
136*cdf0e10cSrcweir void SvGlobalName::NewImp()
137*cdf0e10cSrcweir {
138*cdf0e10cSrcweir 	if( pImp->nRefCount > 1 )
139*cdf0e10cSrcweir 	{
140*cdf0e10cSrcweir 		pImp->nRefCount--;
141*cdf0e10cSrcweir 		pImp = new ImpSvGlobalName( *pImp );
142*cdf0e10cSrcweir 		pImp->nRefCount++;
143*cdf0e10cSrcweir 	}
144*cdf0e10cSrcweir }
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir /*************************************************************************
147*cdf0e10cSrcweir |*	  SvGlobalName::operator << ()
148*cdf0e10cSrcweir |*	  SvGlobalName::operator >> ()
149*cdf0e10cSrcweir *************************************************************************/
150*cdf0e10cSrcweir SvStream& operator << ( SvStream& rOStr, const SvGlobalName & rObj )
151*cdf0e10cSrcweir {
152*cdf0e10cSrcweir 	rOStr << *(sal_uInt32 *)rObj.pImp->szData;
153*cdf0e10cSrcweir 	rOStr << *(sal_uInt16 *)&rObj.pImp->szData[ 4 ];
154*cdf0e10cSrcweir 	rOStr << *(sal_uInt16 *)&rObj.pImp->szData[ 6 ];
155*cdf0e10cSrcweir 	rOStr.Write( (sal_Char *)&rObj.pImp->szData[ 8 ], 8 );
156*cdf0e10cSrcweir 	return rOStr;
157*cdf0e10cSrcweir }
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir SvStream& operator >> ( SvStream& rStr, SvGlobalName & rObj )
160*cdf0e10cSrcweir {
161*cdf0e10cSrcweir 	rObj.NewImp(); // kopieren, falls noetig
162*cdf0e10cSrcweir 	rStr >> *(sal_uInt32 *)rObj.pImp->szData;
163*cdf0e10cSrcweir 	rStr >> *(sal_uInt16 *)&rObj.pImp->szData[ 4 ];
164*cdf0e10cSrcweir 	rStr >> *(sal_uInt16 *)&rObj.pImp->szData[ 6 ];
165*cdf0e10cSrcweir 	rStr.Read( (sal_Char *)&rObj.pImp->szData[ 8 ], 8 );
166*cdf0e10cSrcweir 	return rStr;
167*cdf0e10cSrcweir }
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir /*************************************************************************
171*cdf0e10cSrcweir |*	  SvGlobalName::operator < ()
172*cdf0e10cSrcweir *************************************************************************/
173*cdf0e10cSrcweir sal_Bool SvGlobalName::operator < ( const SvGlobalName & rObj ) const
174*cdf0e10cSrcweir {
175*cdf0e10cSrcweir 	int n = memcmp( pImp->szData +6, rObj.pImp->szData +6,
176*cdf0e10cSrcweir 					sizeof( pImp->szData ) -6);
177*cdf0e10cSrcweir 	if( n < 0 )
178*cdf0e10cSrcweir 		return sal_True;
179*cdf0e10cSrcweir 	else if( n > 0 )
180*cdf0e10cSrcweir 		return sal_False;
181*cdf0e10cSrcweir 	else if( *(sal_uInt16 *)&pImp->szData[ 4 ] < *(sal_uInt16 *)&rObj.pImp->szData[ 4 ] )
182*cdf0e10cSrcweir 		return sal_True;
183*cdf0e10cSrcweir 	else if( *(sal_uInt16 *)&pImp->szData[ 4 ] == *(sal_uInt16 *)&rObj.pImp->szData[ 4 ] )
184*cdf0e10cSrcweir 		return *(sal_uInt32 *)pImp->szData	< *(sal_uInt32 *)rObj.pImp->szData;
185*cdf0e10cSrcweir 	else
186*cdf0e10cSrcweir 		return sal_False;
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir }
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir /*************************************************************************
191*cdf0e10cSrcweir |*	  SvGlobalName::operator +=()
192*cdf0e10cSrcweir *************************************************************************/
193*cdf0e10cSrcweir SvGlobalName & SvGlobalName::operator += ( sal_uInt32 n )
194*cdf0e10cSrcweir {
195*cdf0e10cSrcweir 	NewImp();
196*cdf0e10cSrcweir 	sal_uInt32 nOld = (*(sal_uInt32 *)pImp->szData);
197*cdf0e10cSrcweir 	(*(sal_uInt32 *)pImp->szData) += n;
198*cdf0e10cSrcweir 	if( nOld > *(sal_uInt32 *)pImp->szData )
199*cdf0e10cSrcweir 		// ueberlauf
200*cdf0e10cSrcweir 		(*(sal_uInt16 *)&pImp->szData[ 4 ])++;
201*cdf0e10cSrcweir 	return *this;
202*cdf0e10cSrcweir }
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir /*************************************************************************
205*cdf0e10cSrcweir |*	  SvGlobalName::operator ==()
206*cdf0e10cSrcweir *************************************************************************/
207*cdf0e10cSrcweir sal_Bool SvGlobalName::operator == ( const SvGlobalName & rObj ) const
208*cdf0e10cSrcweir {
209*cdf0e10cSrcweir 	return *pImp == *rObj.pImp;
210*cdf0e10cSrcweir }
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir void SvGlobalName::MakeFromMemory( void * pData )
213*cdf0e10cSrcweir {
214*cdf0e10cSrcweir 	NewImp();
215*cdf0e10cSrcweir 	memcpy( pImp->szData, pData, sizeof( pImp->szData ) );
216*cdf0e10cSrcweir }
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir /*************************************************************************
219*cdf0e10cSrcweir |*	  SvGlobalName::MakeId()
220*cdf0e10cSrcweir *************************************************************************/
221*cdf0e10cSrcweir sal_Bool SvGlobalName::MakeId( const String & rIdStr )
222*cdf0e10cSrcweir {
223*cdf0e10cSrcweir 	ByteString	aStr( rIdStr, RTL_TEXTENCODING_ASCII_US );
224*cdf0e10cSrcweir 	sal_Char * pStr = (sal_Char *)aStr.GetBuffer();
225*cdf0e10cSrcweir 	if( rIdStr.Len() == 36
226*cdf0e10cSrcweir 	  && '-' == pStr[ 8 ]  && '-' == pStr[ 13 ]
227*cdf0e10cSrcweir 	  && '-' == pStr[ 18 ] && '-' == pStr[ 23 ] )
228*cdf0e10cSrcweir 	{
229*cdf0e10cSrcweir 		sal_uInt32 nFirst = 0;
230*cdf0e10cSrcweir 		int i = 0;
231*cdf0e10cSrcweir 		for( i = 0; i < 8; i++ )
232*cdf0e10cSrcweir 		{
233*cdf0e10cSrcweir 			if( isxdigit( *pStr ) )
234*cdf0e10cSrcweir 				if( isdigit( *pStr ) )
235*cdf0e10cSrcweir 					nFirst = nFirst * 16 + (*pStr - '0');
236*cdf0e10cSrcweir 				else
237*cdf0e10cSrcweir 					nFirst = nFirst * 16 + (toupper( *pStr ) - 'A' + 10 );
238*cdf0e10cSrcweir 			else
239*cdf0e10cSrcweir 				return sal_False;
240*cdf0e10cSrcweir 			pStr++;
241*cdf0e10cSrcweir 		}
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir 		sal_uInt16 nSec = 0;
244*cdf0e10cSrcweir 		pStr++;
245*cdf0e10cSrcweir 		for( i = 0; i < 4; i++ )
246*cdf0e10cSrcweir 		{
247*cdf0e10cSrcweir 			if( isxdigit( *pStr ) )
248*cdf0e10cSrcweir 				if( isdigit( *pStr ) )
249*cdf0e10cSrcweir 					nSec = nSec * 16 + (*pStr - '0');
250*cdf0e10cSrcweir 				else
251*cdf0e10cSrcweir 					nSec = nSec * 16 + (sal_uInt16)(toupper( *pStr ) - 'A' + 10 );
252*cdf0e10cSrcweir 			else
253*cdf0e10cSrcweir 				return sal_False;
254*cdf0e10cSrcweir 			pStr++;
255*cdf0e10cSrcweir 		}
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir 		sal_uInt16 nThird = 0;
258*cdf0e10cSrcweir 		pStr++;
259*cdf0e10cSrcweir 		for( i = 0; i < 4; i++ )
260*cdf0e10cSrcweir 		{
261*cdf0e10cSrcweir 			if( isxdigit( *pStr ) )
262*cdf0e10cSrcweir 				if( isdigit( *pStr ) )
263*cdf0e10cSrcweir 					nThird = nThird * 16 + (*pStr - '0');
264*cdf0e10cSrcweir 				else
265*cdf0e10cSrcweir 					nThird = nThird * 16 + (sal_uInt16)(toupper( *pStr ) - 'A' + 10 );
266*cdf0e10cSrcweir 			else
267*cdf0e10cSrcweir 				return sal_False;
268*cdf0e10cSrcweir 			pStr++;
269*cdf0e10cSrcweir 		}
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir 		sal_Int8 szRemain[ 8 ];
272*cdf0e10cSrcweir 		memset( szRemain, 0, sizeof( szRemain ) );
273*cdf0e10cSrcweir 		pStr++;
274*cdf0e10cSrcweir 		for( i = 0; i < 16; i++ )
275*cdf0e10cSrcweir 		{
276*cdf0e10cSrcweir 			if( isxdigit( *pStr ) )
277*cdf0e10cSrcweir 				if( isdigit( *pStr ) )
278*cdf0e10cSrcweir 					szRemain[i/2] = szRemain[i/2] * 16 + (*pStr - '0');
279*cdf0e10cSrcweir 				else
280*cdf0e10cSrcweir 					szRemain[i/2] = szRemain[i/2] * 16 + (sal_Int8)(toupper( *pStr ) - 'A' + 10 );
281*cdf0e10cSrcweir 			else
282*cdf0e10cSrcweir 				return sal_False;
283*cdf0e10cSrcweir 			pStr++;
284*cdf0e10cSrcweir 			if( i == 3 )
285*cdf0e10cSrcweir 				pStr++;
286*cdf0e10cSrcweir 		}
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir 		NewImp();
289*cdf0e10cSrcweir 		*(sal_uInt32 *)pImp->szData 	  = nFirst;
290*cdf0e10cSrcweir 		*(sal_uInt16 *)&pImp->szData[ 4 ] = nSec;
291*cdf0e10cSrcweir 		*(sal_uInt16 *)&pImp->szData[ 6 ] = nThird;
292*cdf0e10cSrcweir 		memcpy( &pImp->szData[ 8 ], szRemain, 8 );
293*cdf0e10cSrcweir 		return sal_True;
294*cdf0e10cSrcweir 	}
295*cdf0e10cSrcweir 	return sal_False;
296*cdf0e10cSrcweir }
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir /*************************************************************************
299*cdf0e10cSrcweir |*	  SvGlobalName::GetctorName()
300*cdf0e10cSrcweir *************************************************************************/
301*cdf0e10cSrcweir String SvGlobalName::GetctorName() const
302*cdf0e10cSrcweir {
303*cdf0e10cSrcweir 	ByteString aRet;
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir 	sal_Char buf[ 20 ];
306*cdf0e10cSrcweir 	sprintf( buf, "0x%8.8lX", (sal_uIntPtr)*(sal_uInt32 *)pImp->szData );
307*cdf0e10cSrcweir 	aRet += buf;
308*cdf0e10cSrcweir 	sal_uInt16 i;
309*cdf0e10cSrcweir 	for( i = 4; i < 8; i += 2 )
310*cdf0e10cSrcweir 	{
311*cdf0e10cSrcweir 		aRet += ',';
312*cdf0e10cSrcweir 		sprintf( buf, "0x%4.4X", *(sal_uInt16 *)&pImp->szData[ i ] );
313*cdf0e10cSrcweir 		aRet += buf;
314*cdf0e10cSrcweir 	}
315*cdf0e10cSrcweir 	for( i = 8; i < 16; i++ )
316*cdf0e10cSrcweir 	{
317*cdf0e10cSrcweir 		aRet += ',';
318*cdf0e10cSrcweir 		sprintf( buf, "0x%2.2x", pImp->szData[ i ] );
319*cdf0e10cSrcweir 		aRet += buf;
320*cdf0e10cSrcweir 	}
321*cdf0e10cSrcweir 	return String( aRet, RTL_TEXTENCODING_ASCII_US );
322*cdf0e10cSrcweir }
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir /*************************************************************************
325*cdf0e10cSrcweir |*	  SvGlobalName::GetHexName()
326*cdf0e10cSrcweir *************************************************************************/
327*cdf0e10cSrcweir String SvGlobalName::GetHexName() const
328*cdf0e10cSrcweir {
329*cdf0e10cSrcweir 	ByteString aRet;
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir 	sal_Char buf[ 10 ];
332*cdf0e10cSrcweir 	sprintf( buf, "%8.8lX", (sal_uIntPtr)*(sal_uInt32 *)pImp->szData );
333*cdf0e10cSrcweir 	aRet += buf;
334*cdf0e10cSrcweir 	aRet += '-';
335*cdf0e10cSrcweir 	sal_uInt16 i ;
336*cdf0e10cSrcweir 	for( i = 4; i < 8; i += 2 )
337*cdf0e10cSrcweir 	{
338*cdf0e10cSrcweir 		sprintf( buf, "%4.4X", *(sal_uInt16 *)&pImp->szData[ i ] );
339*cdf0e10cSrcweir 		aRet += buf;
340*cdf0e10cSrcweir 		aRet += '-';
341*cdf0e10cSrcweir 	}
342*cdf0e10cSrcweir 	for( i = 8; i < 10; i++ )
343*cdf0e10cSrcweir 	{
344*cdf0e10cSrcweir 		sprintf( buf, "%2.2x", pImp->szData[ i ] );
345*cdf0e10cSrcweir 		aRet += buf;
346*cdf0e10cSrcweir 	}
347*cdf0e10cSrcweir 	aRet += '-';
348*cdf0e10cSrcweir 	for( i = 10; i < 16; i++ )
349*cdf0e10cSrcweir 	{
350*cdf0e10cSrcweir 		sprintf( buf, "%2.2x", pImp->szData[ i ] );
351*cdf0e10cSrcweir 		aRet += buf;
352*cdf0e10cSrcweir 	}
353*cdf0e10cSrcweir 	return String( aRet, RTL_TEXTENCODING_ASCII_US );
354*cdf0e10cSrcweir }
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir /************** SvGlobalNameList ****************************************/
357*cdf0e10cSrcweir /************************************************************************/
358*cdf0e10cSrcweir /*************************************************************************
359*cdf0e10cSrcweir |*	  SvGlobalNameList::SvGlobalNameList()
360*cdf0e10cSrcweir *************************************************************************/
361*cdf0e10cSrcweir SvGlobalNameList::SvGlobalNameList()
362*cdf0e10cSrcweir 	: aList( 1, 1 )
363*cdf0e10cSrcweir {
364*cdf0e10cSrcweir }
365*cdf0e10cSrcweir 
366*cdf0e10cSrcweir /*************************************************************************
367*cdf0e10cSrcweir |*	  SvGlobalNameList::~SvGlobalNameList()
368*cdf0e10cSrcweir *************************************************************************/
369*cdf0e10cSrcweir SvGlobalNameList::~SvGlobalNameList()
370*cdf0e10cSrcweir {
371*cdf0e10cSrcweir 	for( sal_uIntPtr i = Count(); i > 0; i-- )
372*cdf0e10cSrcweir 	{
373*cdf0e10cSrcweir 		ImpSvGlobalName * pImp = (ImpSvGlobalName *)aList.GetObject( i -1 );
374*cdf0e10cSrcweir 		pImp->nRefCount--;
375*cdf0e10cSrcweir 		if( !pImp->nRefCount )
376*cdf0e10cSrcweir 			delete pImp;
377*cdf0e10cSrcweir 	}
378*cdf0e10cSrcweir }
379*cdf0e10cSrcweir 
380*cdf0e10cSrcweir /*************************************************************************
381*cdf0e10cSrcweir |*	  SvGlobalNameList::Append()
382*cdf0e10cSrcweir *************************************************************************/
383*cdf0e10cSrcweir void SvGlobalNameList::Append( const SvGlobalName & rName )
384*cdf0e10cSrcweir {
385*cdf0e10cSrcweir 	rName.pImp->nRefCount++;
386*cdf0e10cSrcweir 	aList.Insert( rName.pImp, LIST_APPEND );
387*cdf0e10cSrcweir }
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir /*************************************************************************
390*cdf0e10cSrcweir |*	  SvGlobalNameList::GetObject()
391*cdf0e10cSrcweir *************************************************************************/
392*cdf0e10cSrcweir SvGlobalName SvGlobalNameList::GetObject( sal_uLong nPos )
393*cdf0e10cSrcweir {
394*cdf0e10cSrcweir 	return SvGlobalName( (ImpSvGlobalName *)aList.GetObject( nPos ) );
395*cdf0e10cSrcweir }
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir /*************************************************************************
398*cdf0e10cSrcweir |*	  SvGlobalNameList::IsEntry()
399*cdf0e10cSrcweir *************************************************************************/
400*cdf0e10cSrcweir sal_Bool SvGlobalNameList::IsEntry( const SvGlobalName & rName )
401*cdf0e10cSrcweir {
402*cdf0e10cSrcweir 	for( sal_uIntPtr i = Count(); i > 0; i-- )
403*cdf0e10cSrcweir 	{
404*cdf0e10cSrcweir 		if( *rName.pImp == *(ImpSvGlobalName *)aList.GetObject( i -1 ) )
405*cdf0e10cSrcweir 			return sal_True;
406*cdf0e10cSrcweir 	}
407*cdf0e10cSrcweir 	return sal_False;
408*cdf0e10cSrcweir }
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir com::sun::star::uno::Sequence < sal_Int8 > SvGlobalName::GetByteSequence() const
411*cdf0e10cSrcweir {
412*cdf0e10cSrcweir     // platform independent representation of a "GlobalName"
413*cdf0e10cSrcweir     // maybe transported remotely
414*cdf0e10cSrcweir     com::sun::star::uno::Sequence< sal_Int8 > aResult( 16 );
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir     aResult[0] = (sal_Int8) (*(sal_uInt32 *)pImp->szData >> 24);
417*cdf0e10cSrcweir     aResult[1] = (sal_Int8) ((*(sal_uInt32 *)pImp->szData << 8 ) >> 24);
418*cdf0e10cSrcweir     aResult[2] = (sal_Int8) ((*(sal_uInt32 *)pImp->szData << 16 ) >> 24);
419*cdf0e10cSrcweir     aResult[3] = (sal_Int8) ((*(sal_uInt32 *)pImp->szData << 24 ) >> 24);
420*cdf0e10cSrcweir     aResult[4] = (sal_Int8) (*(sal_uInt16 *)&pImp->szData[ 4 ] >> 8);
421*cdf0e10cSrcweir     aResult[5] = (sal_Int8) ((*(sal_uInt16 *)&pImp->szData[ 4 ] << 8 ) >> 8);
422*cdf0e10cSrcweir     aResult[6] = (sal_Int8) (*(sal_uInt16 *)&pImp->szData[ 6 ] >> 8);
423*cdf0e10cSrcweir     aResult[7] = (sal_Int8) ((*(sal_uInt16 *)&pImp->szData[ 6 ] << 8 ) >> 8);
424*cdf0e10cSrcweir     aResult[8] = pImp->szData[ 8 ];
425*cdf0e10cSrcweir     aResult[9] = pImp->szData[ 9 ];
426*cdf0e10cSrcweir     aResult[10] = pImp->szData[ 10 ];
427*cdf0e10cSrcweir     aResult[11] = pImp->szData[ 11 ];
428*cdf0e10cSrcweir     aResult[12] = pImp->szData[ 12 ];
429*cdf0e10cSrcweir     aResult[13] = pImp->szData[ 13 ];
430*cdf0e10cSrcweir     aResult[14] = pImp->szData[ 14 ];
431*cdf0e10cSrcweir     aResult[15] = pImp->szData[ 15 ];
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir     return aResult;
434*cdf0e10cSrcweir }
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir SvGlobalName::SvGlobalName( const com::sun::star::uno::Sequence < sal_Int8 >& aSeq )
437*cdf0e10cSrcweir {
438*cdf0e10cSrcweir     // create SvGlobalName from a platform independent representation
439*cdf0e10cSrcweir     GUID aResult;
440*cdf0e10cSrcweir     memset( &aResult, 0, sizeof( aResult ) );
441*cdf0e10cSrcweir 	if ( aSeq.getLength() == 16 )
442*cdf0e10cSrcweir 	{
443*cdf0e10cSrcweir 		aResult.Data1 = ( ( ( ( ( ( sal_uInt8 )aSeq[0] << 8 ) + ( sal_uInt8 )aSeq[1] ) << 8 ) + ( sal_uInt8 )aSeq[2] ) << 8 ) + ( sal_uInt8 )aSeq[3];
444*cdf0e10cSrcweir 		aResult.Data2 = ( ( sal_uInt8 )aSeq[4] << 8 ) + ( sal_uInt8 )aSeq[5];
445*cdf0e10cSrcweir 		aResult.Data3 = ( ( sal_uInt8 )aSeq[6] << 8 ) + ( sal_uInt8 )aSeq[7];
446*cdf0e10cSrcweir 		for( int nInd = 0; nInd < 8; nInd++ )
447*cdf0e10cSrcweir 			aResult.Data4[nInd] = ( sal_uInt8 )aSeq[nInd+8];
448*cdf0e10cSrcweir     }
449*cdf0e10cSrcweir 
450*cdf0e10cSrcweir 	pImp = new ImpSvGlobalName();
451*cdf0e10cSrcweir 	pImp->nRefCount++;
452*cdf0e10cSrcweir     memcpy( pImp->szData, &aResult, sizeof( pImp->szData ) );
453*cdf0e10cSrcweir }
454