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: globname.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_tools.hxx"
38 #include <tools/stream.hxx>
39 #include <tools/globname.hxx>
41 /************** class ImpSvGlobalName ************************************/
42 ImpSvGlobalName::ImpSvGlobalName( const ImpSvGlobalName
& rObj
)
45 memcpy( szData
, rObj
.szData
, sizeof( szData
) );
48 /************** class ImpSvGlobalName ************************************/
49 ImpSvGlobalName::ImpSvGlobalName( int )
52 memset( szData
, 0, sizeof( szData
) );
55 /*************************************************************************
56 |* ImpSvGlobalName::operator ==()
57 *************************************************************************/
58 BOOL
ImpSvGlobalName::operator == ( const ImpSvGlobalName
& rObj
) const
60 return !memcmp( szData
, rObj
.szData
, sizeof( szData
) );
63 /*************************************************************************
64 |* SvGlobalName::SvGlobalName()
65 *************************************************************************/
66 SvGlobalName::SvGlobalName()
68 static ImpSvGlobalName
aNoName( 0 );
74 // locker die Struktur von Windows kopiert
86 SvGlobalName::SvGlobalName( const CLSID
& rId
)
88 pImp
= new ImpSvGlobalName();
90 memcpy( pImp
->szData
, &rId
, sizeof( pImp
->szData
) );
93 SvGlobalName::SvGlobalName( UINT32 n1
, USHORT n2
, USHORT n3
,
94 BYTE b8
, BYTE b9
, BYTE b10
, BYTE b11
,
95 BYTE b12
, BYTE b13
, BYTE b14
, BYTE b15
)
97 pImp
= new ImpSvGlobalName();
100 *(UINT32
*)pImp
->szData
= n1
;
101 *(USHORT
*)&pImp
->szData
[ 4 ] = n2
;
102 *(USHORT
*)&pImp
->szData
[ 6 ] = n3
;
103 pImp
->szData
[ 8 ] = b8
;
104 pImp
->szData
[ 9 ] = b9
;
105 pImp
->szData
[ 10 ] = b10
;
106 pImp
->szData
[ 11 ] = b11
;
107 pImp
->szData
[ 12 ] = b12
;
108 pImp
->szData
[ 13 ] = b13
;
109 pImp
->szData
[ 14 ] = b14
;
110 pImp
->szData
[ 15 ] = b15
;
113 /*************************************************************************
114 |* SvGlobalName::~SvGlobalName()
115 *************************************************************************/
116 SvGlobalName::~SvGlobalName()
119 if( !pImp
->nRefCount
)
123 /*************************************************************************
124 |* SvGlobalName::operator = ()
125 *************************************************************************/
126 SvGlobalName
& SvGlobalName::operator = ( const SvGlobalName
& rObj
)
128 rObj
.pImp
->nRefCount
++;
130 if( !pImp
->nRefCount
)
136 /*************************************************************************
137 |* SvGlobalName::NewImp()
138 *************************************************************************/
139 void SvGlobalName::NewImp()
141 if( pImp
->nRefCount
> 1 )
144 pImp
= new ImpSvGlobalName( *pImp
);
149 /*************************************************************************
150 |* SvGlobalName::operator << ()
151 |* SvGlobalName::operator >> ()
152 *************************************************************************/
153 SvStream
& operator << ( SvStream
& rOStr
, const SvGlobalName
& rObj
)
155 rOStr
<< *(UINT32
*)rObj
.pImp
->szData
;
156 rOStr
<< *(USHORT
*)&rObj
.pImp
->szData
[ 4 ];
157 rOStr
<< *(USHORT
*)&rObj
.pImp
->szData
[ 6 ];
158 rOStr
.Write( (sal_Char
*)&rObj
.pImp
->szData
[ 8 ], 8 );
162 SvStream
& operator >> ( SvStream
& rStr
, SvGlobalName
& rObj
)
164 rObj
.NewImp(); // kopieren, falls noetig
165 rStr
>> *(UINT32
*)rObj
.pImp
->szData
;
166 rStr
>> *(USHORT
*)&rObj
.pImp
->szData
[ 4 ];
167 rStr
>> *(USHORT
*)&rObj
.pImp
->szData
[ 6 ];
168 rStr
.Read( (sal_Char
*)&rObj
.pImp
->szData
[ 8 ], 8 );
173 /*************************************************************************
174 |* SvGlobalName::operator < ()
175 *************************************************************************/
176 BOOL
SvGlobalName::operator < ( const SvGlobalName
& rObj
) const
178 int n
= memcmp( pImp
->szData
+6, rObj
.pImp
->szData
+6,
179 sizeof( pImp
->szData
) -6);
184 else if( *(USHORT
*)&pImp
->szData
[ 4 ] < *(USHORT
*)&rObj
.pImp
->szData
[ 4 ] )
186 else if( *(USHORT
*)&pImp
->szData
[ 4 ] == *(USHORT
*)&rObj
.pImp
->szData
[ 4 ] )
187 return *(UINT32
*)pImp
->szData
< *(UINT32
*)rObj
.pImp
->szData
;
193 /*************************************************************************
194 |* SvGlobalName::operator +=()
195 *************************************************************************/
196 SvGlobalName
& SvGlobalName::operator += ( UINT32 n
)
199 UINT32 nOld
= (*(UINT32
*)pImp
->szData
);
200 (*(UINT32
*)pImp
->szData
) += n
;
201 if( nOld
> *(UINT32
*)pImp
->szData
)
203 (*(USHORT
*)&pImp
->szData
[ 4 ])++;
207 /*************************************************************************
208 |* SvGlobalName::operator ==()
209 *************************************************************************/
210 BOOL
SvGlobalName::operator == ( const SvGlobalName
& rObj
) const
212 return *pImp
== *rObj
.pImp
;
215 void SvGlobalName::MakeFromMemory( void * pData
)
218 memcpy( pImp
->szData
, pData
, sizeof( pImp
->szData
) );
221 /*************************************************************************
222 |* SvGlobalName::MakeId()
223 *************************************************************************/
224 BOOL
SvGlobalName::MakeId( const String
& rIdStr
)
226 ByteString
aStr( rIdStr
, RTL_TEXTENCODING_ASCII_US
);
227 sal_Char
* pStr
= (sal_Char
*)aStr
.GetBuffer();
228 if( rIdStr
.Len() == 36
229 && '-' == pStr
[ 8 ] && '-' == pStr
[ 13 ]
230 && '-' == pStr
[ 18 ] && '-' == pStr
[ 23 ] )
234 for( i
= 0; i
< 8; i
++ )
236 if( isxdigit( *pStr
) )
237 if( isdigit( *pStr
) )
238 nFirst
= nFirst
* 16 + (*pStr
- '0');
240 nFirst
= nFirst
* 16 + (toupper( *pStr
) - 'A' + 10 );
248 for( i
= 0; i
< 4; i
++ )
250 if( isxdigit( *pStr
) )
251 if( isdigit( *pStr
) )
252 nSec
= nSec
* 16 + (*pStr
- '0');
254 nSec
= nSec
* 16 + (UINT16
)(toupper( *pStr
) - 'A' + 10 );
262 for( i
= 0; i
< 4; i
++ )
264 if( isxdigit( *pStr
) )
265 if( isdigit( *pStr
) )
266 nThird
= nThird
* 16 + (*pStr
- '0');
268 nThird
= nThird
* 16 + (UINT16
)(toupper( *pStr
) - 'A' + 10 );
275 memset( szRemain
, 0, sizeof( szRemain
) );
277 for( i
= 0; i
< 16; i
++ )
279 if( isxdigit( *pStr
) )
280 if( isdigit( *pStr
) )
281 szRemain
[i
/2] = szRemain
[i
/2] * 16 + (*pStr
- '0');
283 szRemain
[i
/2] = szRemain
[i
/2] * 16 + (BYTE
)(toupper( *pStr
) - 'A' + 10 );
292 *(UINT32
*)pImp
->szData
= nFirst
;
293 *(USHORT
*)&pImp
->szData
[ 4 ] = nSec
;
294 *(USHORT
*)&pImp
->szData
[ 6 ] = nThird
;
295 memcpy( &pImp
->szData
[ 8 ], szRemain
, 8 );
301 /*************************************************************************
302 |* SvGlobalName::GetctorName()
303 *************************************************************************/
304 String
SvGlobalName::GetctorName() const
309 sprintf( buf
, "0x%8.8lX", (ULONG
)*(UINT32
*)pImp
->szData
);
312 for( i
= 4; i
< 8; i
+= 2 )
315 sprintf( buf
, "0x%4.4X", *(USHORT
*)&pImp
->szData
[ i
] );
318 for( i
= 8; i
< 16; i
++ )
321 sprintf( buf
, "0x%2.2x", pImp
->szData
[ i
] );
324 return String( aRet
, RTL_TEXTENCODING_ASCII_US
);
327 /*************************************************************************
328 |* SvGlobalName::GetHexName()
329 *************************************************************************/
330 String
SvGlobalName::GetHexName() const
335 sprintf( buf
, "%8.8lX", (ULONG
)*(UINT32
*)pImp
->szData
);
339 for( i
= 4; i
< 8; i
+= 2 )
341 sprintf( buf
, "%4.4X", *(USHORT
*)&pImp
->szData
[ i
] );
345 for( i
= 8; i
< 10; i
++ )
347 sprintf( buf
, "%2.2x", pImp
->szData
[ i
] );
351 for( i
= 10; i
< 16; i
++ )
353 sprintf( buf
, "%2.2x", pImp
->szData
[ i
] );
356 return String( aRet
, RTL_TEXTENCODING_ASCII_US
);
359 /************** SvGlobalNameList ****************************************/
360 /************************************************************************/
361 /*************************************************************************
362 |* SvGlobalNameList::SvGlobalNameList()
363 *************************************************************************/
364 SvGlobalNameList::SvGlobalNameList()
369 /*************************************************************************
370 |* SvGlobalNameList::~SvGlobalNameList()
371 *************************************************************************/
372 SvGlobalNameList::~SvGlobalNameList()
374 for( ULONG i
= Count(); i
> 0; i
-- )
376 ImpSvGlobalName
* pImp
= (ImpSvGlobalName
*)aList
.GetObject( i
-1 );
378 if( !pImp
->nRefCount
)
383 /*************************************************************************
384 |* SvGlobalNameList::Append()
385 *************************************************************************/
386 void SvGlobalNameList::Append( const SvGlobalName
& rName
)
388 rName
.pImp
->nRefCount
++;
389 aList
.Insert( rName
.pImp
, LIST_APPEND
);
392 /*************************************************************************
393 |* SvGlobalNameList::GetObject()
394 *************************************************************************/
395 SvGlobalName
SvGlobalNameList::GetObject( ULONG nPos
)
397 return SvGlobalName( (ImpSvGlobalName
*)aList
.GetObject( nPos
) );
400 /*************************************************************************
401 |* SvGlobalNameList::IsEntry()
402 *************************************************************************/
403 BOOL
SvGlobalNameList::IsEntry( const SvGlobalName
& rName
)
405 for( ULONG i
= Count(); i
> 0; i
-- )
407 if( *rName
.pImp
== *(ImpSvGlobalName
*)aList
.GetObject( i
-1 ) )
413 com::sun::star::uno::Sequence
< sal_Int8
> SvGlobalName::GetByteSequence() const
415 // platform independent representation of a "GlobalName"
416 // maybe transported remotely
417 com::sun::star::uno::Sequence
< sal_Int8
> aResult( 16 );
419 aResult
[0] = (sal_Int8
) (*(UINT32
*)pImp
->szData
>> 24);
420 aResult
[1] = (sal_Int8
) ((*(UINT32
*)pImp
->szData
<< 8 ) >> 24);
421 aResult
[2] = (sal_Int8
) ((*(UINT32
*)pImp
->szData
<< 16 ) >> 24);
422 aResult
[3] = (sal_Int8
) ((*(UINT32
*)pImp
->szData
<< 24 ) >> 24);
423 aResult
[4] = (sal_Int8
) (*(USHORT
*)&pImp
->szData
[ 4 ] >> 8);
424 aResult
[5] = (sal_Int8
) ((*(USHORT
*)&pImp
->szData
[ 4 ] << 8 ) >> 8);
425 aResult
[6] = (sal_Int8
) (*(USHORT
*)&pImp
->szData
[ 6 ] >> 8);
426 aResult
[7] = (sal_Int8
) ((*(USHORT
*)&pImp
->szData
[ 6 ] << 8 ) >> 8);
427 aResult
[8] = pImp
->szData
[ 8 ];
428 aResult
[9] = pImp
->szData
[ 9 ];
429 aResult
[10] = pImp
->szData
[ 10 ];
430 aResult
[11] = pImp
->szData
[ 11 ];
431 aResult
[12] = pImp
->szData
[ 12 ];
432 aResult
[13] = pImp
->szData
[ 13 ];
433 aResult
[14] = pImp
->szData
[ 14 ];
434 aResult
[15] = pImp
->szData
[ 15 ];
439 SvGlobalName::SvGlobalName( const com::sun::star::uno::Sequence
< sal_Int8
>& aSeq
)
441 // create SvGlobalName from a platform independent representation
443 memset( &aResult
, 0, sizeof( aResult
) );
444 if ( aSeq
.getLength() == 16 )
446 aResult
.Data1
= ( ( ( ( ( ( sal_uInt8
)aSeq
[0] << 8 ) + ( sal_uInt8
)aSeq
[1] ) << 8 ) + ( sal_uInt8
)aSeq
[2] ) << 8 ) + ( sal_uInt8
)aSeq
[3];
447 aResult
.Data2
= ( ( sal_uInt8
)aSeq
[4] << 8 ) + ( sal_uInt8
)aSeq
[5];
448 aResult
.Data3
= ( ( sal_uInt8
)aSeq
[6] << 8 ) + ( sal_uInt8
)aSeq
[7];
449 for( int nInd
= 0; nInd
< 8; nInd
++ )
450 aResult
.Data4
[nInd
] = ( sal_uInt8
)aSeq
[nInd
+8];
453 pImp
= new ImpSvGlobalName();
455 memcpy( pImp
->szData
, &aResult
, sizeof( pImp
->szData
) );