merged tag ooo/DEV300_m102
[LibreOffice.git] / idl / source / objects / bastype.cxx
blob19df1c0967b213dd0ffff08015a5f0e0eaddeb10
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>
33 #include <limits.h>
34 #include <ctype.h>
35 #include <bastype.hxx>
36 #include <lex.hxx>
37 #include <globals.hxx>
38 #include <hash.hxx>
39 #include <database.hxx>
41 #ifdef IDL_COMPILER
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 )
59 *pValue = n;
60 bOk = sal_True;
65 if( bOk )
66 return sal_True;
69 rInStm.Seek( nTokPos );
70 return sal_False;
72 #endif
74 /*************************************************************************
76 |* SvUINT32::Read()
77 |* SvUINT32::Write()
79 |* Beschreibung
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 )
99 |* Beschreibung
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;
107 if( rb.bSet )
108 n |= 0x02;
109 rStm << n;
110 return rStm;
112 SvStream& operator >> (SvStream & rStm, SvBOOL & rb )
114 sal_uInt8 n;
115 rStm >> n;
116 rb.nVal = (n & 0x01) ? sal_True : sal_False;
117 rb.bSet = (n & 0x02) ? sal_True : sal_False;
118 if( n & ~0x03 )
120 rStm.SetError( SVSTREAM_FILEFORMAT_ERROR );
121 DBG_ERROR( "format error" );
123 return rStm;
126 /*************************************************************************
128 |* SvStream& operator << ( SvVersion )
129 |* SvStream& operator >> ( SvVersion )
131 |* Beschreibung
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;
148 else
150 rStm << (sal_uInt8)0;
151 rStm << r.GetMajorVersion();
152 rStm << r.GetMinorVersion();
154 return rStm;
157 SvStream& operator >> (SvStream & rStm, SvVersion & r )
159 sal_uInt8 n;
160 rStm >> n;
161 if( n == 0 )
162 { // nicht komprimiert
163 rStm >> r.nMajorVersion;
164 rStm >> r.nMinorVersion;
166 else
167 { // komprimiert
168 r.nMajorVersion = (n >> 4) & 0x0F;
169 r.nMinorVersion = n & 0x0F;
171 return rStm;
175 #ifdef IDL_COMPILER
176 /************************************************************************/
178 /*************************************************************************
180 |* SvBOOL::ReadSvIdl()
182 |* Beschreibung
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();
199 if( pTok->IsBool() )
201 *this = pTok->GetBool();
203 rInStm.GetToken_Next();
205 if( bOk && bBraket )
206 bOk = rInStm.Read( ')' );
208 else
209 *this = sal_True; //Defaultaktion ist auf sal_True setzen
210 if( bOk )
211 return sal_True;
213 rInStm.Seek( nTokPos );
214 return sal_False;
217 /*************************************************************************
219 |* SvBOOL::WriteSvIdl()
221 |* Beschreibung
223 *************************************************************************/
224 sal_Bool SvBOOL::WriteSvIdl( SvStringHashEntry * pName, SvStream & rOutStm )
226 if( nVal )
227 rOutStm << pName->GetName().GetBuffer();
228 else
229 rOutStm << pName->GetName().GetBuffer() << "(FALSE)";
230 return sal_True;
233 /*************************************************************************
235 |* SvBOOL::WriteSvIdl()
237 |* Beschreibung
239 *************************************************************************/
240 ByteString SvBOOL::GetSvIdlString( SvStringHashEntry * pName )
242 if( nVal )
243 return pName->GetName();
244 else
246 ByteString aTmp( pName->GetName() );
247 aTmp += "(FALSE)";
248 return aTmp;
253 /************************************************************************/
254 /*************************************************************************
256 |* SvIdentifier::ReadSvIdl()
258 |* Beschreibung
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();
278 if( bOk && bBraket )
279 bOk = rInStm.Read( ')' );
281 if( bOk )
282 return sal_True;
284 rInStm.Seek( nTokPos );
285 return sal_False;
288 /*************************************************************************
290 |* SvIdentifier::WriteSvIdl()
292 |* Beschreibung
294 *************************************************************************/
295 sal_Bool SvIdentifier::WriteSvIdl( SvStringHashEntry * pName,
296 SvStream & rOutStm,
297 sal_uInt16 /*nTab */ )
299 rOutStm << pName->GetName().GetBuffer() << '(';
300 rOutStm << GetBuffer() << ')';
301 return sal_True;
304 SvStream& operator << (SvStream & rStm, const SvIdentifier & r )
306 rStm.WriteByteString( r );
307 return rStm;
310 SvStream& operator >> (SvStream & rStm, SvIdentifier & r )
312 rStm.ReadByteString( r );
313 return rStm;
317 /************************************************************************/
318 /*************************************************************************
320 |* SvNumberIdentifier::ReadSvIdl()
322 |* Beschreibung
324 *************************************************************************/
325 sal_Bool SvNumberIdentifier::ReadSvIdl( SvIdlDataBase & rBase,
326 SvStringHashEntry * pName,
327 SvTokenStream & rInStm )
329 if( SvIdentifier::ReadSvIdl( pName, rInStm ) )
331 sal_uLong n;
332 if( rBase.FindId( *this, &n ) )
334 nValue = n;
335 return sal_True;
337 else
339 ByteString aStr ("no value for identifier <");
340 aStr += *this;
341 aStr += "> ";
342 rBase.SetError( aStr, rInStm.GetToken() );
343 rBase.WriteError( rInStm );
346 return sal_False;
349 /*************************************************************************
351 |* SvNumberIdentifier::ReadSvIdl()
353 |* Beschreibung
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() )
364 sal_uLong n;
365 if( rBase.FindId( pTok->GetString(), &n ) )
367 *(ByteString *)this = pTok->GetString();
368 nValue = n;
369 return sal_True;
371 else
373 ByteString aStr ("no value for identifier <");
374 aStr += *this;
375 aStr += "> ";
376 rBase.SetError( aStr, rInStm.GetToken() );
377 rBase.WriteError( rInStm );
380 rInStm.Seek( nTokPos );
381 return sal_False;
384 /*************************************************************************
386 |* SvStream& operator << ( SvNumberIdentifier )
387 |* SvStream& operator >> ( SvNumberIdentifier )
389 |* Beschreibung
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 );
398 return rStm;
401 SvStream& operator >> (SvStream & rStm, SvNumberIdentifier & r )
403 rStm >> (SvIdentifier &)r;
404 r.nValue = SvPersistStream::ReadCompressed( rStm );
405 return rStm;
409 /************************************************************************/
410 /*************************************************************************
412 |* SvString::ReadSvIdl()
414 |* Beschreibung
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();
436 if( bOk && bBraket )
437 bOk = rInStm.Read( ')' );
439 if( bOk )
440 return sal_True;
442 rInStm.Seek( nTokPos );
443 return sal_False;
446 /*************************************************************************
448 |* SvString::WriteSvIdl()
450 |* Beschreibung
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() << "\")";
460 return sal_True;
463 SvStream& operator << (SvStream & rStm, const SvString & r )
465 rStm.WriteByteString( r );
466 return rStm;
469 SvStream& operator >> (SvStream & rStm, SvString & r )
471 rStm.ReadByteString( r );
472 return rStm;
476 /*************************************************************************
478 |* SvHelpText::ReadSvIdl()
480 |* Beschreibung
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()
494 |* Beschreibung
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()
509 |* Beschreibung
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() ) );
531 if( bOk && bBraket )
532 bOk = rInStm.Read( ')' );
534 if( bOk )
535 return sal_True;
537 rInStm.Seek( nTokPos );
538 return sal_False;
541 /*************************************************************************
543 |* SvMetaObject::WriteSvIdl()
545 |* Beschreibung
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() << "\")";
555 return sal_True;
559 /************************************************************************/
560 /*************************************************************************
562 |* SvVersion::ReadSvIdl()
564 |* Beschreibung
565 |* Ersterstellung MM 12.12.94
566 |* Letzte Aenderung MM 12.12.94
568 *************************************************************************/
569 sal_Bool SvVersion::ReadSvIdl( SvTokenStream & rInStm )
571 sal_uLong n = 0;
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();
583 return sal_True;
586 else
587 return sal_True;
589 rInStm.Seek( nTokPos );
590 return sal_False;
593 /*************************************************************************
595 |* SvVersion::WriteSvIdl()
597 |* Beschreibung
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() << ')';
607 return sal_True;
609 #endif //IDL_COMPILER