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: bastype.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_idl.hxx"
34 #include <tools/debug.hxx>
38 #include <bastype.hxx>
40 #include <globals.hxx>
42 #include <database.hxx>
45 /************************************************************************/
46 static BOOL
ReadRangeSvIdl( SvStringHashEntry
* pName
, SvTokenStream
& rInStm
,
47 ULONG nMin
, ULONG nMax
, ULONG
* pValue
)
49 UINT32 nTokPos
= rInStm
.Tell();
50 SvToken
* pTok
= rInStm
.GetToken_Next();
51 if( pTok
->Is( pName
) )
54 if( rInStm
.Read( '=' ) )
56 pTok
= rInStm
.GetToken_Next();
57 if( pTok
->IsInteger() )
59 ULONG n
= pTok
->GetNumber();
60 if ( n
>= nMin
&& n
<= nMax
)
72 rInStm
.Seek( nTokPos
);
77 /*************************************************************************
83 |* Ersterstellung MM 12.12.94
84 |* Letzte Aenderung MM 12.12.94
86 *************************************************************************/
87 UINT32
SvUINT32::Read( SvStream
& rStm
)
89 return SvPersistStream::ReadCompressed( rStm
);
92 void SvUINT32::Write( SvStream
& rStm
, UINT32 nVal
)
94 SvPersistStream::WriteCompressed( rStm
, nVal
);
97 /*************************************************************************
99 |* SvStream& operator << ( SvBOOL )
100 |* SvStream& operator >> ( SvBOOL )
103 |* Ersterstellung MM 12.12.94
104 |* Letzte Aenderung MM 12.12.94
106 *************************************************************************/
107 SvStream
& operator << (SvStream
& rStm
, const SvBOOL
& rb
)
115 SvStream
& operator >> (SvStream
& rStm
, SvBOOL
& rb
)
119 rb
.nVal
= (n
& 0x01) ? TRUE
: FALSE
;
120 rb
.bSet
= (n
& 0x02) ? TRUE
: FALSE
;
123 rStm
.SetError( SVSTREAM_FILEFORMAT_ERROR
);
124 DBG_ERROR( "format error" );
129 /*************************************************************************
131 |* SvStream& operator << ( SvVersion )
132 |* SvStream& operator >> ( SvVersion )
135 |* Ersterstellung MM 12.12.94
136 |* Letzte Aenderung MM 12.12.94
138 *************************************************************************/
139 SvStream
& operator << (SvStream
& rStm
, const SvVersion
& r
)
141 if( (r
.GetMajorVersion() || r
.GetMinorVersion())
142 && r
.GetMajorVersion() <= 0x0F && r
.GetMinorVersion() <= 0x0F )
143 { // Versionsnummer in 1 Byte komprimieren
144 // Format 4 Bit fuer Major, dann 4 Bit fuer Minor.
145 // 0.0 wird nicht komprimiert
147 int n
= r
.GetMajorVersion() << 4;
148 n
|= r
.GetMinorVersion();
154 rStm
<< r
.GetMajorVersion();
155 rStm
<< r
.GetMinorVersion();
160 SvStream
& operator >> (SvStream
& rStm
, SvVersion
& r
)
165 { // nicht komprimiert
166 rStm
>> r
.nMajorVersion
;
167 rStm
>> r
.nMinorVersion
;
171 r
.nMajorVersion
= (n
>> 4) & 0x0F;
172 r
.nMinorVersion
= n
& 0x0F;
179 /************************************************************************/
181 /*************************************************************************
183 |* SvBOOL::ReadSvIdl()
186 |* Ersterstellung MM 12.12.94
187 |* Letzte Aenderung MM 12.12.94
189 *************************************************************************/
190 BOOL
SvBOOL::ReadSvIdl( SvStringHashEntry
* pName
, SvTokenStream
& rInStm
)
192 UINT32 nTokPos
= rInStm
.Tell();
193 SvToken
* pTok
= rInStm
.GetToken_Next();
195 if( pTok
->Is( pName
) )
198 BOOL bBraket
= rInStm
.Read( '(' );
199 if( bBraket
|| rInStm
.Read( '=' ) )
201 pTok
= rInStm
.GetToken();
204 *this = pTok
->GetBool();
206 rInStm
.GetToken_Next();
209 bOk
= rInStm
.Read( ')' );
212 *this = TRUE
; //Defaultaktion ist auf TRUE setzen
216 rInStm
.Seek( nTokPos
);
220 /*************************************************************************
222 |* SvBOOL::WriteSvIdl()
226 *************************************************************************/
227 BOOL
SvBOOL::WriteSvIdl( SvStringHashEntry
* pName
, SvStream
& rOutStm
)
230 rOutStm
<< pName
->GetName().GetBuffer();
232 rOutStm
<< pName
->GetName().GetBuffer() << "(FALSE)";
236 /*************************************************************************
238 |* SvBOOL::WriteSvIdl()
242 *************************************************************************/
243 ByteString
SvBOOL::GetSvIdlString( SvStringHashEntry
* pName
)
246 return pName
->GetName();
249 ByteString
aTmp( pName
->GetName() );
256 /************************************************************************/
257 /*************************************************************************
259 |* SvIdentifier::ReadSvIdl()
263 *************************************************************************/
264 BOOL
SvIdentifier::ReadSvIdl( SvStringHashEntry
* pName
, SvTokenStream
& rInStm
)
266 UINT32 nTokPos
= rInStm
.Tell();
267 SvToken
* pTok
= rInStm
.GetToken_Next();
269 if( pTok
->Is( pName
) )
272 BOOL bBraket
= rInStm
.Read( '(' );
273 if( bBraket
|| rInStm
.Read( '=' ) )
275 pTok
= rInStm
.GetToken();
276 if( pTok
->IsIdentifier() )
278 *(ByteString
*)this = pTok
->GetString();
279 rInStm
.GetToken_Next();
282 bOk
= rInStm
.Read( ')' );
287 rInStm
.Seek( nTokPos
);
291 /*************************************************************************
293 |* SvIdentifier::WriteSvIdl()
297 *************************************************************************/
298 BOOL
SvIdentifier::WriteSvIdl( SvStringHashEntry
* pName
,
302 rOutStm
<< pName
->GetName().GetBuffer() << '(';
303 rOutStm
<< GetBuffer() << ')';
307 SvStream
& operator << (SvStream
& rStm
, const SvIdentifier
& r
)
309 rStm
.WriteByteString( r
);
313 SvStream
& operator >> (SvStream
& rStm
, SvIdentifier
& r
)
315 rStm
.ReadByteString( r
);
320 /************************************************************************/
321 /*************************************************************************
323 |* SvNumberIdentifier::ReadSvIdl()
327 *************************************************************************/
328 BOOL
SvNumberIdentifier::ReadSvIdl( SvIdlDataBase
& rBase
,
329 SvStringHashEntry
* pName
,
330 SvTokenStream
& rInStm
)
332 if( SvIdentifier::ReadSvIdl( pName
, rInStm
) )
335 if( rBase
.FindId( *this, &n
) )
342 ByteString
aStr ("no value for identifier <");
345 rBase
.SetError( aStr
, rInStm
.GetToken() );
346 rBase
.WriteError( rInStm
);
352 /*************************************************************************
354 |* SvNumberIdentifier::ReadSvIdl()
358 *************************************************************************/
359 BOOL
SvNumberIdentifier::ReadSvIdl( SvIdlDataBase
& rBase
,
360 SvTokenStream
& rInStm
)
362 UINT32 nTokPos
= rInStm
.Tell();
363 SvToken
* pTok
= rInStm
.GetToken_Next();
365 if( pTok
->IsIdentifier() )
368 if( rBase
.FindId( pTok
->GetString(), &n
) )
370 *(ByteString
*)this = pTok
->GetString();
376 ByteString
aStr ("no value for identifier <");
379 rBase
.SetError( aStr
, rInStm
.GetToken() );
380 rBase
.WriteError( rInStm
);
383 rInStm
.Seek( nTokPos
);
387 /*************************************************************************
389 |* SvStream& operator << ( SvNumberIdentifier )
390 |* SvStream& operator >> ( SvNumberIdentifier )
393 |* Ersterstellung MM 12.12.94
394 |* Letzte Aenderung MM 12.12.94
396 *************************************************************************/
397 SvStream
& operator << (SvStream
& rStm
, const SvNumberIdentifier
& r
)
399 rStm
<< (SvIdentifier
&)r
;
400 SvPersistStream::WriteCompressed( rStm
, r
.nValue
);
404 SvStream
& operator >> (SvStream
& rStm
, SvNumberIdentifier
& r
)
406 rStm
>> (SvIdentifier
&)r
;
407 r
.nValue
= SvPersistStream::ReadCompressed( rStm
);
412 /************************************************************************/
413 /*************************************************************************
415 |* SvString::ReadSvIdl()
418 |* Ersterstellung MM 12.12.94
419 |* Letzte Aenderung MM 12.12.94
421 *************************************************************************/
422 BOOL
SvString::ReadSvIdl( SvStringHashEntry
* pName
, SvTokenStream
& rInStm
)
424 UINT32 nTokPos
= rInStm
.Tell();
425 SvToken
* pTok
= rInStm
.GetToken_Next();
427 if( pTok
->Is( pName
) )
430 BOOL bBraket
= rInStm
.Read( '(' );
431 if( bBraket
|| rInStm
.Read( '=' ) )
433 pTok
= rInStm
.GetToken();
434 if( pTok
->IsString() )
436 *(ByteString
*)this = pTok
->GetString();
437 rInStm
.GetToken_Next();
440 bOk
= rInStm
.Read( ')' );
445 rInStm
.Seek( nTokPos
);
449 /*************************************************************************
451 |* SvString::WriteSvIdl()
454 |* Ersterstellung MM 12.12.94
455 |* Letzte Aenderung MM 12.12.94
457 *************************************************************************/
458 BOOL
SvString::WriteSvIdl( SvStringHashEntry
* pName
, SvStream
& rOutStm
,
461 rOutStm
<< pName
->GetName().GetBuffer() << "(\"";
462 rOutStm
<< GetBuffer() << "\")";
466 SvStream
& operator << (SvStream
& rStm
, const SvString
& r
)
468 rStm
.WriteByteString( r
);
472 SvStream
& operator >> (SvStream
& rStm
, SvString
& r
)
474 rStm
.ReadByteString( r
);
479 /*************************************************************************
481 |* SvHelpText::ReadSvIdl()
484 |* Ersterstellung MM 12.12.94
485 |* Letzte Aenderung MM 12.12.94
487 *************************************************************************/
488 BOOL
SvHelpText::ReadSvIdl( SvIdlDataBase
&, SvTokenStream
& rInStm
)
490 return SvString::ReadSvIdl( SvHash_HelpText(), rInStm
);
493 /*************************************************************************
495 |* SvHelpText::WriteSvIdl()
498 |* Ersterstellung MM 12.12.94
499 |* Letzte Aenderung MM 12.12.94
501 *************************************************************************/
502 BOOL
SvHelpText::WriteSvIdl( SvIdlDataBase
&, SvStream
& rOutStm
, USHORT nTab
)
504 return SvString::WriteSvIdl( SvHash_HelpText(), rOutStm
, nTab
);
507 /************************************************************************/
508 /*************************************************************************
510 |* SvUUId::ReadSvIdl()
513 |* Ersterstellung MM 12.12.94
514 |* Letzte Aenderung MM 12.12.94
516 *************************************************************************/
517 BOOL
SvUUId::ReadSvIdl( SvIdlDataBase
&, SvTokenStream
& rInStm
)
519 UINT32 nTokPos
= rInStm
.Tell();
520 SvToken
* pTok
= rInStm
.GetToken_Next();
522 if( pTok
->Is( SvHash_uuid() ) )
525 BOOL bBraket
= rInStm
.Read( '(' );
526 if( bBraket
|| rInStm
.Read( '=' ) )
528 pTok
= rInStm
.GetToken();
529 if( pTok
->IsString() )
531 pTok
= rInStm
.GetToken_Next();
532 bOk
= MakeId( String::CreateFromAscii( pTok
->GetString().GetBuffer() ) );
535 bOk
= rInStm
.Read( ')' );
540 rInStm
.Seek( nTokPos
);
544 /*************************************************************************
546 |* SvMetaObject::WriteSvIdl()
549 |* Ersterstellung MM 12.12.94
550 |* Letzte Aenderung MM 12.12.94
552 *************************************************************************/
553 BOOL
SvUUId::WriteSvIdl( SvStream
& rOutStm
)
555 // Global Id schreiben
556 rOutStm
<< SvHash_uuid()->GetName().GetBuffer() << "(\"";
557 rOutStm
<< ByteString( GetHexName(), RTL_TEXTENCODING_UTF8
).GetBuffer() << "\")";
562 /************************************************************************/
563 /*************************************************************************
565 |* SvVersion::ReadSvIdl()
568 |* Ersterstellung MM 12.12.94
569 |* Letzte Aenderung MM 12.12.94
571 *************************************************************************/
572 BOOL
SvVersion::ReadSvIdl( SvTokenStream
& rInStm
)
576 UINT32 nTokPos
= rInStm
.Tell();
577 if( ReadRangeSvIdl( SvHash_Version(), rInStm
, 0 , 0xFFFF, &n
) )
579 nMajorVersion
= (USHORT
)n
;
580 if( rInStm
.Read( '.' ) )
582 SvToken
* pTok
= rInStm
.GetToken_Next();
583 if( pTok
->IsInteger() && pTok
->GetNumber() <= 0xFFFF )
585 nMinorVersion
= (USHORT
)pTok
->GetNumber();
592 rInStm
.Seek( nTokPos
);
596 /*************************************************************************
598 |* SvVersion::WriteSvIdl()
601 |* Ersterstellung MM 12.12.94
602 |* Letzte Aenderung MM 12.12.94
604 *************************************************************************/
605 BOOL
SvVersion::WriteSvIdl( SvStream
& rOutStm
)
607 rOutStm
<< SvHash_Version()->GetName().GetBuffer() << '('
608 << ByteString::CreateFromInt32( nMajorVersion
).GetBuffer() << '.'
609 << ByteString::CreateFromInt32( nMinorVersion
).GetBuffer() << ')';
612 #endif //IDL_COMPILER