1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_idl.hxx"
31 #include <tools/debug.hxx>
35 #include <bastype.hxx>
37 #include <globals.hxx>
39 #include <database.hxx>
42 /************************************************************************/
43 static sal_Bool
ReadRangeSvIdl( SvStringHashEntry
* pName
, SvTokenStream
& rInStm
,
44 sal_uLong nMin
, sal_uLong nMax
, sal_uLong
* pValue
)
46 sal_uInt32 nTokPos
= rInStm
.Tell();
47 SvToken
* pTok
= rInStm
.GetToken_Next();
48 if( pTok
->Is( pName
) )
50 sal_Bool bOk
= sal_False
;
51 if( rInStm
.Read( '=' ) )
53 pTok
= rInStm
.GetToken_Next();
54 if( pTok
->IsInteger() )
56 sal_uLong n
= pTok
->GetNumber();
57 if ( n
>= nMin
&& n
<= nMax
)
69 rInStm
.Seek( nTokPos
);
74 /*************************************************************************
80 |* Ersterstellung MM 12.12.94
81 |* Letzte Aenderung MM 12.12.94
83 *************************************************************************/
84 sal_uInt32
SvUINT32::Read( SvStream
& rStm
)
86 return SvPersistStream::ReadCompressed( rStm
);
89 void SvUINT32::Write( SvStream
& rStm
, sal_uInt32 nVal
)
91 SvPersistStream::WriteCompressed( rStm
, nVal
);
94 /*************************************************************************
96 |* SvStream& operator << ( SvBOOL )
97 |* SvStream& operator >> ( SvBOOL )
100 |* Ersterstellung MM 12.12.94
101 |* Letzte Aenderung MM 12.12.94
103 *************************************************************************/
104 SvStream
& operator << (SvStream
& rStm
, const SvBOOL
& rb
)
106 sal_uInt8 n
= rb
.nVal
;
112 SvStream
& operator >> (SvStream
& rStm
, SvBOOL
& rb
)
116 rb
.nVal
= (n
& 0x01) ? sal_True
: sal_False
;
117 rb
.bSet
= (n
& 0x02) ? sal_True
: sal_False
;
120 rStm
.SetError( SVSTREAM_FILEFORMAT_ERROR
);
121 DBG_ERROR( "format error" );
126 /*************************************************************************
128 |* SvStream& operator << ( SvVersion )
129 |* SvStream& operator >> ( SvVersion )
132 |* Ersterstellung MM 12.12.94
133 |* Letzte Aenderung MM 12.12.94
135 *************************************************************************/
136 SvStream
& operator << (SvStream
& rStm
, const SvVersion
& r
)
138 if( (r
.GetMajorVersion() || r
.GetMinorVersion())
139 && r
.GetMajorVersion() <= 0x0F && r
.GetMinorVersion() <= 0x0F )
140 { // Versionsnummer in 1 Byte komprimieren
141 // Format 4 Bit fuer Major, dann 4 Bit fuer Minor.
142 // 0.0 wird nicht komprimiert
144 int n
= r
.GetMajorVersion() << 4;
145 n
|= r
.GetMinorVersion();
146 rStm
<< (sal_uInt8
)n
;
150 rStm
<< (sal_uInt8
)0;
151 rStm
<< r
.GetMajorVersion();
152 rStm
<< r
.GetMinorVersion();
157 SvStream
& operator >> (SvStream
& rStm
, SvVersion
& r
)
162 { // nicht komprimiert
163 rStm
>> r
.nMajorVersion
;
164 rStm
>> r
.nMinorVersion
;
168 r
.nMajorVersion
= (n
>> 4) & 0x0F;
169 r
.nMinorVersion
= n
& 0x0F;
176 /************************************************************************/
178 /*************************************************************************
180 |* SvBOOL::ReadSvIdl()
183 |* Ersterstellung MM 12.12.94
184 |* Letzte Aenderung MM 12.12.94
186 *************************************************************************/
187 sal_Bool
SvBOOL::ReadSvIdl( SvStringHashEntry
* pName
, SvTokenStream
& rInStm
)
189 sal_uInt32 nTokPos
= rInStm
.Tell();
190 SvToken
* pTok
= rInStm
.GetToken_Next();
192 if( pTok
->Is( pName
) )
194 sal_Bool bOk
= sal_True
;
195 sal_Bool bBraket
= rInStm
.Read( '(' );
196 if( bBraket
|| rInStm
.Read( '=' ) )
198 pTok
= rInStm
.GetToken();
201 *this = pTok
->GetBool();
203 rInStm
.GetToken_Next();
206 bOk
= rInStm
.Read( ')' );
209 *this = sal_True
; //Defaultaktion ist auf sal_True setzen
213 rInStm
.Seek( nTokPos
);
217 /*************************************************************************
219 |* SvBOOL::WriteSvIdl()
223 *************************************************************************/
224 sal_Bool
SvBOOL::WriteSvIdl( SvStringHashEntry
* pName
, SvStream
& rOutStm
)
227 rOutStm
<< pName
->GetName().GetBuffer();
229 rOutStm
<< pName
->GetName().GetBuffer() << "(FALSE)";
233 /*************************************************************************
235 |* SvBOOL::WriteSvIdl()
239 *************************************************************************/
240 ByteString
SvBOOL::GetSvIdlString( SvStringHashEntry
* pName
)
243 return pName
->GetName();
246 ByteString
aTmp( pName
->GetName() );
253 /************************************************************************/
254 /*************************************************************************
256 |* SvIdentifier::ReadSvIdl()
260 *************************************************************************/
261 sal_Bool
SvIdentifier::ReadSvIdl( SvStringHashEntry
* pName
, SvTokenStream
& rInStm
)
263 sal_uInt32 nTokPos
= rInStm
.Tell();
264 SvToken
* pTok
= rInStm
.GetToken_Next();
266 if( pTok
->Is( pName
) )
268 sal_Bool bOk
= sal_True
;
269 sal_Bool bBraket
= rInStm
.Read( '(' );
270 if( bBraket
|| rInStm
.Read( '=' ) )
272 pTok
= rInStm
.GetToken();
273 if( pTok
->IsIdentifier() )
275 *(ByteString
*)this = pTok
->GetString();
276 rInStm
.GetToken_Next();
279 bOk
= rInStm
.Read( ')' );
284 rInStm
.Seek( nTokPos
);
288 /*************************************************************************
290 |* SvIdentifier::WriteSvIdl()
294 *************************************************************************/
295 sal_Bool
SvIdentifier::WriteSvIdl( SvStringHashEntry
* pName
,
297 sal_uInt16
/*nTab */ )
299 rOutStm
<< pName
->GetName().GetBuffer() << '(';
300 rOutStm
<< GetBuffer() << ')';
304 SvStream
& operator << (SvStream
& rStm
, const SvIdentifier
& r
)
306 rStm
.WriteByteString( r
);
310 SvStream
& operator >> (SvStream
& rStm
, SvIdentifier
& r
)
312 rStm
.ReadByteString( r
);
317 /************************************************************************/
318 /*************************************************************************
320 |* SvNumberIdentifier::ReadSvIdl()
324 *************************************************************************/
325 sal_Bool
SvNumberIdentifier::ReadSvIdl( SvIdlDataBase
& rBase
,
326 SvStringHashEntry
* pName
,
327 SvTokenStream
& rInStm
)
329 if( SvIdentifier::ReadSvIdl( pName
, rInStm
) )
332 if( rBase
.FindId( *this, &n
) )
339 ByteString
aStr ("no value for identifier <");
342 rBase
.SetError( aStr
, rInStm
.GetToken() );
343 rBase
.WriteError( rInStm
);
349 /*************************************************************************
351 |* SvNumberIdentifier::ReadSvIdl()
355 *************************************************************************/
356 sal_Bool
SvNumberIdentifier::ReadSvIdl( SvIdlDataBase
& rBase
,
357 SvTokenStream
& rInStm
)
359 sal_uInt32 nTokPos
= rInStm
.Tell();
360 SvToken
* pTok
= rInStm
.GetToken_Next();
362 if( pTok
->IsIdentifier() )
365 if( rBase
.FindId( pTok
->GetString(), &n
) )
367 *(ByteString
*)this = pTok
->GetString();
373 ByteString
aStr ("no value for identifier <");
376 rBase
.SetError( aStr
, rInStm
.GetToken() );
377 rBase
.WriteError( rInStm
);
380 rInStm
.Seek( nTokPos
);
384 /*************************************************************************
386 |* SvStream& operator << ( SvNumberIdentifier )
387 |* SvStream& operator >> ( SvNumberIdentifier )
390 |* Ersterstellung MM 12.12.94
391 |* Letzte Aenderung MM 12.12.94
393 *************************************************************************/
394 SvStream
& operator << (SvStream
& rStm
, const SvNumberIdentifier
& r
)
396 rStm
<< (SvIdentifier
&)r
;
397 SvPersistStream::WriteCompressed( rStm
, r
.nValue
);
401 SvStream
& operator >> (SvStream
& rStm
, SvNumberIdentifier
& r
)
403 rStm
>> (SvIdentifier
&)r
;
404 r
.nValue
= SvPersistStream::ReadCompressed( rStm
);
409 /************************************************************************/
410 /*************************************************************************
412 |* SvString::ReadSvIdl()
415 |* Ersterstellung MM 12.12.94
416 |* Letzte Aenderung MM 12.12.94
418 *************************************************************************/
419 sal_Bool
SvString::ReadSvIdl( SvStringHashEntry
* pName
, SvTokenStream
& rInStm
)
421 sal_uInt32 nTokPos
= rInStm
.Tell();
422 SvToken
* pTok
= rInStm
.GetToken_Next();
424 if( pTok
->Is( pName
) )
426 sal_Bool bOk
= sal_True
;
427 sal_Bool bBraket
= rInStm
.Read( '(' );
428 if( bBraket
|| rInStm
.Read( '=' ) )
430 pTok
= rInStm
.GetToken();
431 if( pTok
->IsString() )
433 *(ByteString
*)this = pTok
->GetString();
434 rInStm
.GetToken_Next();
437 bOk
= rInStm
.Read( ')' );
442 rInStm
.Seek( nTokPos
);
446 /*************************************************************************
448 |* SvString::WriteSvIdl()
451 |* Ersterstellung MM 12.12.94
452 |* Letzte Aenderung MM 12.12.94
454 *************************************************************************/
455 sal_Bool
SvString::WriteSvIdl( SvStringHashEntry
* pName
, SvStream
& rOutStm
,
456 sal_uInt16
/*nTab */ )
458 rOutStm
<< pName
->GetName().GetBuffer() << "(\"";
459 rOutStm
<< GetBuffer() << "\")";
463 SvStream
& operator << (SvStream
& rStm
, const SvString
& r
)
465 rStm
.WriteByteString( r
);
469 SvStream
& operator >> (SvStream
& rStm
, SvString
& r
)
471 rStm
.ReadByteString( r
);
476 /*************************************************************************
478 |* SvHelpText::ReadSvIdl()
481 |* Ersterstellung MM 12.12.94
482 |* Letzte Aenderung MM 12.12.94
484 *************************************************************************/
485 sal_Bool
SvHelpText::ReadSvIdl( SvIdlDataBase
&, SvTokenStream
& rInStm
)
487 return SvString::ReadSvIdl( SvHash_HelpText(), rInStm
);
490 /*************************************************************************
492 |* SvHelpText::WriteSvIdl()
495 |* Ersterstellung MM 12.12.94
496 |* Letzte Aenderung MM 12.12.94
498 *************************************************************************/
499 sal_Bool
SvHelpText::WriteSvIdl( SvIdlDataBase
&, SvStream
& rOutStm
, sal_uInt16 nTab
)
501 return SvString::WriteSvIdl( SvHash_HelpText(), rOutStm
, nTab
);
504 /************************************************************************/
505 /*************************************************************************
507 |* SvUUId::ReadSvIdl()
510 |* Ersterstellung MM 12.12.94
511 |* Letzte Aenderung MM 12.12.94
513 *************************************************************************/
514 sal_Bool
SvUUId::ReadSvIdl( SvIdlDataBase
&, SvTokenStream
& rInStm
)
516 sal_uInt32 nTokPos
= rInStm
.Tell();
517 SvToken
* pTok
= rInStm
.GetToken_Next();
519 if( pTok
->Is( SvHash_uuid() ) )
521 sal_Bool bOk
= sal_True
;
522 sal_Bool bBraket
= rInStm
.Read( '(' );
523 if( bBraket
|| rInStm
.Read( '=' ) )
525 pTok
= rInStm
.GetToken();
526 if( pTok
->IsString() )
528 pTok
= rInStm
.GetToken_Next();
529 bOk
= MakeId( String::CreateFromAscii( pTok
->GetString().GetBuffer() ) );
532 bOk
= rInStm
.Read( ')' );
537 rInStm
.Seek( nTokPos
);
541 /*************************************************************************
543 |* SvMetaObject::WriteSvIdl()
546 |* Ersterstellung MM 12.12.94
547 |* Letzte Aenderung MM 12.12.94
549 *************************************************************************/
550 sal_Bool
SvUUId::WriteSvIdl( SvStream
& rOutStm
)
552 // Global Id schreiben
553 rOutStm
<< SvHash_uuid()->GetName().GetBuffer() << "(\"";
554 rOutStm
<< ByteString( GetHexName(), RTL_TEXTENCODING_UTF8
).GetBuffer() << "\")";
559 /************************************************************************/
560 /*************************************************************************
562 |* SvVersion::ReadSvIdl()
565 |* Ersterstellung MM 12.12.94
566 |* Letzte Aenderung MM 12.12.94
568 *************************************************************************/
569 sal_Bool
SvVersion::ReadSvIdl( SvTokenStream
& rInStm
)
573 sal_uInt32 nTokPos
= rInStm
.Tell();
574 if( ReadRangeSvIdl( SvHash_Version(), rInStm
, 0 , 0xFFFF, &n
) )
576 nMajorVersion
= (sal_uInt16
)n
;
577 if( rInStm
.Read( '.' ) )
579 SvToken
* pTok
= rInStm
.GetToken_Next();
580 if( pTok
->IsInteger() && pTok
->GetNumber() <= 0xFFFF )
582 nMinorVersion
= (sal_uInt16
)pTok
->GetNumber();
589 rInStm
.Seek( nTokPos
);
593 /*************************************************************************
595 |* SvVersion::WriteSvIdl()
598 |* Ersterstellung MM 12.12.94
599 |* Letzte Aenderung MM 12.12.94
601 *************************************************************************/
602 sal_Bool
SvVersion::WriteSvIdl( SvStream
& rOutStm
)
604 rOutStm
<< SvHash_Version()->GetName().GetBuffer() << '('
605 << ByteString::CreateFromInt32( nMajorVersion
).GetBuffer() << '.'
606 << ByteString::CreateFromInt32( nMinorVersion
).GetBuffer() << ')';
609 #endif //IDL_COMPILER