bump product version to 5.0.4.1
[LibreOffice.git] / idl / source / objects / bastype.cxx
blob5b1548526e190fdca272d6f4d96388226c5e0732
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <limits.h>
22 #include <ctype.h>
23 #include <bastype.hxx>
24 #include <lex.hxx>
25 #include <globals.hxx>
26 #include <hash.hxx>
27 #include <database.hxx>
28 #include <osl/diagnose.h>
30 static bool ReadRangeSvIdl( SvStringHashEntry * pName, SvTokenStream & rInStm,
31 sal_uLong nMin, sal_uLong nMax, sal_uLong* pValue )
33 sal_uInt32 nTokPos = rInStm.Tell();
34 SvToken * pTok = rInStm.GetToken_Next();
35 if( pTok->Is( pName ) )
37 bool bOk = false;
38 if( rInStm.Read( '=' ) )
40 pTok = rInStm.GetToken_Next();
41 if( pTok->IsInteger() )
43 sal_uLong n = pTok->GetNumber();
44 if ( n >= nMin && n <= nMax )
46 *pValue = n;
47 bOk = true;
52 if( bOk )
53 return true;
56 rInStm.Seek( nTokPos );
57 return false;
60 SvStream& WriteSvBOOL(SvStream & rStm, const SvBOOL & rb )
62 sal_uInt8 n = int(rb.nVal);
63 if( rb.bSet )
64 n |= 0x02;
65 rStm.WriteUChar( n );
66 return rStm;
68 SvStream& operator >> (SvStream & rStm, SvBOOL & rb )
70 sal_uInt8 n;
71 rStm.ReadUChar( n );
72 rb.nVal = (n & 0x01) != 0;
73 rb.bSet = (n & 0x02) != 0;
74 if( n & ~0x03 )
76 rStm.SetError( SVSTREAM_FILEFORMAT_ERROR );
77 OSL_FAIL( "format error" );
79 return rStm;
82 SvStream& WriteSvVersion(SvStream & rStm, const SvVersion & r )
84 if( (r.GetMajorVersion() || r.GetMinorVersion())
85 && r.GetMajorVersion() <= 0x0F && r.GetMinorVersion() <= 0x0F )
86 { // compress version number in 1 byte
87 // format first 4 bit for major, then 4 bit for minor
88 // 0.0 gets not compressed
90 int n = r.GetMajorVersion() << 4;
91 n |= r.GetMinorVersion();
92 rStm.WriteUChar( n );
94 else
96 rStm.WriteUChar( 0 );
97 rStm.WriteUInt16( r.GetMajorVersion() );
98 rStm.WriteUInt16( r.GetMinorVersion() );
100 return rStm;
103 SvStream& operator >> (SvStream & rStm, SvVersion & r )
105 sal_uInt8 n;
106 rStm.ReadUChar( n );
107 if( n == 0 )
108 { // not compressed
109 rStm.ReadUInt16( r.nMajorVersion );
110 rStm.ReadUInt16( r.nMinorVersion );
112 else
113 { // compressed
114 r.nMajorVersion = (n >> 4) & 0x0F;
115 r.nMinorVersion = n & 0x0F;
117 return rStm;
121 bool SvBOOL::ReadSvIdl( SvStringHashEntry * pName, SvTokenStream & rInStm )
123 sal_uInt32 nTokPos = rInStm.Tell();
124 SvToken * pTok = rInStm.GetToken_Next();
126 if( pTok->Is( pName ) )
128 bool bOk = true;
129 bool bBraket = rInStm.Read( '(' );
130 if( bBraket || rInStm.Read( '=' ) )
132 pTok = rInStm.GetToken();
133 if( pTok->IsBool() )
135 *this = pTok->GetBool();
137 rInStm.GetToken_Next();
139 if( bOk && bBraket )
140 bOk = rInStm.Read( ')' );
142 else
143 *this = true; //default action set to TRUE
144 if( bOk )
145 return true;
147 rInStm.Seek( nTokPos );
148 return false;
151 bool SvIdentifier::ReadSvIdl( SvStringHashEntry * pName, SvTokenStream & rInStm )
153 sal_uInt32 nTokPos = rInStm.Tell();
154 SvToken * pTok = rInStm.GetToken_Next();
156 if( pTok->Is( pName ) )
158 bool bOk = true;
159 bool bBraket = rInStm.Read( '(' );
160 if( bBraket || rInStm.Read( '=' ) )
162 pTok = rInStm.GetToken();
163 if( pTok->IsIdentifier() )
165 setString(pTok->GetString());
166 rInStm.GetToken_Next();
168 if( bOk && bBraket )
169 bOk = rInStm.Read( ')' );
171 if( bOk )
172 return true;
174 rInStm.Seek( nTokPos );
175 return false;
178 bool SvNumberIdentifier::ReadSvIdl( SvIdlDataBase & rBase,
179 SvStringHashEntry * pName,
180 SvTokenStream & rInStm )
182 if( SvIdentifier::ReadSvIdl( pName, rInStm ) )
184 sal_uLong n;
185 if( rBase.FindId( getString(), &n ) )
187 nValue = n;
188 return true;
190 else
192 OStringBuffer aStr("no value for identifier <");
193 aStr.append(getString()).append("> ");
194 rBase.SetError( aStr.makeStringAndClear(), rInStm.GetToken() );
195 rBase.WriteError( rInStm );
198 return false;
201 bool SvNumberIdentifier::ReadSvIdl( SvIdlDataBase & rBase,
202 SvTokenStream & rInStm )
204 sal_uInt32 nTokPos = rInStm.Tell();
205 SvToken * pTok = rInStm.GetToken_Next();
207 if( pTok->IsIdentifier() )
209 sal_uLong n;
210 if( rBase.FindId( pTok->GetString(), &n ) )
212 setString(pTok->GetString());
213 nValue = n;
214 return true;
216 else
218 OStringBuffer aStr("no value for identifier <");
219 aStr.append(getString()).append("> ");
220 rBase.SetError( aStr.makeStringAndClear(), rInStm.GetToken() );
221 rBase.WriteError( rInStm );
224 rInStm.Seek( nTokPos );
225 return false;
228 bool SvString::ReadSvIdl( SvStringHashEntry * pName, SvTokenStream & rInStm )
230 sal_uInt32 nTokPos = rInStm.Tell();
231 SvToken * pTok = rInStm.GetToken_Next();
233 if( pTok->Is( pName ) )
235 bool bOk = true;
236 bool bBraket = rInStm.Read( '(' );
237 if( bBraket || rInStm.Read( '=' ) )
239 pTok = rInStm.GetToken();
240 if( pTok->IsString() )
242 setString(pTok->GetString());
243 rInStm.GetToken_Next();
245 if( bOk && bBraket )
246 bOk = rInStm.Read( ')' );
248 if( bOk )
249 return true;
251 rInStm.Seek( nTokPos );
252 return false;
255 SvStream& WriteSvString(SvStream & rStm, const SvString & r )
257 write_uInt16_lenPrefixed_uInt8s_FromOString(rStm, r.getString());
258 return rStm;
261 SvStream& operator >> (SvStream & rStm, SvString & r )
263 r.setString(read_uInt16_lenPrefixed_uInt8s_ToOString(rStm));
264 return rStm;
268 bool SvHelpText::ReadSvIdl( SvIdlDataBase &, SvTokenStream & rInStm )
270 return SvString::ReadSvIdl( SvHash_HelpText(), rInStm );
273 bool SvUUId::ReadSvIdl( SvIdlDataBase &, SvTokenStream & rInStm )
275 sal_uInt32 nTokPos = rInStm.Tell();
276 SvToken * pTok = rInStm.GetToken_Next();
278 if( pTok->Is( SvHash_uuid() ) )
280 bool bOk = true;
281 bool bBraket = rInStm.Read( '(' );
282 if( bBraket || rInStm.Read( '=' ) )
284 pTok = rInStm.GetToken();
285 if( pTok->IsString() )
287 pTok = rInStm.GetToken_Next();
288 bOk = MakeId(OStringToOUString(pTok->GetString(), RTL_TEXTENCODING_ASCII_US));
290 if( bOk && bBraket )
291 bOk = rInStm.Read( ')' );
293 if( bOk )
294 return true;
296 rInStm.Seek( nTokPos );
297 return false;
300 bool SvVersion::ReadSvIdl( SvTokenStream & rInStm )
302 sal_uLong n = 0;
304 sal_uInt32 nTokPos = rInStm.Tell();
305 if( ReadRangeSvIdl( SvHash_Version(), rInStm, 0 , 0xFFFF, &n ) )
307 nMajorVersion = (sal_uInt16)n;
308 if( rInStm.Read( '.' ) )
310 SvToken * pTok = rInStm.GetToken_Next();
311 if( pTok->IsInteger() && pTok->GetNumber() <= 0xFFFF )
313 nMinorVersion = (sal_uInt16)pTok->GetNumber();
314 return true;
317 else
318 return true;
320 rInStm.Seek( nTokPos );
321 return false;
324 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */