Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include <ctype.h>
22 : #include <stdio.h>
23 :
24 : #include <tools/debug.hxx>
25 :
26 : #include <basobj.hxx>
27 : #include <module.hxx>
28 : #include <globals.hxx>
29 : #include <database.hxx>
30 :
31 34598 : SV_IMPL_META_FACTORY1( SvMetaObject, SvRttiBase )
32 29598 : SvMetaObject::SvMetaObject()
33 : {
34 29598 : }
35 :
36 0 : void SvMetaObject::Load( SvPersistStream & )
37 : {
38 0 : }
39 :
40 24368 : void SvMetaObject::Save( SvPersistStream & )
41 : {
42 24368 : }
43 :
44 143701 : void SvMetaObject::WriteTab( SvStream & rOutStm, sal_uInt16 nTab )
45 : {
46 605332 : while( nTab-- )
47 317930 : rOutStm << " ";
48 143701 : }
49 :
50 597 : void SvMetaObject::WriteStars( SvStream & rOutStm )
51 : {
52 597 : rOutStm << '/';
53 4179 : for( int i = 6; i > 0; i-- )
54 3582 : rOutStm << "**********";
55 597 : rOutStm << '/' << endl;
56 597 : }
57 :
58 59524 : sal_Bool SvMetaObject::TestAndSeekSpaceOnly( SvStream & rOutStm, sal_uLong nBegPos )
59 : {
60 : // write no empty brackets
61 59524 : sal_uLong nPos = rOutStm.Tell();
62 59524 : rOutStm.Seek( nBegPos );
63 59524 : sal_Bool bOnlySpace = sal_True;
64 344454 : while( bOnlySpace && rOutStm.Tell() < nPos )
65 : {
66 : char c;
67 225406 : rOutStm >> c;
68 225406 : if( !isspace( c ) )
69 24752 : bOnlySpace = sal_False;
70 : }
71 59524 : if( bOnlySpace )
72 : // nothing written
73 34772 : rOutStm.Seek( nBegPos );
74 : else
75 24752 : rOutStm.Seek( nPos );
76 59524 : return bOnlySpace;
77 : }
78 :
79 140 : void SvMetaObject::Back2Delemitter( SvStream & rOutStm )
80 : {
81 : // write no empty brackets
82 140 : sal_uLong nPos = rOutStm.Tell();
83 140 : rOutStm.SeekRel( -1 );
84 140 : char c = 0;
85 140 : rOutStm >> c;
86 :
87 420 : while( isspace( c ) && rOutStm.Tell() != 1 )
88 : {
89 140 : rOutStm.SeekRel( -2 );
90 140 : rOutStm >> c;
91 : }
92 :
93 140 : if( c == ';' || c == ',' )
94 140 : rOutStm.SeekRel( -1 );
95 : else
96 0 : rOutStm.Seek( nPos );
97 140 : }
98 :
99 0 : sal_Bool SvMetaObject::ReadSvIdl( SvIdlDataBase &, SvTokenStream & )
100 : {
101 0 : return sal_False;
102 : }
103 :
104 0 : void SvMetaObject::WriteSvIdl( SvIdlDataBase &, SvStream &, sal_uInt16 /*nTab */ )
105 : {
106 0 : }
107 :
108 0 : void SvMetaObject::Write( SvIdlDataBase &, SvStream &, sal_uInt16 /*nTab */,
109 : WriteType, WriteAttribute )
110 : {
111 0 : }
112 :
113 34598 : SV_IMPL_META_FACTORY1( SvMetaName, SvMetaObject );
114 29598 : SvMetaName::SvMetaName()
115 : {
116 29598 : }
117 :
118 0 : void SvMetaName::Load( SvPersistStream & rStm )
119 : {
120 0 : SvMetaObject::Load( rStm );
121 : sal_uInt8 nMask;
122 0 : rStm >> nMask;
123 :
124 0 : if( nMask >= 0x20 )
125 : {
126 0 : rStm.SetError( SVSTREAM_FILEFORMAT_ERROR );
127 : OSL_FAIL( "wrong format" );
128 0 : return;
129 : }
130 0 : if( nMask & 0x01 ) rStm >> aName;
131 0 : if( nMask & 0x02 ) rStm >> aHelpContext;
132 0 : if( nMask & 0x04 ) rStm >> aHelpText;
133 0 : if( nMask & 0x08 ) rStm >> aConfigName;
134 0 : if( nMask & 0x10 ) rStm >> aDescription;
135 : }
136 :
137 24368 : void SvMetaName::Save( SvPersistStream & rStm )
138 : {
139 24368 : SvMetaObject::Save( rStm );
140 24368 : sal_uInt8 nMask = 0;
141 24368 : if( aName.IsSet() ) nMask |= 0x01;
142 24368 : if( aHelpContext.IsSet() ) nMask |= 0x02;
143 24368 : if( aHelpText.IsSet() ) nMask |= 0x04;
144 24368 : if( aConfigName.IsSet() ) nMask |= 0x08;
145 24368 : if( aDescription.IsSet() ) nMask |= 0x10;
146 :
147 24368 : rStm << nMask;
148 24368 : if( nMask & 0x01 ) rStm << aName;
149 24368 : if( nMask & 0x02 ) rStm << aHelpContext;
150 24368 : if( nMask & 0x04 ) rStm << aHelpText;
151 24368 : if( nMask & 0x08 ) rStm << aConfigName;
152 24368 : if( nMask & 0x10 ) rStm << aDescription;
153 24368 : }
154 :
155 20026 : sal_Bool SvMetaName::SetName( const rtl::OString& rName, SvIdlDataBase * )
156 : {
157 20026 : aName.setString(rName);
158 20026 : return sal_True;
159 : }
160 :
161 16291 : sal_Bool SvMetaName::ReadNameSvIdl( SvIdlDataBase & rBase,
162 : SvTokenStream & rInStm )
163 : {
164 16291 : sal_uInt32 nTokPos = rInStm.Tell();
165 16291 : SvToken * pTok = rInStm.GetToken_Next();
166 :
167 : // read module name
168 16291 : if( pTok->IsIdentifier() )
169 16086 : if( SetName( pTok->GetString(), &rBase ) )
170 16086 : return sal_True;
171 :
172 205 : rInStm.Seek( nTokPos );
173 205 : return sal_False;
174 : }
175 :
176 160718 : void SvMetaName::ReadAttributesSvIdl( SvIdlDataBase & rBase,
177 : SvTokenStream & rInStm )
178 : {
179 160718 : sal_uInt32 nTokPos = rInStm.Tell();
180 160718 : if( aName.ReadSvIdl( SvHash_Name(), rInStm ) )
181 : {
182 0 : if( !SetName( aName.getString(), &rBase ) )
183 0 : rInStm.Seek( nTokPos );
184 : }
185 160718 : aHelpContext.ReadSvIdl( rBase, SvHash_HelpContext(), rInStm );
186 160718 : aHelpText.ReadSvIdl( rBase, rInStm );
187 160718 : aConfigName.ReadSvIdl( SvHash_ConfigName(), rInStm );
188 160718 : aDescription.ReadSvIdl( SvHash_Description(), rInStm );
189 160718 : }
190 :
191 5097 : void SvMetaName::DoReadContextSvIdl( SvIdlDataBase & rBase,
192 : SvTokenStream & rInStm, char cDel )
193 : {
194 5097 : sal_uInt32 nBeginPos = 0; // can not happen with Tell
195 25548 : while( nBeginPos != rInStm.Tell() )
196 : {
197 15354 : nBeginPos = rInStm.Tell();
198 15354 : ReadContextSvIdl( rBase, rInStm );
199 15354 : if( cDel == '\0' )
200 15354 : rInStm.ReadDelemiter();
201 : else
202 0 : rInStm.Read( cDel );
203 : }
204 5097 : }
205 :
206 0 : void SvMetaName::ReadContextSvIdl( SvIdlDataBase &, SvTokenStream & )
207 : {
208 0 : }
209 :
210 0 : sal_Bool SvMetaName::Test( SvIdlDataBase &, SvTokenStream & )
211 : {
212 0 : return sal_True;
213 : }
214 :
215 18126 : void SvMetaName::WriteContextSvIdl( SvIdlDataBase &, SvStream &, sal_uInt16 )
216 : {
217 18126 : }
218 :
219 0 : void SvMetaName::WriteDescription( SvStream & rOutStm )
220 : {
221 0 : rOutStm << "<DESCRIPTION>" << endl;
222 :
223 0 : rtl::OString aDesc( GetDescription().getString() );
224 0 : sal_Int32 nPos = aDesc.indexOf('\n');
225 0 : while ( nPos != -1 )
226 : {
227 0 : rOutStm << aDesc.copy( 0, nPos ).getStr() << endl;
228 0 : aDesc = aDesc.copy(nPos+1);
229 0 : nPos = aDesc.indexOf('\n');
230 : }
231 :
232 0 : rOutStm << aDesc.getStr() << endl << "</DESCRIPTION>" << endl;
233 0 : }
234 :
235 19977 : void SvMetaName::WriteAttributesSvIdl( SvIdlDataBase & rBase,
236 : SvStream & rOutStm,
237 : sal_uInt16 nTab )
238 : {
239 19977 : if( aHelpContext.IsSet() || aHelpText.IsSet() || aConfigName.IsSet() )
240 : {
241 8 : WriteTab( rOutStm, nTab );
242 8 : rOutStm << "// class SvMetaName" << endl;
243 : }
244 19977 : if( aHelpContext.IsSet() )
245 : {
246 0 : WriteTab( rOutStm, nTab );
247 0 : aHelpContext.WriteSvIdl( SvHash_HelpContext(), rOutStm, nTab );
248 0 : rOutStm << ';' << endl;
249 : }
250 19977 : if( aHelpText.IsSet() )
251 : {
252 8 : WriteTab( rOutStm, nTab );
253 8 : aHelpText.WriteSvIdl( rBase, rOutStm, nTab );
254 8 : rOutStm << ';' << endl;
255 : }
256 19977 : if( aConfigName.IsSet() )
257 : {
258 0 : WriteTab( rOutStm, nTab );
259 0 : aConfigName.WriteSvIdl( SvHash_ConfigName(), rOutStm, nTab );
260 0 : rOutStm << ';' << endl;
261 : }
262 19977 : }
263 :
264 18457 : sal_Bool SvMetaName::ReadSvIdl( SvIdlDataBase & rBase, SvTokenStream & rInStm )
265 : {
266 18457 : sal_uInt32 nTokPos = rInStm.Tell();
267 18457 : sal_Bool bOk = sal_True;
268 18457 : if( rInStm.Read( '[' ) )
269 : {
270 11947 : sal_uInt32 nBeginPos = 0; // can not happen with Tell
271 184612 : while( nBeginPos != rInStm.Tell() )
272 : {
273 160718 : nBeginPos = rInStm.Tell();
274 160718 : ReadAttributesSvIdl( rBase, rInStm );
275 160718 : rInStm.ReadDelemiter();
276 : }
277 11947 : bOk = rInStm.Read( ']' );
278 : }
279 :
280 18457 : if( bOk )
281 : {
282 18457 : if( rInStm.Read( '{' ) )
283 : {
284 714 : DoReadContextSvIdl( rBase, rInStm );
285 714 : bOk = rInStm.Read( '}' );
286 : }
287 : }
288 :
289 18457 : if( !bOk )
290 0 : rInStm.Seek( nTokPos );
291 18457 : return bOk;
292 : }
293 :
294 19977 : void SvMetaName::WriteSvIdl( SvIdlDataBase & rBase, SvStream & rOutStm,
295 : sal_uInt16 nTab )
296 : {
297 19977 : sal_uLong nBeginPos = rOutStm.Tell();
298 19977 : WriteTab( rOutStm, nTab );
299 19977 : rOutStm << '[' << endl;
300 19977 : sal_uLong nOldPos = rOutStm.Tell();
301 19977 : WriteAttributesSvIdl( rBase, rOutStm, nTab +1 );
302 :
303 : // write no empty brackets
304 19977 : if( TestAndSeekSpaceOnly( rOutStm, nOldPos ) )
305 : // nothing written
306 7952 : rOutStm.Seek( nBeginPos );
307 : else
308 : {
309 12025 : WriteTab( rOutStm, nTab );
310 12025 : rOutStm << ']';
311 12025 : nBeginPos = rOutStm.Tell();
312 12025 : rOutStm << endl;
313 : }
314 :
315 19977 : WriteTab( rOutStm, nTab );
316 19977 : rOutStm << '{' << endl;
317 19977 : nOldPos = rOutStm.Tell();
318 19977 : WriteContextSvIdl( rBase, rOutStm, nTab +1 );
319 :
320 : // write no empty brackets
321 19977 : if( TestAndSeekSpaceOnly( rOutStm, nOldPos ) )
322 : // nothing written
323 19278 : rOutStm.Seek( nBeginPos );
324 : else
325 : {
326 699 : WriteTab( rOutStm, nTab );
327 699 : rOutStm << '}';
328 : }
329 19977 : }
330 :
331 0 : void SvMetaName::Write( SvIdlDataBase & rBase, SvStream & rOutStm,
332 : sal_uInt16 nTab,
333 : WriteType nT, WriteAttribute nA )
334 : {
335 0 : sal_uLong nBeginPos = rOutStm.Tell();
336 0 : WriteTab( rOutStm, nTab );
337 0 : rOutStm << '[' << endl;
338 0 : sal_uLong nOldPos = rOutStm.Tell();
339 0 : WriteAttributes( rBase, rOutStm, nTab +1, nT, nA );
340 :
341 : // write no empty brackets
342 0 : sal_uLong nPos = rOutStm.Tell();
343 0 : rOutStm.Seek( nOldPos );
344 0 : sal_Bool bOnlySpace = sal_True;
345 0 : while( bOnlySpace && rOutStm.Tell() < nPos )
346 : {
347 : char c;
348 0 : rOutStm >> c;
349 0 : if( !isspace( c ) )
350 0 : bOnlySpace = sal_False;
351 : }
352 0 : if( bOnlySpace )
353 : // nothing written
354 0 : rOutStm.Seek( nBeginPos );
355 : else
356 : {
357 0 : rOutStm.Seek( nPos );
358 0 : WriteTab( rOutStm, nTab );
359 0 : rOutStm << ']' << endl;
360 : }
361 0 : }
362 :
363 0 : void SvMetaName::WriteAttributes( SvIdlDataBase &, SvStream & rOutStm,
364 : sal_uInt16 nTab,
365 : WriteType, WriteAttribute )
366 : {
367 0 : if( GetHelpText().IsSet() || GetHelpContext().IsSet() )
368 : {
369 0 : WriteTab( rOutStm, nTab );
370 0 : rOutStm << "// class SvMetaName" << endl;
371 : }
372 0 : if( GetHelpText().IsSet() )
373 : {
374 0 : WriteTab( rOutStm, nTab );
375 0 : rOutStm << "helpstring(\"" << GetHelpText().getString().getStr() << "\")," << endl;
376 : }
377 0 : if( GetHelpContext().IsSet() )
378 : {
379 0 : WriteTab( rOutStm, nTab );
380 0 : rOutStm << "helpcontext("
381 : << rtl::OString::valueOf(static_cast<sal_Int64>(
382 0 : GetHelpContext().GetValue())).getStr()
383 0 : << ")," << endl;
384 : }
385 0 : }
386 :
387 0 : void SvMetaName::WriteContext( SvIdlDataBase &, SvStream &,
388 : sal_uInt16,
389 : WriteType, WriteAttribute )
390 : {
391 0 : }
392 :
393 34598 : SV_IMPL_META_FACTORY1( SvMetaReference, SvMetaName );
394 :
395 27969 : SvMetaReference::SvMetaReference()
396 : {
397 27969 : }
398 :
399 0 : void SvMetaReference::Load( SvPersistStream & rStm )
400 : {
401 0 : SvMetaName::Load( rStm );
402 :
403 : sal_uInt8 nMask;
404 0 : rStm >> nMask;
405 0 : if( nMask >= 0x2 )
406 : {
407 0 : rStm.SetError( SVSTREAM_FILEFORMAT_ERROR );
408 : OSL_FAIL( "wrong format" );
409 0 : return;
410 : }
411 0 : if( nMask & 0x01 )
412 : {
413 : SvMetaReference * pRef;
414 0 : rStm >> pRef;
415 0 : aRef = pRef;
416 : }
417 : }
418 :
419 22944 : void SvMetaReference::Save( SvPersistStream & rStm )
420 : {
421 22944 : SvMetaName::Save( rStm );
422 :
423 : // create mask
424 22944 : sal_uInt8 nMask = 0;
425 22944 : if( aRef.Is() )
426 9364 : nMask |= 0x01;
427 :
428 : // write data
429 22944 : rStm << nMask;
430 22944 : if( nMask & 0x01 ) rStm << aRef;
431 22944 : }
432 :
433 34566 : SV_IMPL_META_FACTORY1( SvMetaExtern, SvMetaReference );
434 :
435 6346 : SvMetaExtern::SvMetaExtern()
436 : : pModule( NULL )
437 : , bReadUUId( sal_False )
438 6346 : , bReadVersion( sal_False )
439 : {
440 6346 : }
441 :
442 0 : void SvMetaExtern::Load( SvPersistStream & rStm )
443 : {
444 0 : SvMetaReference::Load( rStm );
445 :
446 : sal_uInt8 nMask;
447 0 : rStm >> nMask;
448 0 : if( nMask >= 0x20 )
449 : {
450 0 : rStm.SetError( SVSTREAM_FILEFORMAT_ERROR );
451 : OSL_FAIL( "wrong format" );
452 0 : return;
453 : }
454 0 : if( nMask & 0x01 ) rStm >> pModule;
455 0 : if( nMask & 0x02 ) rStm >> aUUId;
456 0 : if( nMask & 0x04 ) rStm >> aVersion;
457 0 : if( nMask & 0x08 ) bReadUUId = sal_True;
458 0 : if( nMask & 0x10 ) bReadVersion = sal_True;
459 : }
460 :
461 6346 : void SvMetaExtern::Save( SvPersistStream & rStm )
462 : {
463 6346 : SvMetaReference::Save( rStm );
464 :
465 : // create mask
466 6346 : sal_uInt8 nMask = 0;
467 6346 : if( pModule ) nMask |= 0x01;
468 6346 : if( aUUId != SvGlobalName() ) nMask |= 0x02;
469 6346 : if( aVersion != SvVersion() ) nMask |= 0x04;
470 6346 : if( bReadUUId ) nMask |= 0x08;
471 6346 : if( bReadVersion ) nMask |= 0x10;
472 :
473 : // write data
474 6346 : rStm << nMask;
475 6346 : if( nMask & 0x01 ) rStm << pModule;
476 6346 : if( nMask & 0x02 ) rStm << aUUId;
477 6346 : if( nMask & 0x04 ) rStm << aVersion;
478 6346 : }
479 :
480 1452 : SvMetaModule * SvMetaExtern::GetModule() const
481 : {
482 : DBG_ASSERT( pModule != NULL, "module not set" );
483 1452 : return pModule;
484 : }
485 :
486 1452 : const SvGlobalName & SvMetaExtern::GetUUId() const
487 : {
488 1452 : if( aUUId == SvGlobalName() )
489 1452 : GetModule()->FillNextName( &((SvMetaExtern *)this)->aUUId );
490 1452 : return aUUId;
491 : }
492 :
493 3311 : void SvMetaExtern::SetModule( SvIdlDataBase & rBase )
494 : {
495 3311 : pModule = (SvMetaModule *)rBase.GetStack().Get( TYPE( SvMetaModule ) );
496 3311 : }
497 :
498 203 : void SvMetaExtern::ReadAttributesSvIdl( SvIdlDataBase & rBase,
499 : SvTokenStream & rInStm )
500 : {
501 203 : SvMetaReference::ReadAttributesSvIdl( rBase, rInStm );
502 203 : if( aUUId.ReadSvIdl( rBase, rInStm ) )
503 68 : bReadUUId = sal_True;
504 203 : if( aVersion.ReadSvIdl( rInStm ) )
505 0 : bReadVersion = sal_True;
506 203 : }
507 :
508 1859 : void SvMetaExtern::WriteAttributesSvIdl( SvIdlDataBase & rBase,
509 : SvStream & rOutStm, sal_uInt16 nTab )
510 : {
511 1859 : SvMetaReference::WriteAttributesSvIdl( rBase, rOutStm, nTab );
512 1859 : if( bReadUUId || bReadVersion )
513 : {
514 68 : WriteTab( rOutStm, nTab );
515 68 : rOutStm << "// class SvMetaExtern" << endl;
516 :
517 68 : if( bReadUUId )
518 : {
519 68 : WriteTab( rOutStm, nTab );
520 68 : aUUId.WriteSvIdl( rOutStm );
521 68 : rOutStm << ';' << endl;
522 : }
523 68 : if( bReadVersion )
524 : {
525 0 : WriteTab( rOutStm, nTab );
526 0 : aVersion.WriteSvIdl( rOutStm );
527 0 : rOutStm << ';' << endl;
528 : }
529 : }
530 1859 : }
531 :
532 1452 : sal_Bool SvMetaExtern::ReadSvIdl( SvIdlDataBase & rBase, SvTokenStream & rInStm )
533 : {
534 1452 : SetModule( rBase );
535 1452 : GetUUId(); // id gets created
536 1452 : return SvMetaReference::ReadSvIdl( rBase, rInStm );
537 : }
538 :
539 1460 : void SvMetaExtern::WriteSvIdl( SvIdlDataBase & rBase, SvStream & rOutStm,
540 : sal_uInt16 nTab )
541 : {
542 1460 : SvMetaReference::WriteSvIdl( rBase, rOutStm, nTab );
543 1460 : }
544 :
545 0 : void SvMetaExtern::Write( SvIdlDataBase & rBase, SvStream & rOutStm,
546 : sal_uInt16 nTab,
547 : WriteType nT, WriteAttribute nA )
548 : {
549 0 : SvMetaReference::Write( rBase, rOutStm, nTab, nT, nA );
550 0 : }
551 :
552 0 : void SvMetaExtern::WriteAttributes( SvIdlDataBase & rBase, SvStream & rOutStm,
553 : sal_uInt16 nTab,
554 : WriteType nT, WriteAttribute nA )
555 : {
556 0 : SvMetaReference::WriteAttributes( rBase, rOutStm, nTab, nT, nA );
557 :
558 0 : WriteTab( rOutStm, nTab );
559 0 : rOutStm << "// class SvMetaExtern" << endl;
560 0 : WriteTab( rOutStm, nTab );
561 0 : rOutStm << "uuid(" << rtl::OUStringToOString(GetUUId().GetHexName(), RTL_TEXTENCODING_UTF8).getStr() << ")," << endl;
562 0 : WriteTab( rOutStm, nTab );
563 0 : rOutStm << "version("
564 0 : << rtl::OString::valueOf(static_cast<sal_Int32>(aVersion.GetMajorVersion())).getStr()
565 0 : << '.'
566 0 : << rtl::OString::valueOf(static_cast<sal_Int32>(aVersion.GetMinorVersion())).getStr()
567 0 : << ")," << endl;
568 0 : }
569 :
570 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|