xref: /aoo42x/main/idl/source/objects/bastype.cxx (revision 79aad27f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_idl.hxx"
26 
27 #include <tools/debug.hxx>
28 
29 #include <limits.h>
30 #include <ctype.h>
31 #include <bastype.hxx>
32 #include <lex.hxx>
33 #include <globals.hxx>
34 #include <hash.hxx>
35 #include <database.hxx>
36 
37 #ifdef IDL_COMPILER
38 /************************************************************************/
ReadRangeSvIdl(SvStringHashEntry * pName,SvTokenStream & rInStm,sal_uLong nMin,sal_uLong nMax,sal_uLong * pValue)39 static sal_Bool ReadRangeSvIdl( SvStringHashEntry * pName, SvTokenStream & rInStm,
40                             sal_uLong nMin, sal_uLong nMax, sal_uLong* pValue )
41 {
42     sal_uInt32 nTokPos = rInStm.Tell();
43     SvToken * pTok = rInStm.GetToken_Next();
44     if( pTok->Is( pName ) )
45     {
46         sal_Bool bOk = sal_False;
47         if( rInStm.Read( '=' ) )
48         {
49             pTok = rInStm.GetToken_Next();
50             if( pTok->IsInteger() )
51             {
52                 sal_uLong n = pTok->GetNumber();
53                 if ( n >= nMin && n <= nMax )
54                 {
55                     *pValue = n;
56                     bOk = sal_True;
57                 }
58             }
59         }
60 
61         if( bOk )
62             return sal_True;
63     }
64 
65     rInStm.Seek( nTokPos );
66     return sal_False;
67 }
68 #endif
69 
70 /*************************************************************************
71 |*
72 |*    SvUINT32::Read()
73 |*    SvUINT32::Write()
74 |*
75 |*    Beschreibung
76 |*    Ersterstellung    MM 12.12.94
77 |*    Letzte Aenderung  MM 12.12.94
78 |*
79 *************************************************************************/
Read(SvStream & rStm)80 sal_uInt32 SvUINT32::Read( SvStream & rStm )
81 {
82     return SvPersistStream::ReadCompressed( rStm );
83 }
84 
Write(SvStream & rStm,sal_uInt32 nVal)85 void SvUINT32::Write( SvStream & rStm, sal_uInt32 nVal )
86 {
87     SvPersistStream::WriteCompressed( rStm, nVal );
88 }
89 
90 /*************************************************************************
91 |*
92 |*    SvStream& operator << ( SvBOOL )
93 |*    SvStream& operator >> ( SvBOOL )
94 |*
95 |*    Beschreibung
96 |*    Ersterstellung    MM 12.12.94
97 |*    Letzte Aenderung  MM 12.12.94
98 |*
99 *************************************************************************/
operator <<(SvStream & rStm,const SvBOOL & rb)100 SvStream& operator << (SvStream & rStm, const SvBOOL & rb )
101 {
102     sal_uInt8 n = rb.nVal;
103     if( rb.bSet )
104         n |= 0x02;
105     rStm << n;
106     return rStm;
107 }
operator >>(SvStream & rStm,SvBOOL & rb)108 SvStream& operator >> (SvStream & rStm, SvBOOL & rb )
109 {
110     sal_uInt8 n;
111     rStm >> n;
112     rb.nVal = (n & 0x01) ? sal_True : sal_False;
113     rb.bSet = (n & 0x02) ? sal_True : sal_False;
114     if( n & ~0x03 )
115     {
116         rStm.SetError( SVSTREAM_FILEFORMAT_ERROR );
117         DBG_ERROR( "format error" );
118     }
119     return rStm;
120 }
121 
122 /*************************************************************************
123 |*
124 |*    SvStream& operator << ( SvVersion )
125 |*    SvStream& operator >> ( SvVersion )
126 |*
127 |*    Beschreibung
128 |*    Ersterstellung    MM 12.12.94
129 |*    Letzte Aenderung  MM 12.12.94
130 |*
131 *************************************************************************/
operator <<(SvStream & rStm,const SvVersion & r)132 SvStream& operator << (SvStream & rStm, const SvVersion & r )
133 {
134     if( (r.GetMajorVersion() || r.GetMinorVersion())
135       && r.GetMajorVersion() <= 0x0F && r.GetMinorVersion() <= 0x0F )
136     { // Versionsnummer in 1 Byte komprimieren
137         // Format 4 Bit fuer Major, dann 4 Bit fuer Minor.
138         // 0.0 wird nicht komprimiert
139 
140         int n = r.GetMajorVersion() << 4;
141         n |= r.GetMinorVersion();
142         rStm << (sal_uInt8)n;
143     }
144     else
145     {
146         rStm << (sal_uInt8)0;
147         rStm << r.GetMajorVersion();
148         rStm << r.GetMinorVersion();
149     }
150     return rStm;
151 }
152 
operator >>(SvStream & rStm,SvVersion & r)153 SvStream& operator >> (SvStream & rStm, SvVersion & r )
154 {
155     sal_uInt8 n;
156     rStm >> n;
157     if( n == 0 )
158     { // nicht komprimiert
159         rStm >> r.nMajorVersion;
160         rStm >> r.nMinorVersion;
161     }
162     else
163     { // komprimiert
164         r.nMajorVersion = (n >> 4) & 0x0F;
165         r.nMinorVersion = n & 0x0F;
166     }
167     return rStm;
168 }
169 
170 
171 #ifdef IDL_COMPILER
172 /************************************************************************/
173 
174 /*************************************************************************
175 |*
176 |*    SvBOOL::ReadSvIdl()
177 |*
178 |*    Beschreibung
179 |*    Ersterstellung    MM 12.12.94
180 |*    Letzte Aenderung  MM 12.12.94
181 |*
182 *************************************************************************/
ReadSvIdl(SvStringHashEntry * pName,SvTokenStream & rInStm)183 sal_Bool SvBOOL::ReadSvIdl( SvStringHashEntry * pName, SvTokenStream & rInStm )
184 {
185     sal_uInt32 nTokPos = rInStm.Tell();
186     SvToken * pTok = rInStm.GetToken_Next();
187 
188     if( pTok->Is( pName ) )
189     {
190         sal_Bool bOk = sal_True;
191         sal_Bool bBraket = rInStm.Read( '(' );
192         if( bBraket || rInStm.Read( '=' ) )
193         {
194             pTok = rInStm.GetToken();
195             if( pTok->IsBool() )
196             {
197                 *this = pTok->GetBool();
198 
199                 rInStm.GetToken_Next();
200             }
201             if( bOk && bBraket )
202                 bOk = rInStm.Read( ')' );
203         }
204         else
205             *this = sal_True; //Defaultaktion ist auf sal_True setzen
206         if( bOk )
207             return sal_True;
208     }
209     rInStm.Seek( nTokPos );
210     return sal_False;
211 }
212 
213 /*************************************************************************
214 |*
215 |*    SvBOOL::WriteSvIdl()
216 |*
217 |*    Beschreibung
218 |*
219 *************************************************************************/
WriteSvIdl(SvStringHashEntry * pName,SvStream & rOutStm)220 sal_Bool SvBOOL::WriteSvIdl( SvStringHashEntry * pName, SvStream & rOutStm )
221 {
222     if( nVal )
223         rOutStm << pName->GetName().GetBuffer();
224     else
225         rOutStm << pName->GetName().GetBuffer() << "(FALSE)";
226     return sal_True;
227 }
228 
229 /*************************************************************************
230 |*
231 |*    SvBOOL::WriteSvIdl()
232 |*
233 |*    Beschreibung
234 |*
235 *************************************************************************/
GetSvIdlString(SvStringHashEntry * pName)236 ByteString SvBOOL::GetSvIdlString( SvStringHashEntry * pName )
237 {
238     if( nVal )
239         return pName->GetName();
240     else
241     {
242         ByteString aTmp( pName->GetName() );
243         aTmp += "(FALSE)";
244         return aTmp;
245     }
246 }
247 
248 
249 /************************************************************************/
250 /*************************************************************************
251 |*
252 |*    SvIdentifier::ReadSvIdl()
253 |*
254 |*    Beschreibung
255 |*
256 *************************************************************************/
ReadSvIdl(SvStringHashEntry * pName,SvTokenStream & rInStm)257 sal_Bool SvIdentifier::ReadSvIdl( SvStringHashEntry * pName, SvTokenStream & rInStm )
258 {
259     sal_uInt32 nTokPos = rInStm.Tell();
260     SvToken * pTok = rInStm.GetToken_Next();
261 
262     if( pTok->Is( pName ) )
263     {
264         sal_Bool bOk = sal_True;
265         sal_Bool bBraket = rInStm.Read( '(' );
266         if( bBraket || rInStm.Read( '=' ) )
267         {
268             pTok = rInStm.GetToken();
269             if( pTok->IsIdentifier() )
270             {
271                 *(ByteString *)this = pTok->GetString();
272                 rInStm.GetToken_Next();
273             }
274             if( bOk && bBraket )
275                 bOk = rInStm.Read( ')' );
276         }
277         if( bOk )
278             return sal_True;
279     }
280     rInStm.Seek( nTokPos );
281     return sal_False;
282 }
283 
284 /*************************************************************************
285 |*
286 |*    SvIdentifier::WriteSvIdl()
287 |*
288 |*    Beschreibung
289 |*
290 *************************************************************************/
WriteSvIdl(SvStringHashEntry * pName,SvStream & rOutStm,sal_uInt16)291 sal_Bool SvIdentifier::WriteSvIdl( SvStringHashEntry * pName,
292                                SvStream & rOutStm,
293                                sal_uInt16 /*nTab */ )
294 {
295     rOutStm << pName->GetName().GetBuffer() << '(';
296     rOutStm << GetBuffer() << ')';
297     return sal_True;
298 }
299 
operator <<(SvStream & rStm,const SvIdentifier & r)300 SvStream& operator << (SvStream & rStm, const SvIdentifier & r )
301 {
302     rStm.WriteByteString( r );
303     return rStm;
304 }
305 
operator >>(SvStream & rStm,SvIdentifier & r)306 SvStream& operator >> (SvStream & rStm, SvIdentifier & r )
307 {
308     rStm.ReadByteString( r );
309     return rStm;
310 }
311 
312 
313 /************************************************************************/
314 /*************************************************************************
315 |*
316 |*    SvNumberIdentifier::ReadSvIdl()
317 |*
318 |*    Beschreibung
319 |*
320 *************************************************************************/
ReadSvIdl(SvIdlDataBase & rBase,SvStringHashEntry * pName,SvTokenStream & rInStm)321 sal_Bool SvNumberIdentifier::ReadSvIdl( SvIdlDataBase & rBase,
322                                     SvStringHashEntry * pName,
323                                     SvTokenStream & rInStm )
324 {
325     if( SvIdentifier::ReadSvIdl( pName, rInStm ) )
326     {
327         sal_uLong n;
328         if( rBase.FindId( *this, &n ) )
329         {
330             nValue = n;
331             return sal_True;
332         }
333         else
334         {
335             ByteString aStr ("no value for identifier <");
336 			aStr += *this;
337 			aStr += "> ";
338             rBase.SetError( aStr, rInStm.GetToken() );
339             rBase.WriteError( rInStm );
340         }
341     }
342     return sal_False;
343 }
344 
345 /*************************************************************************
346 |*
347 |*    SvNumberIdentifier::ReadSvIdl()
348 |*
349 |*    Beschreibung
350 |*
351 *************************************************************************/
ReadSvIdl(SvIdlDataBase & rBase,SvTokenStream & rInStm)352 sal_Bool SvNumberIdentifier::ReadSvIdl( SvIdlDataBase & rBase,
353                                     SvTokenStream & rInStm )
354 {
355     sal_uInt32 nTokPos = rInStm.Tell();
356     SvToken * pTok = rInStm.GetToken_Next();
357 
358     if( pTok->IsIdentifier() )
359     {
360         sal_uLong n;
361         if( rBase.FindId( pTok->GetString(), &n ) )
362         {
363             *(ByteString *)this = pTok->GetString();
364             nValue = n;
365             return sal_True;
366         }
367         else
368         {
369             ByteString aStr ("no value for identifier <");
370 			aStr += *this;
371 			aStr += "> ";
372             rBase.SetError( aStr, rInStm.GetToken() );
373             rBase.WriteError( rInStm );
374         }
375     }
376     rInStm.Seek( nTokPos );
377     return sal_False;
378 }
379 
380 /*************************************************************************
381 |*
382 |*    SvStream& operator << ( SvNumberIdentifier )
383 |*    SvStream& operator >> ( SvNumberIdentifier )
384 |*
385 |*    Beschreibung
386 |*    Ersterstellung    MM 12.12.94
387 |*    Letzte Aenderung  MM 12.12.94
388 |*
389 *************************************************************************/
operator <<(SvStream & rStm,const SvNumberIdentifier & r)390 SvStream& operator << (SvStream & rStm, const SvNumberIdentifier & r )
391 {
392     rStm << (SvIdentifier &)r;
393     SvPersistStream::WriteCompressed( rStm, r.nValue );
394     return rStm;
395 }
396 
operator >>(SvStream & rStm,SvNumberIdentifier & r)397 SvStream& operator >> (SvStream & rStm, SvNumberIdentifier & r )
398 {
399     rStm >> (SvIdentifier &)r;
400     r.nValue = SvPersistStream::ReadCompressed( rStm );
401     return rStm;
402 }
403 
404 
405 /************************************************************************/
406 /*************************************************************************
407 |*
408 |*    SvString::ReadSvIdl()
409 |*
410 |*    Beschreibung
411 |*    Ersterstellung    MM 12.12.94
412 |*    Letzte Aenderung  MM 12.12.94
413 |*
414 *************************************************************************/
ReadSvIdl(SvStringHashEntry * pName,SvTokenStream & rInStm)415 sal_Bool SvString::ReadSvIdl( SvStringHashEntry * pName, SvTokenStream & rInStm )
416 {
417     sal_uInt32 nTokPos = rInStm.Tell();
418     SvToken * pTok = rInStm.GetToken_Next();
419 
420     if( pTok->Is( pName ) )
421     {
422         sal_Bool bOk = sal_True;
423         sal_Bool bBraket = rInStm.Read( '(' );
424         if( bBraket || rInStm.Read( '=' ) )
425         {
426             pTok = rInStm.GetToken();
427             if( pTok->IsString() )
428             {
429                 *(ByteString *)this = pTok->GetString();
430                 rInStm.GetToken_Next();
431             }
432             if( bOk && bBraket )
433                 bOk = rInStm.Read( ')' );
434         }
435         if( bOk )
436             return sal_True;
437     }
438     rInStm.Seek( nTokPos );
439     return sal_False;
440 }
441 
442 /*************************************************************************
443 |*
444 |*    SvString::WriteSvIdl()
445 |*
446 |*    Beschreibung
447 |*    Ersterstellung    MM 12.12.94
448 |*    Letzte Aenderung  MM 12.12.94
449 |*
450 *************************************************************************/
WriteSvIdl(SvStringHashEntry * pName,SvStream & rOutStm,sal_uInt16)451 sal_Bool SvString::WriteSvIdl( SvStringHashEntry * pName, SvStream & rOutStm,
452                            sal_uInt16 /*nTab */ )
453 {
454     rOutStm << pName->GetName().GetBuffer() << "(\"";
455     rOutStm << GetBuffer() << "\")";
456     return sal_True;
457 }
458 
operator <<(SvStream & rStm,const SvString & r)459 SvStream& operator << (SvStream & rStm, const SvString & r )
460 {
461     rStm.WriteByteString( r );
462     return rStm;
463 }
464 
operator >>(SvStream & rStm,SvString & r)465 SvStream& operator >> (SvStream & rStm, SvString & r )
466 {
467     rStm.ReadByteString( r );
468     return rStm;
469 }
470 
471 
472 /*************************************************************************
473 |*
474 |*    SvHelpText::ReadSvIdl()
475 |*
476 |*    Beschreibung
477 |*    Ersterstellung    MM 12.12.94
478 |*    Letzte Aenderung  MM 12.12.94
479 |*
480 *************************************************************************/
ReadSvIdl(SvIdlDataBase &,SvTokenStream & rInStm)481 sal_Bool SvHelpText::ReadSvIdl( SvIdlDataBase &, SvTokenStream & rInStm )
482 {
483     return SvString::ReadSvIdl( SvHash_HelpText(), rInStm );
484 }
485 
486 /*************************************************************************
487 |*
488 |*    SvHelpText::WriteSvIdl()
489 |*
490 |*    Beschreibung
491 |*    Ersterstellung    MM 12.12.94
492 |*    Letzte Aenderung  MM 12.12.94
493 |*
494 *************************************************************************/
WriteSvIdl(SvIdlDataBase &,SvStream & rOutStm,sal_uInt16 nTab)495 sal_Bool SvHelpText::WriteSvIdl( SvIdlDataBase &, SvStream & rOutStm, sal_uInt16 nTab )
496 {
497     return SvString::WriteSvIdl( SvHash_HelpText(), rOutStm, nTab );
498 }
499 
500 /************************************************************************/
501 /*************************************************************************
502 |*
503 |*    SvUUId::ReadSvIdl()
504 |*
505 |*    Beschreibung
506 |*    Ersterstellung    MM 12.12.94
507 |*    Letzte Aenderung  MM 12.12.94
508 |*
509 *************************************************************************/
ReadSvIdl(SvIdlDataBase &,SvTokenStream & rInStm)510 sal_Bool SvUUId::ReadSvIdl( SvIdlDataBase &, SvTokenStream & rInStm )
511 {
512     sal_uInt32 nTokPos = rInStm.Tell();
513     SvToken * pTok = rInStm.GetToken_Next();
514 
515     if( pTok->Is( SvHash_uuid() ) )
516     {
517         sal_Bool bOk = sal_True;
518         sal_Bool bBraket = rInStm.Read( '(' );
519         if( bBraket || rInStm.Read( '=' ) )
520         {
521             pTok = rInStm.GetToken();
522             if( pTok->IsString() )
523             {
524                 pTok = rInStm.GetToken_Next();
525                 bOk = MakeId( String::CreateFromAscii( pTok->GetString().GetBuffer() ) );
526             }
527             if( bOk && bBraket )
528                 bOk = rInStm.Read( ')' );
529         }
530         if( bOk )
531             return sal_True;
532     }
533     rInStm.Seek( nTokPos );
534     return sal_False;
535 }
536 
537 /*************************************************************************
538 |*
539 |*    SvMetaObject::WriteSvIdl()
540 |*
541 |*    Beschreibung
542 |*    Ersterstellung    MM 12.12.94
543 |*    Letzte Aenderung  MM 12.12.94
544 |*
545 *************************************************************************/
WriteSvIdl(SvStream & rOutStm)546 sal_Bool SvUUId::WriteSvIdl( SvStream & rOutStm )
547 {
548     // Global Id schreiben
549     rOutStm << SvHash_uuid()->GetName().GetBuffer() << "(\"";
550     rOutStm << ByteString( GetHexName(), RTL_TEXTENCODING_UTF8 ).GetBuffer() << "\")";
551     return sal_True;
552 }
553 
554 
555 /************************************************************************/
556 /*************************************************************************
557 |*
558 |*    SvVersion::ReadSvIdl()
559 |*
560 |*    Beschreibung
561 |*    Ersterstellung    MM 12.12.94
562 |*    Letzte Aenderung  MM 12.12.94
563 |*
564 *************************************************************************/
ReadSvIdl(SvTokenStream & rInStm)565 sal_Bool SvVersion::ReadSvIdl( SvTokenStream & rInStm )
566 {
567     sal_uLong n = 0;
568 
569     sal_uInt32 nTokPos = rInStm.Tell();
570     if( ReadRangeSvIdl( SvHash_Version(), rInStm, 0 , 0xFFFF, &n ) )
571     {
572         nMajorVersion = (sal_uInt16)n;
573         if( rInStm.Read( '.' ) )
574         {
575             SvToken * pTok = rInStm.GetToken_Next();
576             if( pTok->IsInteger() && pTok->GetNumber() <= 0xFFFF )
577             {
578                 nMinorVersion = (sal_uInt16)pTok->GetNumber();
579                 return sal_True;
580             }
581         }
582         else
583             return sal_True;
584     }
585     rInStm.Seek( nTokPos );
586     return sal_False;
587 }
588 
589 /*************************************************************************
590 |*
591 |*    SvVersion::WriteSvIdl()
592 |*
593 |*    Beschreibung
594 |*    Ersterstellung    MM 12.12.94
595 |*    Letzte Aenderung  MM 12.12.94
596 |*
597 *************************************************************************/
WriteSvIdl(SvStream & rOutStm)598 sal_Bool SvVersion::WriteSvIdl( SvStream & rOutStm )
599 {
600     rOutStm << SvHash_Version()->GetName().GetBuffer() << '('
601             << ByteString::CreateFromInt32( nMajorVersion ).GetBuffer() << '.'
602             << ByteString::CreateFromInt32( nMinorVersion ).GetBuffer() << ')';
603     return sal_True;
604 }
605 #endif //IDL_COMPILER
606 
607 
608