Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / idl / source / objects / basobj.cxx
blob8ad1b08a52810c0b6aa410f20b8ba1681ae0d30d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <ctype.h>
31 #include <stdio.h>
33 #include <tools/debug.hxx>
35 #include <basobj.hxx>
36 #include <module.hxx>
37 #include <globals.hxx>
38 #include <database.hxx>
40 SV_IMPL_META_FACTORY1( SvMetaObject, SvRttiBase )
41 SvMetaObject::SvMetaObject()
45 void SvMetaObject::Load( SvPersistStream & )
49 void SvMetaObject::Save( SvPersistStream & )
53 void SvMetaObject::WriteTab( SvStream & rOutStm, sal_uInt16 nTab )
55 while( nTab-- )
56 rOutStm << " ";
59 void SvMetaObject::WriteStars( SvStream & rOutStm )
61 rOutStm << '/';
62 for( int i = 6; i > 0; i-- )
63 rOutStm << "**********";
64 rOutStm << '/' << endl;
67 sal_Bool SvMetaObject::TestAndSeekSpaceOnly( SvStream & rOutStm, sal_uLong nBegPos )
69 // write no empty brackets
70 sal_uLong nPos = rOutStm.Tell();
71 rOutStm.Seek( nBegPos );
72 sal_Bool bOnlySpace = sal_True;
73 while( bOnlySpace && rOutStm.Tell() < nPos )
75 char c;
76 rOutStm >> c;
77 if( !isspace( c ) )
78 bOnlySpace = sal_False;
80 if( bOnlySpace )
81 // nothing written
82 rOutStm.Seek( nBegPos );
83 else
84 rOutStm.Seek( nPos );
85 return bOnlySpace;
88 void SvMetaObject::Back2Delemitter( SvStream & rOutStm )
90 // write no empty brackets
91 sal_uLong nPos = rOutStm.Tell();
92 rOutStm.SeekRel( -1 );
93 char c = 0;
94 rOutStm >> c;
96 while( isspace( c ) && rOutStm.Tell() != 1 )
98 rOutStm.SeekRel( -2 );
99 rOutStm >> c;
102 if( c == ';' || c == ',' )
103 rOutStm.SeekRel( -1 );
104 else
105 rOutStm.Seek( nPos );
108 sal_Bool SvMetaObject::ReadSvIdl( SvIdlDataBase &, SvTokenStream & )
110 return sal_False;
113 void SvMetaObject::WriteSvIdl( SvIdlDataBase &, SvStream &, sal_uInt16 /*nTab */ )
117 void SvMetaObject::Write( SvIdlDataBase &, SvStream &, sal_uInt16 /*nTab */,
118 WriteType, WriteAttribute )
122 SV_IMPL_META_FACTORY1( SvMetaName, SvMetaObject );
123 SvMetaName::SvMetaName()
127 void SvMetaName::Load( SvPersistStream & rStm )
129 SvMetaObject::Load( rStm );
130 sal_uInt8 nMask;
131 rStm >> nMask;
133 if( nMask >= 0x20 )
135 rStm.SetError( SVSTREAM_FILEFORMAT_ERROR );
136 OSL_FAIL( "wrong format" );
137 return;
139 if( nMask & 0x01 ) rStm >> aName;
140 if( nMask & 0x02 ) rStm >> aHelpContext;
141 if( nMask & 0x04 ) rStm >> aHelpText;
142 if( nMask & 0x08 ) rStm >> aConfigName;
143 if( nMask & 0x10 ) rStm >> aDescription;
146 void SvMetaName::Save( SvPersistStream & rStm )
148 SvMetaObject::Save( rStm );
149 sal_uInt8 nMask = 0;
150 if( aName.IsSet() ) nMask |= 0x01;
151 if( aHelpContext.IsSet() ) nMask |= 0x02;
152 if( aHelpText.IsSet() ) nMask |= 0x04;
153 if( aConfigName.IsSet() ) nMask |= 0x08;
154 if( aDescription.IsSet() ) nMask |= 0x10;
156 rStm << nMask;
157 if( nMask & 0x01 ) rStm << aName;
158 if( nMask & 0x02 ) rStm << aHelpContext;
159 if( nMask & 0x04 ) rStm << aHelpText;
160 if( nMask & 0x08 ) rStm << aConfigName;
161 if( nMask & 0x10 ) rStm << aDescription;
164 sal_Bool SvMetaName::SetName( const rtl::OString& rName, SvIdlDataBase * )
166 aName.setString(rName);
167 return sal_True;
170 sal_Bool SvMetaName::ReadNameSvIdl( SvIdlDataBase & rBase,
171 SvTokenStream & rInStm )
173 sal_uInt32 nTokPos = rInStm.Tell();
174 SvToken * pTok = rInStm.GetToken_Next();
176 // read module name
177 if( pTok->IsIdentifier() )
178 if( SetName( pTok->GetString(), &rBase ) )
179 return sal_True;
181 rInStm.Seek( nTokPos );
182 return sal_False;
185 void SvMetaName::ReadAttributesSvIdl( SvIdlDataBase & rBase,
186 SvTokenStream & rInStm )
188 sal_uInt32 nTokPos = rInStm.Tell();
189 if( aName.ReadSvIdl( SvHash_Name(), rInStm ) )
191 if( !SetName( aName.getString(), &rBase ) )
192 rInStm.Seek( nTokPos );
194 aHelpContext.ReadSvIdl( rBase, SvHash_HelpContext(), rInStm );
195 aHelpText.ReadSvIdl( rBase, rInStm );
196 aConfigName.ReadSvIdl( SvHash_ConfigName(), rInStm );
197 aDescription.ReadSvIdl( SvHash_Description(), rInStm );
200 void SvMetaName::DoReadContextSvIdl( SvIdlDataBase & rBase,
201 SvTokenStream & rInStm, char cDel )
203 sal_uInt32 nBeginPos = 0; // can not happen with Tell
204 while( nBeginPos != rInStm.Tell() )
206 nBeginPos = rInStm.Tell();
207 ReadContextSvIdl( rBase, rInStm );
208 if( cDel == '\0' )
209 rInStm.ReadDelemiter();
210 else
211 rInStm.Read( cDel );
215 void SvMetaName::ReadContextSvIdl( SvIdlDataBase &, SvTokenStream & )
219 sal_Bool SvMetaName::Test( SvIdlDataBase &, SvTokenStream & )
221 return sal_True;
224 void SvMetaName::WriteContextSvIdl( SvIdlDataBase &, SvStream &, sal_uInt16 )
228 void SvMetaName::WriteDescription( SvStream & rOutStm )
230 rOutStm << "<DESCRIPTION>" << endl;
232 rtl::OString aDesc( GetDescription().getString() );
233 sal_Int32 nPos = aDesc.indexOf('\n');
234 while ( nPos != -1 )
236 rOutStm << aDesc.copy( 0, nPos ).getStr() << endl;
237 aDesc = aDesc.copy(nPos+1);
238 nPos = aDesc.indexOf('\n');
241 rOutStm << aDesc.getStr() << endl << "</DESCRIPTION>" << endl;
244 void SvMetaName::WriteAttributesSvIdl( SvIdlDataBase & rBase,
245 SvStream & rOutStm,
246 sal_uInt16 nTab )
248 if( aHelpContext.IsSet() || aHelpText.IsSet() || aConfigName.IsSet() )
250 WriteTab( rOutStm, nTab );
251 rOutStm << "// class SvMetaName" << endl;
253 if( aHelpContext.IsSet() )
255 WriteTab( rOutStm, nTab );
256 aHelpContext.WriteSvIdl( SvHash_HelpContext(), rOutStm, nTab );
257 rOutStm << ';' << endl;
259 if( aHelpText.IsSet() )
261 WriteTab( rOutStm, nTab );
262 aHelpText.WriteSvIdl( rBase, rOutStm, nTab );
263 rOutStm << ';' << endl;
265 if( aConfigName.IsSet() )
267 WriteTab( rOutStm, nTab );
268 aConfigName.WriteSvIdl( SvHash_ConfigName(), rOutStm, nTab );
269 rOutStm << ';' << endl;
273 sal_Bool SvMetaName::ReadSvIdl( SvIdlDataBase & rBase, SvTokenStream & rInStm )
275 sal_uInt32 nTokPos = rInStm.Tell();
276 sal_Bool bOk = sal_True;
277 if( rInStm.Read( '[' ) )
279 sal_uInt32 nBeginPos = 0; // can not happen with Tell
280 while( nBeginPos != rInStm.Tell() )
282 nBeginPos = rInStm.Tell();
283 ReadAttributesSvIdl( rBase, rInStm );
284 rInStm.ReadDelemiter();
286 bOk = rInStm.Read( ']' );
289 if( bOk )
291 if( rInStm.Read( '{' ) )
293 DoReadContextSvIdl( rBase, rInStm );
294 bOk = rInStm.Read( '}' );
298 if( !bOk )
299 rInStm.Seek( nTokPos );
300 return bOk;
303 void SvMetaName::WriteSvIdl( SvIdlDataBase & rBase, SvStream & rOutStm,
304 sal_uInt16 nTab )
306 sal_uLong nBeginPos = rOutStm.Tell();
307 WriteTab( rOutStm, nTab );
308 rOutStm << '[' << endl;
309 sal_uLong nOldPos = rOutStm.Tell();
310 WriteAttributesSvIdl( rBase, rOutStm, nTab +1 );
312 // write no empty brackets
313 if( TestAndSeekSpaceOnly( rOutStm, nOldPos ) )
314 // nothing written
315 rOutStm.Seek( nBeginPos );
316 else
318 WriteTab( rOutStm, nTab );
319 rOutStm << ']';
320 nBeginPos = rOutStm.Tell();
321 rOutStm << endl;
324 WriteTab( rOutStm, nTab );
325 rOutStm << '{' << endl;
326 nOldPos = rOutStm.Tell();
327 WriteContextSvIdl( rBase, rOutStm, nTab +1 );
329 // write no empty brackets
330 if( TestAndSeekSpaceOnly( rOutStm, nOldPos ) )
331 // nothing written
332 rOutStm.Seek( nBeginPos );
333 else
335 WriteTab( rOutStm, nTab );
336 rOutStm << '}';
340 void SvMetaName::Write( SvIdlDataBase & rBase, SvStream & rOutStm,
341 sal_uInt16 nTab,
342 WriteType nT, WriteAttribute nA )
344 sal_uLong nBeginPos = rOutStm.Tell();
345 WriteTab( rOutStm, nTab );
346 rOutStm << '[' << endl;
347 sal_uLong nOldPos = rOutStm.Tell();
348 WriteAttributes( rBase, rOutStm, nTab +1, nT, nA );
350 // write no empty brackets
351 sal_uLong nPos = rOutStm.Tell();
352 rOutStm.Seek( nOldPos );
353 sal_Bool bOnlySpace = sal_True;
354 while( bOnlySpace && rOutStm.Tell() < nPos )
356 char c;
357 rOutStm >> c;
358 if( !isspace( c ) )
359 bOnlySpace = sal_False;
361 if( bOnlySpace )
362 // nothing written
363 rOutStm.Seek( nBeginPos );
364 else
366 rOutStm.Seek( nPos );
367 WriteTab( rOutStm, nTab );
368 rOutStm << ']' << endl;
372 void SvMetaName::WriteAttributes( SvIdlDataBase &, SvStream & rOutStm,
373 sal_uInt16 nTab,
374 WriteType, WriteAttribute )
376 if( GetHelpText().IsSet() || GetHelpContext().IsSet() )
378 WriteTab( rOutStm, nTab );
379 rOutStm << "// class SvMetaName" << endl;
381 if( GetHelpText().IsSet() )
383 WriteTab( rOutStm, nTab );
384 rOutStm << "helpstring(\"" << GetHelpText().getString().getStr() << "\")," << endl;
386 if( GetHelpContext().IsSet() )
388 WriteTab( rOutStm, nTab );
389 rOutStm << "helpcontext("
390 << rtl::OString::valueOf(static_cast<sal_Int64>(
391 GetHelpContext().GetValue())).getStr()
392 << ")," << endl;
396 void SvMetaName::WriteContext( SvIdlDataBase &, SvStream &,
397 sal_uInt16,
398 WriteType, WriteAttribute )
402 SV_IMPL_META_FACTORY1( SvMetaReference, SvMetaName );
404 SvMetaReference::SvMetaReference()
408 void SvMetaReference::Load( SvPersistStream & rStm )
410 SvMetaName::Load( rStm );
412 sal_uInt8 nMask;
413 rStm >> nMask;
414 if( nMask >= 0x2 )
416 rStm.SetError( SVSTREAM_FILEFORMAT_ERROR );
417 OSL_FAIL( "wrong format" );
418 return;
420 if( nMask & 0x01 )
422 SvMetaReference * pRef;
423 rStm >> pRef;
424 aRef = pRef;
428 void SvMetaReference::Save( SvPersistStream & rStm )
430 SvMetaName::Save( rStm );
432 // create mask
433 sal_uInt8 nMask = 0;
434 if( aRef.Is() )
435 nMask |= 0x01;
437 // write data
438 rStm << nMask;
439 if( nMask & 0x01 ) rStm << aRef;
442 SV_IMPL_META_FACTORY1( SvMetaExtern, SvMetaReference );
444 SvMetaExtern::SvMetaExtern()
445 : pModule( NULL )
446 , bReadUUId( sal_False )
447 , bReadVersion( sal_False )
451 void SvMetaExtern::Load( SvPersistStream & rStm )
453 SvMetaReference::Load( rStm );
455 sal_uInt8 nMask;
456 rStm >> nMask;
457 if( nMask >= 0x20 )
459 rStm.SetError( SVSTREAM_FILEFORMAT_ERROR );
460 OSL_FAIL( "wrong format" );
461 return;
463 if( nMask & 0x01 ) rStm >> pModule;
464 if( nMask & 0x02 ) rStm >> aUUId;
465 if( nMask & 0x04 ) rStm >> aVersion;
466 if( nMask & 0x08 ) bReadUUId = sal_True;
467 if( nMask & 0x10 ) bReadVersion = sal_True;
470 void SvMetaExtern::Save( SvPersistStream & rStm )
472 SvMetaReference::Save( rStm );
474 // create mask
475 sal_uInt8 nMask = 0;
476 if( pModule ) nMask |= 0x01;
477 if( aUUId != SvGlobalName() ) nMask |= 0x02;
478 if( aVersion != SvVersion() ) nMask |= 0x04;
479 if( bReadUUId ) nMask |= 0x08;
480 if( bReadVersion ) nMask |= 0x10;
482 // write data
483 rStm << nMask;
484 if( nMask & 0x01 ) rStm << pModule;
485 if( nMask & 0x02 ) rStm << aUUId;
486 if( nMask & 0x04 ) rStm << aVersion;
489 SvMetaModule * SvMetaExtern::GetModule() const
491 DBG_ASSERT( pModule != NULL, "module not set" );
492 return pModule;
495 const SvGlobalName & SvMetaExtern::GetUUId() const
497 if( aUUId == SvGlobalName() )
498 GetModule()->FillNextName( &((SvMetaExtern *)this)->aUUId );
499 return aUUId;
502 void SvMetaExtern::SetModule( SvIdlDataBase & rBase )
504 pModule = (SvMetaModule *)rBase.GetStack().Get( TYPE( SvMetaModule ) );
507 void SvMetaExtern::ReadAttributesSvIdl( SvIdlDataBase & rBase,
508 SvTokenStream & rInStm )
510 SvMetaReference::ReadAttributesSvIdl( rBase, rInStm );
511 if( aUUId.ReadSvIdl( rBase, rInStm ) )
512 bReadUUId = sal_True;
513 if( aVersion.ReadSvIdl( rInStm ) )
514 bReadVersion = sal_True;
517 void SvMetaExtern::WriteAttributesSvIdl( SvIdlDataBase & rBase,
518 SvStream & rOutStm, sal_uInt16 nTab )
520 SvMetaReference::WriteAttributesSvIdl( rBase, rOutStm, nTab );
521 if( bReadUUId || bReadVersion )
523 WriteTab( rOutStm, nTab );
524 rOutStm << "// class SvMetaExtern" << endl;
526 if( bReadUUId )
528 WriteTab( rOutStm, nTab );
529 aUUId.WriteSvIdl( rOutStm );
530 rOutStm << ';' << endl;
532 if( bReadVersion )
534 WriteTab( rOutStm, nTab );
535 aVersion.WriteSvIdl( rOutStm );
536 rOutStm << ';' << endl;
541 sal_Bool SvMetaExtern::ReadSvIdl( SvIdlDataBase & rBase, SvTokenStream & rInStm )
543 SetModule( rBase );
544 GetUUId(); // id gets created
545 return SvMetaReference::ReadSvIdl( rBase, rInStm );
548 void SvMetaExtern::WriteSvIdl( SvIdlDataBase & rBase, SvStream & rOutStm,
549 sal_uInt16 nTab )
551 SvMetaReference::WriteSvIdl( rBase, rOutStm, nTab );
554 void SvMetaExtern::Write( SvIdlDataBase & rBase, SvStream & rOutStm,
555 sal_uInt16 nTab,
556 WriteType nT, WriteAttribute nA )
558 SvMetaReference::Write( rBase, rOutStm, nTab, nT, nA );
561 void SvMetaExtern::WriteAttributes( SvIdlDataBase & rBase, SvStream & rOutStm,
562 sal_uInt16 nTab,
563 WriteType nT, WriteAttribute nA )
565 SvMetaReference::WriteAttributes( rBase, rOutStm, nTab, nT, nA );
567 WriteTab( rOutStm, nTab );
568 rOutStm << "// class SvMetaExtern" << endl;
569 WriteTab( rOutStm, nTab );
570 rOutStm << "uuid(" << rtl::OUStringToOString(GetUUId().GetHexName(), RTL_TEXTENCODING_UTF8).getStr() << ")," << endl;
571 WriteTab( rOutStm, nTab );
572 rOutStm << "version("
573 << rtl::OString::valueOf(static_cast<sal_Int32>(aVersion.GetMajorVersion())).getStr()
574 << '.'
575 << rtl::OString::valueOf(static_cast<sal_Int32>(aVersion.GetMinorVersion())).getStr()
576 << ")," << endl;
579 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */