Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / idl / source / objects / types.cxx
blob4e0313a774df104e84b122c9c6597ee61617e3b7
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 <types.hxx>
36 #include <globals.hxx>
37 #include <database.hxx>
39 SV_IMPL_META_FACTORY1( SvMetaAttribute, SvMetaReference );
40 SvMetaAttribute::SvMetaAttribute()
41 : aAutomation( sal_True, sal_False )
42 , aExport( sal_True, sal_False )
43 , aIsCollection ( sal_False, sal_False )
44 , aReadOnlyDoc ( sal_True, sal_False )
45 , aHidden( sal_False, sal_False )
46 , bNewAttr( sal_False )
50 SvMetaAttribute::SvMetaAttribute( SvMetaType * pType )
51 : aType( pType )
52 , aAutomation( sal_True, sal_False )
53 , aExport( sal_True, sal_False )
54 , aIsCollection ( sal_False, sal_False)
55 , aReadOnlyDoc ( sal_True, sal_False)
56 , aHidden( sal_False, sal_False )
57 , bNewAttr( sal_False )
61 void SvMetaAttribute::Load( SvPersistStream & rStm )
63 SvMetaReference::Load( rStm );
65 sal_uInt8 nMask;
66 rStm >> nMask;
67 if( nMask & 0x01 )
69 SvMetaType * pType;
70 rStm >> pType;
71 aType = pType;
73 if( nMask & 0x02 ) rStm >> aSlotId;
74 if( nMask & 0x04 ) rStm >> aExport;
75 if( nMask & 0x08 ) rStm >> aReadonly;
76 if( nMask & 0x10 ) rStm >> aAutomation;
77 if( nMask & 0x20 ) rStm >> aIsCollection;
78 if( nMask & 0x40 ) rStm >> aReadOnlyDoc;
79 if( nMask & 0x80 ) rStm >> aHidden;
82 void SvMetaAttribute::Save( SvPersistStream & rStm )
84 SvMetaReference::Save( rStm );
86 // create mask
87 sal_uInt8 nMask = 0;
88 if( aType.Is() ) nMask |= 0x1;
89 if( aSlotId.IsSet() ) nMask |= 0x2;
90 if( aExport.IsSet() ) nMask |= 0x4;
91 if( aReadonly.IsSet() ) nMask |= 0x8;
92 if( aAutomation.IsSet() ) nMask |= 0x10;
93 if( aIsCollection.IsSet() ) nMask |= 0x20;
94 if( aReadOnlyDoc.IsSet() ) nMask |= 0x40;
95 if( aHidden.IsSet() ) nMask |= 0x80;
97 // write data
98 rStm << nMask;
99 if( nMask & 0x1 ) rStm << aType;
100 if( nMask & 0x2 ) rStm << aSlotId;
101 if( nMask & 0x4 ) rStm << aExport;
102 if( nMask & 0x8 ) rStm << aReadonly;
103 if( nMask & 0x10 ) rStm << aAutomation;
104 if( nMask & 0x20 ) rStm << aIsCollection;
105 if( nMask & 0x40 ) rStm << aReadOnlyDoc;
106 if( nMask & 0x80 ) rStm << aHidden;
109 SvMetaType * SvMetaAttribute::GetType() const
111 if( aType.Is() || !GetRef() ) return aType;
112 return ((SvMetaAttribute *)GetRef())->GetType();
115 const SvNumberIdentifier & SvMetaAttribute::GetSlotId() const
117 if( aSlotId.IsSet() || !GetRef() ) return aSlotId;
118 return ((SvMetaAttribute *)GetRef())->GetSlotId();
121 sal_Bool SvMetaAttribute::GetReadonly() const
123 if( aReadonly.IsSet() || !GetRef() ) return aReadonly;
124 return ((SvMetaAttribute *)GetRef())->GetReadonly();
127 sal_Bool SvMetaAttribute::GetExport() const
129 if( aExport.IsSet() || !GetRef() ) return aExport;
130 return ((SvMetaAttribute *)GetRef())->GetExport();
133 sal_Bool SvMetaAttribute::GetHidden() const
135 // when export is set, but hidden is not the default is used
136 if ( aExport.IsSet() && !aHidden.IsSet() )
137 return !aExport;
138 else if( aHidden.IsSet() || !GetRef() )
139 return aHidden;
140 else
141 return ((SvMetaAttribute *)GetRef())->GetHidden();
144 sal_Bool SvMetaAttribute::GetAutomation() const
146 if( aAutomation.IsSet() || !GetRef() ) return aAutomation;
147 return ((SvMetaAttribute *)GetRef())->GetAutomation();
150 sal_Bool SvMetaAttribute::GetIsCollection() const
152 sal_Bool bRet;
153 if( aIsCollection.IsSet() || !GetRef() )
155 if ( aIsCollection.IsSet() )
157 bRet = aIsCollection;
158 return bRet;
161 return aIsCollection;
164 return ((SvMetaSlot *)GetRef())->GetIsCollection();
167 sal_Bool SvMetaAttribute::GetReadOnlyDoc() const
169 if( aReadOnlyDoc.IsSet() || !GetRef() ) return aReadOnlyDoc;
170 return ((SvMetaSlot *)GetRef())->GetReadOnlyDoc();
173 sal_Bool SvMetaAttribute::IsMethod() const
175 SvMetaType * pType = GetType();
176 DBG_ASSERT( pType, "no type for attribute" );
177 return pType->GetType() == TYPE_METHOD;
180 sal_Bool SvMetaAttribute::IsVariable() const
182 SvMetaType * pType = GetType();
183 return pType->GetType() != TYPE_METHOD;
186 rtl::OString SvMetaAttribute::GetMangleName( sal_Bool ) const
188 return GetName().getString();
191 sal_Bool SvMetaAttribute::Test( SvIdlDataBase & rBase,
192 SvTokenStream & rInStm )
194 sal_Bool bOk = sal_True;
195 if( GetType()->IsItem() && !GetSlotId().IsSet() )
197 rBase.SetError( "slot without id declared", rInStm.GetToken() );
198 rBase.WriteError( rInStm );
199 bOk = sal_False;
201 return bOk;
204 sal_Bool SvMetaAttribute::ReadSvIdl( SvIdlDataBase & rBase,
205 SvTokenStream & rInStm )
207 sal_uInt32 nTokPos = rInStm.Tell();
208 if( !GetType() )
209 // no type in ctor passed on
210 aType = rBase.ReadKnownType( rInStm );
211 sal_Bool bOk = sal_False;
212 if( GetType() )
214 ReadNameSvIdl( rBase, rInStm );
215 aSlotId.ReadSvIdl( rBase, rInStm );
217 bOk = sal_True;
218 SvToken * pTok = rInStm.GetToken();
219 if( bOk && pTok->IsChar() && pTok->GetChar() == '(' )
221 SvMetaTypeRef xT = new SvMetaType();
222 xT->SetRef( GetType() );
223 aType = xT;
224 bOk = aType->ReadMethodArgs( rBase, rInStm );
226 if( bOk )
227 bOk = SvMetaName::ReadSvIdl( rBase, rInStm );
229 else
230 rBase.SetError( "unknown type", rInStm.GetToken() );
232 if( !bOk )
233 rInStm.Seek( nTokPos );
234 return bOk;
237 void SvMetaAttribute::WriteSvIdl
239 SvIdlDataBase & rBase,
240 SvStream & rOutStm,
241 sal_uInt16 nTab
244 SvMetaType * pType = GetType();
245 pType->WriteTypePrefix( rBase, rOutStm, nTab, WRITE_IDL );
246 rOutStm << ' ' << GetName().getString().getStr();
247 if( aSlotId.IsSet() )
248 rOutStm << ' ' << aSlotId.getString().getStr();
249 if( pType->GetType() == TYPE_METHOD )
250 pType->WriteMethodArgs( rBase, rOutStm, nTab, WRITE_IDL );
251 sal_uLong nPos = rOutStm.Tell();
252 rOutStm << endl;
253 SvMetaName::WriteSvIdl( rBase, rOutStm, nTab );
254 TestAndSeekSpaceOnly( rOutStm, nPos );
257 void SvMetaAttribute::ReadAttributesSvIdl( SvIdlDataBase & rBase,
258 SvTokenStream & rInStm )
260 SvMetaReference::ReadAttributesSvIdl( rBase, rInStm );
261 aSlotId.ReadSvIdl( rBase, SvHash_SlotId(), rInStm );
262 aExport.ReadSvIdl( SvHash_Export(), rInStm );
263 aHidden.ReadSvIdl( SvHash_Hidden(), rInStm );
264 aAutomation.ReadSvIdl( SvHash_Automation(), rInStm );
265 aIsCollection.ReadSvIdl( SvHash_IsCollection(), rInStm );
266 aReadOnlyDoc.ReadSvIdl( SvHash_ReadOnlyDoc(), rInStm );
267 if( aReadonly.ReadSvIdl( SvHash_Readonly(), rInStm ) )
269 if( GetType()->GetType() == TYPE_METHOD )
271 // set error
272 rBase.SetError( "Readonly in function attribute", rInStm.GetToken() );
273 rBase.WriteError( rInStm );
278 void SvMetaAttribute::WriteAttributesSvIdl
280 SvIdlDataBase & rBase,
281 SvStream & rOutStm,
282 sal_uInt16 nTab
285 SvMetaReference::WriteAttributesSvIdl( rBase, rOutStm, nTab );
287 if( !aExport || !aAutomation || aReadonly )
289 WriteTab( rOutStm, nTab );
290 rOutStm << "//class SvMetaAttribute" << endl;
291 if( !aExport )
293 WriteTab( rOutStm, nTab );
294 aExport.WriteSvIdl( SvHash_Export(), rOutStm );
295 rOutStm << ';' << endl;
297 if ( aHidden != aExport )
299 WriteTab( rOutStm, nTab );
300 aExport.WriteSvIdl( SvHash_Hidden(), rOutStm );
301 rOutStm << ';' << endl;
303 if( aReadonly )
305 WriteTab( rOutStm, nTab );
306 aReadonly.WriteSvIdl( SvHash_Readonly(), rOutStm );
307 rOutStm << ';' << endl;
309 if( !aAutomation )
311 WriteTab( rOutStm, nTab );
312 aAutomation.WriteSvIdl( SvHash_Automation(), rOutStm );
313 rOutStm << ';' << endl;
315 if( aIsCollection )
317 WriteTab( rOutStm, nTab );
318 aIsCollection.WriteSvIdl( SvHash_IsCollection(), rOutStm );
319 rOutStm << ';' << endl;
321 if( !aReadOnlyDoc )
323 WriteTab( rOutStm, nTab );
324 aReadOnlyDoc.WriteSvIdl( SvHash_ReadOnlyDoc(), rOutStm );
325 rOutStm << ';' << endl;
330 void SvMetaAttribute::WriteParam( SvIdlDataBase & rBase,
331 SvStream & rOutStm,
332 sal_uInt16 nTab,
333 WriteType nT )
335 SvMetaType * pType = GetType();
336 DBG_ASSERT( pType, "no type for attribute" );
337 SvMetaType * pBaseType = pType->GetBaseType();
338 DBG_ASSERT( pBaseType, "no base type for attribute" );
340 if( nT == WRITE_ODL || nT == WRITE_DOCU
341 || nT == WRITE_C_HEADER || nT == WRITE_C_SOURCE )
343 if( pBaseType->GetType() == TYPE_STRUCT )
345 const SvMetaAttributeMemberList & rList = pBaseType->GetAttrList();
346 sal_uLong nCount = rList.Count();
347 for( sal_uLong i = 0; i < nCount; i++ )
349 rList.GetObject( i )->WriteParam( rBase, rOutStm, nTab, nT );
350 if( i+1<nCount )
352 rOutStm << ',';
356 else
358 if ( nT != WRITE_DOCU )
360 WriteTab( rOutStm, nTab );
361 pBaseType->WriteTypePrefix( rBase, rOutStm, nTab, nT );
364 if( !GetName().getString().isEmpty() )
366 rOutStm << ' ';
367 rOutStm << GetName().getString().getStr();
370 if ( nT == WRITE_DOCU )
372 if( pBaseType->GetType() == TYPE_METHOD ||
373 pBaseType->GetType() == TYPE_STRUCT ||
374 pBaseType->GetType() == TYPE_ENUM )
376 OSL_FAIL( "Falscher Parametertyp!" );
378 else
379 rOutStm << pBaseType->GetBasicPostfix().getStr();
385 sal_uLong SvMetaAttribute::MakeSlotValue( SvIdlDataBase & rBase, sal_Bool bVar ) const
387 const SvNumberIdentifier & rId = GetSlotId();
388 sal_uLong n = rId.GetValue();
389 if( !rBase.aStructSlotId.getString().isEmpty() )
391 n = n << 20;
392 n += rBase.aStructSlotId.GetValue();
394 if( PTR_CAST( SvMetaSlot, this ) )
395 n |= 0x20000;
396 if( !bVar )
397 n += 0x10000;
398 else if ( GetIsCollection() )
399 n += 0x40000;
400 return n;
403 void SvMetaAttribute::WriteAttributes( SvIdlDataBase & rBase, SvStream & rOutStm,
404 sal_uInt16 nTab,
405 WriteType nT, WriteAttribute nA )
407 if( nT == WRITE_ODL )
409 const SvNumberIdentifier & rId = GetSlotId();
410 sal_Bool bReadonly = GetReadonly() || ( nA & WA_READONLY );
411 if( (rId.IsSet() && !(nA & WA_STRUCT)) || bReadonly )
413 sal_Bool bVar = IsVariable();
414 if( nA & WA_VARIABLE )
415 bVar = sal_True;
416 else if( nA & WA_METHOD )
417 bVar = sal_False;
419 WriteTab( rOutStm, nTab );
420 rOutStm << "//class SvMetaAttribute" << endl;
421 if( rId.IsSet() && !(nA & WA_STRUCT) )
423 WriteTab( rOutStm, nTab );
424 rOutStm << "id("
425 << rtl::OString::valueOf(static_cast<sal_Int32>(MakeSlotValue(rBase,bVar))).getStr()
426 << ")," << endl;
428 if( bVar && (bReadonly || IsMethod()) )
430 WriteTab( rOutStm, nTab );
431 rOutStm << "readonly," << endl;
437 void SvMetaAttribute::WriteCSource( SvIdlDataBase & rBase, SvStream & rOutStm,
438 sal_Bool bSet )
440 rOutStm << endl;
441 SvMetaType * pType = GetType();
442 SvMetaType * pBaseType = pType->GetBaseType();
444 // for Set the return is always void
445 sal_Bool bVoid = bSet;
446 if( pBaseType->GetType() == TYPE_METHOD )
447 bVoid = pBaseType->GetReturnType()->GetBaseType()->GetName().getString() == "void";
449 // emit methods/functions body
450 rOutStm << '{' << endl;
451 WriteTab( rOutStm, 1 );
453 if( !bVoid )
455 if ( pBaseType->GetCName() == "double" )
457 rOutStm << "return *(double*)";
459 else
461 rOutStm << "return (";
462 pType->WriteTypePrefix( rBase, rOutStm, 2, WRITE_C_SOURCE );
463 rOutStm << ") ";
466 rOutStm << "pODKCallFunction( "
467 << rtl::OString::valueOf(static_cast<sal_Int32>(MakeSlotValue(rBase, IsVariable()))).getStr();
468 rOutStm << ',' << endl;
469 WriteTab( rOutStm, 3 );
470 rOutStm << " h" << rBase.aIFaceName.getStr() << " , ";
472 rtl::OString aParserStr;
473 if( pBaseType->GetType() == TYPE_METHOD || bSet )
474 aParserStr = pBaseType->GetParserString();
475 if( !aParserStr.isEmpty() )
477 rOutStm << '\"';
478 rOutStm << aParserStr.getStr();
479 rOutStm << "\", ";
481 else
482 rOutStm << "NULL, ";
484 if( pBaseType->GetType() == TYPE_METHOD && !bVoid )
486 rOutStm << "'";
487 rOutStm << pBaseType->GetReturnType()->GetBaseType()->GetParserChar();
488 rOutStm << "'";
490 else if ( !bSet )
492 rOutStm << "'";
493 rOutStm << pBaseType->GetParserChar();
494 rOutStm << "'";
496 else
497 rOutStm << '0';
499 if( !aParserStr.isEmpty() )
501 rOutStm << ", ";
502 if( IsMethod() )
503 pBaseType->WriteParamNames( rBase, rOutStm, rtl::OString() );
504 else if( bSet )
505 pBaseType->WriteParamNames( rBase, rOutStm, GetName().getString() );
508 rOutStm << " );" << endl;
509 rOutStm << '}' << endl;
512 void SvMetaAttribute::WriteRecursiv_Impl( SvIdlDataBase & rBase,
513 SvStream & rOutStm, sal_uInt16 nTab,
514 WriteType nT, WriteAttribute nA )
516 const SvMetaAttributeMemberList & rList = GetType()->GetBaseType()->GetAttrList();
517 sal_uLong nCount = rList.Count();
519 SvNumberIdentifier slotId = rBase.aStructSlotId;
520 if ( !GetSlotId().getString().isEmpty() )
521 rBase.aStructSlotId = GetSlotId();
523 // offial hack interface by MM: special controls get passed with the WriteAttribute
524 if ( GetReadonly() )
525 nA |= WA_READONLY;
527 for( sal_uLong i = 0; i < nCount; i++ )
529 SvMetaAttribute *pAttr = rList.GetObject( i );
530 if ( nT == WRITE_DOCU )
531 pAttr->SetDescription( GetDescription().getString() );
532 pAttr->Write( rBase, rOutStm, nTab, nT, nA );
533 if( nT == WRITE_ODL && i +1 < nCount )
534 rOutStm << ';' << endl;
537 rBase.aStructSlotId = slotId;
540 void SvMetaAttribute::Write( SvIdlDataBase & rBase, SvStream & rOutStm,
541 sal_uInt16 nTab,
542 WriteType nT, WriteAttribute nA )
544 // no attributes for automation
545 if( nT == WRITE_DOCU )
547 if ( GetHidden() )
548 return;
550 else if ( !GetAutomation() || !GetExport() )
551 return;
553 sal_Bool bVariable;
554 if( nA & WA_VARIABLE )
555 bVariable = sal_True;
556 else if( nA & WA_METHOD )
557 bVariable = sal_False;
558 else
559 bVariable = IsVariable();
561 SvMetaType * pType = GetType();
562 DBG_ASSERT( pType, "no type for attribute" );
563 SvMetaType * pBaseType = pType->GetBaseType();
564 DBG_ASSERT( pBaseType, "no base type for attribute" );
565 int nBType = pBaseType->GetType();
567 if( nT == WRITE_ODL )
569 if( (bVariable && IsVariable()) || (!bVariable && IsMethod()) )
571 if( nBType == TYPE_STRUCT )
572 WriteRecursiv_Impl( rBase, rOutStm, nTab, nT, nA );
573 else
575 SvMetaReference::Write( rBase, rOutStm, nTab, nT, nA );
576 WriteTab( rOutStm, nTab );
577 pBaseType->WriteTypePrefix( rBase, rOutStm, nTab, nT );
579 if( !GetName().getString().isEmpty() )
581 rOutStm << ' ';
582 rOutStm << GetName().getString().getStr();
584 if( pType->GetType() == TYPE_METHOD )
585 pType->WriteMethodArgs( rBase, rOutStm, nTab, nT );
589 else if( nT == WRITE_C_HEADER || nT == WRITE_C_SOURCE )
591 if( !bVariable && IsMethod() )
593 rtl::OString name = rBase.aIFaceName + GetName().getString();
594 const char * pName = name.getStr();
595 WriteTab( rOutStm, nTab );
596 pBaseType->WriteTypePrefix( rBase, rOutStm, nTab, nT );
597 rOutStm << ' ' << pName;
598 pType->WriteMethodArgs( rBase, rOutStm, nTab, nT );
599 if( nT == WRITE_C_HEADER )
600 rOutStm << ';' << endl << endl;
601 else
602 WriteCSource( rBase, rOutStm, sal_False );
604 else if ( bVariable && IsVariable() )
606 if( nBType == TYPE_STRUCT )
608 // for assistance emit the name of the property as acomment
609 rOutStm << "/* " << GetName().getString().getStr() << " */" << endl;
611 WriteRecursiv_Impl( rBase, rOutStm, nTab, nT, nA );
613 else
615 rtl::OString name = GetName().getString();
617 sal_Bool bReadonly = GetReadonly() || ( nA & WA_READONLY );
618 if ( !bReadonly && !IsMethod() )
620 // allocation
621 WriteTab( rOutStm, nTab );
622 rOutStm << "void ";
623 rOutStm << rBase.aIFaceName.getStr()
624 << "Set" << name.getStr() << "( " << C_PREF
625 << "Object h" << rBase.aIFaceName.getStr() << ", " << endl;
626 WriteTab( rOutStm, nTab+1 );
627 pBaseType->WriteTypePrefix( rBase, rOutStm, nTab, nT );
628 rOutStm << ' ' << name.getStr() << " )";
629 if( nT == WRITE_C_HEADER )
630 rOutStm << ';' << endl << endl;
631 else
632 WriteCSource( rBase, rOutStm, sal_True );
635 // access
636 WriteTab( rOutStm, nTab );
637 pBaseType->WriteTypePrefix( rBase, rOutStm, nTab, nT );
638 rOutStm << ' ';
639 rOutStm << rBase.aIFaceName.getStr()
640 << "Get" << name.getStr() << "( " << C_PREF
641 << "Object h" << rBase.aIFaceName.getStr() << " )";
642 if( nT == WRITE_C_HEADER )
643 rOutStm << ';' << endl << endl;
644 else
645 WriteCSource( rBase, rOutStm, sal_False );
649 else if ( nT == WRITE_DOCU )
651 if( !bVariable && IsMethod() )
653 rOutStm << "<METHOD>" << endl
654 << GetSlotId().getString().getStr() << endl
655 << GetName().getString().getStr() << endl
656 << endl; // readonly
658 // return type
659 SvMetaType* pType2 = GetType();
660 SvMetaType* pBaseType2 = pType2->GetBaseType();
661 rOutStm << pBaseType2->GetReturnType()->GetBaseType()->GetBasicName().getStr() << endl;
663 DBG_ASSERT( !pBaseType2->GetReturnType()->GetBaseType()->GetBasicName().isEmpty(),
664 "Leerer BasicName" );
666 // syntax
667 rOutStm << GetName().getString().getStr();
668 pType2->WriteMethodArgs( rBase, rOutStm, nTab, nT );
670 // C return type
671 pBaseType2->WriteTypePrefix( rBase, rOutStm, 0, WRITE_C_HEADER );
672 rOutStm << endl;
674 // for methods also C syntax
675 rOutStm << "<C-SYNTAX>" << endl;
676 Write( rBase, rOutStm, 0, WRITE_C_HEADER, nA );
677 rOutStm << "</C-SYNTAX>" << endl;
679 // description
680 WriteDescription( rOutStm );
681 rOutStm << "</METHOD>" << endl << endl;
683 else if( bVariable && IsVariable() )
685 if( nBType == TYPE_STRUCT )
687 WriteRecursiv_Impl( rBase, rOutStm, nTab, nT, nA );
689 else
691 rOutStm << "<PROPERTY>" << endl
692 << GetSlotId().getString().getStr() << endl
693 << GetName().getString().getStr() << endl;
694 if ( GetReadonly() )
695 rOutStm << "(nur lesen)" << endl;
696 else
697 rOutStm << endl;
699 // for properties type instead of the return value
700 rOutStm << pBaseType->GetBasicName().getStr() << endl;
702 DBG_ASSERT( !pBaseType->GetBasicName().isEmpty(),
703 "Leerer BasicName" );
705 // for properties no syntax
706 rOutStm << endl;
708 // C return type
709 pBaseType->WriteTypePrefix( rBase, rOutStm, 0, WRITE_C_HEADER );
710 rOutStm << endl;
712 // description
713 WriteDescription( rOutStm );
714 rOutStm << "</PROPERTY>" << endl << endl;
720 sal_uLong SvMetaAttribute::MakeSfx( rtl::OStringBuffer& rAttrArray )
722 SvMetaType * pType = GetType();
723 DBG_ASSERT( pType, "no type for attribute" );
724 SvMetaType * pBaseType = pType->GetBaseType();
725 DBG_ASSERT( pBaseType, "no base type for attribute" );
726 if( pBaseType->GetType() == TYPE_STRUCT )
727 return pBaseType->MakeSfx( rAttrArray );
728 else
730 rAttrArray.append('{');
731 rAttrArray.append(GetSlotId().getString());
732 rAttrArray.append(",\"");
733 rAttrArray.append(GetName().getString());
734 rAttrArray.append("\"}");
735 return 1;
739 void SvMetaAttribute::Insert (SvSlotElementList&, const rtl::OString&, SvIdlDataBase&)
743 void SvMetaAttribute::WriteHelpId( SvIdlDataBase &, SvStream &, HelpIdTable& )
747 SV_IMPL_META_FACTORY1( SvMetaType, SvMetaExtern );
748 #define CTOR \
749 : aCall0( CALL_VALUE, sal_False ) \
750 , aCall1( CALL_VALUE, sal_False ) \
751 , aSbxDataType( 0, sal_False ) \
752 , pAttrList( NULL ) \
753 , nType( TYPE_BASE ) \
754 , bIsItem( sal_False ) \
755 , bIsShell( sal_False ) \
756 , cParserChar( 'h' )
758 SvMetaType::SvMetaType()
759 CTOR
763 SvMetaType::SvMetaType( const rtl::OString& rName, char cPC,
764 const rtl::OString& rCName )
765 CTOR
767 SetName( rName );
768 cParserChar = cPC;
769 aCName.setString(rCName);
772 SvMetaType::SvMetaType( const rtl::OString& rName,
773 const rtl::OString& rSbxName,
774 const rtl::OString& rOdlName,
775 char cPc,
776 const rtl::OString& rCName,
777 const rtl::OString& rBasicName,
778 const rtl::OString& rBasicPostfix )
779 CTOR
781 SetName( rName );
782 aSbxName.setString(rSbxName);
783 aOdlName.setString(rOdlName);
784 cParserChar = cPc;
785 aCName.setString(rCName);
786 aBasicName.setString(rBasicName);
787 aBasicPostfix.setString(rBasicPostfix);
790 void SvMetaType::Load( SvPersistStream & rStm )
792 SvMetaExtern::Load( rStm );
794 sal_uInt16 nMask;
795 rStm >> nMask;
796 if( nMask & 0x0001 ) rStm >> aIn;
797 if( nMask & 0x0002 ) rStm >> aOut;
798 if( nMask & 0x0004 ) rStm >> aCall0;
799 if( nMask & 0x0008 ) rStm >> aCall1;
800 if( nMask & 0x0010 ) rStm >> aSbxDataType;
801 if( nMask & 0x0020 ) rStm >> aSvName;
802 if( nMask & 0x0040 ) rStm >> aSbxName;
803 if( nMask & 0x0080 ) rStm >> aOdlName;
804 if( nMask & 0x0100 ) rStm >> GetAttrList();
805 if( nMask & 0x0200 ) bIsItem = sal_True;
806 if( nMask & 0x0400 ) bIsShell = sal_True;
807 if( nMask & 0x0800 )
809 sal_uInt16 nT;
810 rStm >> nT;
811 nType = nT;
813 if( nMask & 0x1000 ) rStm >> cParserChar;
814 if( nMask & 0x2000 ) rStm >> aCName;
815 if( nMask & 0x4000 ) rStm >> aBasicName;
816 if( nMask & 0x8000 ) rStm >> aBasicPostfix;
819 void SvMetaType::Save( SvPersistStream & rStm )
821 SvMetaExtern::Save( rStm );
823 // create mask
824 sal_uInt16 nMask = 0;
825 if( aIn.IsSet() ) nMask |= 0x0001;
826 if( aOut.IsSet() ) nMask |= 0x0002;
827 if( aCall0.IsSet() ) nMask |= 0x0004;
828 if( aCall1.IsSet() ) nMask |= 0x0008;
829 if( aSbxDataType.IsSet() ) nMask |= 0x0010;
830 if( aSvName.IsSet() ) nMask |= 0x0020;
831 if( aSbxName.IsSet() ) nMask |= 0x0040;
832 if( aOdlName.IsSet() ) nMask |= 0x0080;
833 if( GetAttrCount() ) nMask |= 0x0100;
834 if( bIsItem ) nMask |= 0x0200;
835 if( bIsShell ) nMask |= 0x0400;
836 if( nType != TYPE_BASE ) nMask |= 0x0800;
837 if( cParserChar != 'h' ) nMask |= 0x1000;
838 if( aCName.IsSet() ) nMask |= 0x2000;
839 if( aBasicName.IsSet() ) nMask |= 0x4000;
840 if( aBasicPostfix.IsSet() ) nMask |= 0x8000;
842 // write data
843 rStm << nMask;
844 if( nMask & 0x0001 ) rStm << aIn;
845 if( nMask & 0x0002 ) rStm << aOut;
846 if( nMask & 0x0004 ) rStm << aCall0;
847 if( nMask & 0x0008 ) rStm << aCall1;
848 if( nMask & 0x0010 ) rStm << aSbxDataType;
849 if( nMask & 0x0020 ) rStm << aSvName;
850 if( nMask & 0x0040 ) rStm << aSbxName;
851 if( nMask & 0x0080 ) rStm << aOdlName;
852 if( nMask & 0x0100 ) rStm << *pAttrList;
853 if( nMask & 0x0800 ) rStm << (sal_uInt16)nType;
854 if( nMask & 0x1000 ) rStm << cParserChar;
855 if( nMask & 0x2000 ) rStm << aCName;
856 if( nMask & 0x4000 ) rStm << aBasicName;
857 if( nMask & 0x8000 ) rStm << aBasicPostfix;
860 SvMetaAttributeMemberList & SvMetaType::GetAttrList() const
862 if( !pAttrList )
863 ((SvMetaType *)this)->pAttrList = new SvMetaAttributeMemberList();
864 return *pAttrList;
867 void SvMetaType::SetType( int nT )
869 nType = nT;
870 if( nType == TYPE_ENUM )
872 aOdlName.setString("short");
874 else if( nType == TYPE_CLASS )
876 rtl::OStringBuffer aTmp(C_PREF);
877 aTmp.append(RTL_CONSTASCII_STRINGPARAM("Object *"));
878 aCName.setString(aTmp.makeStringAndClear());
882 SvMetaType * SvMetaType::GetBaseType() const
884 if( GetRef() && GetType() == TYPE_BASE )
885 return ((SvMetaType *)GetRef())->GetBaseType();
886 return (SvMetaType *)this;
889 SvMetaType * SvMetaType::GetReturnType() const
891 DBG_ASSERT( GetType() == TYPE_METHOD, "no method" );
892 DBG_ASSERT( GetRef(), "no return type" );
893 return (SvMetaType *)GetRef();
896 const rtl::OString& SvMetaType::GetBasicName() const
898 if( aBasicName.IsSet() || !GetRef() )
899 return aBasicName.getString();
900 else
901 return ((SvMetaType*)GetRef())->GetBasicName();
904 rtl::OString SvMetaType::GetBasicPostfix() const
906 // MBN and Co always want "As xxx"
907 return rtl::OStringBuffer(RTL_CONSTASCII_STRINGPARAM(" As ")).
908 append(GetBasicName()).
909 makeStringAndClear();
912 sal_Bool SvMetaType::GetIn() const
914 if( aIn.IsSet() || !GetRef() )
915 return aIn;
916 else
917 return ((SvMetaType *)GetRef())->GetIn();
920 sal_Bool SvMetaType::GetOut() const
922 if( aOut.IsSet() || !GetRef() )
923 return aOut;
924 else
925 return ((SvMetaType *)GetRef())->GetOut();
928 void SvMetaType::SetCall0( int e )
930 aCall0 = (int)e;
931 if( aCall0 == CALL_VALUE && aCall1 == CALL_VALUE )
933 if( GetType() == TYPE_POINTER )
934 SetType( TYPE_BASE );
936 else
938 DBG_ASSERT( nType == TYPE_POINTER || nType == TYPE_BASE,
939 "set no base type to pointer" );
940 SetType( TYPE_POINTER );
944 int SvMetaType::GetCall0() const
946 if( aCall0.IsSet() || !GetRef() )
947 return aCall0;
948 else
949 return ((SvMetaType *)GetRef())->GetCall0();
952 void SvMetaType::SetCall1( int e )
954 aCall1 = (int)e;
955 if( aCall0 == CALL_VALUE && aCall1 == CALL_VALUE )
957 if( GetType() == TYPE_POINTER )
958 SetType( TYPE_BASE );
960 else
962 DBG_ASSERT( nType == TYPE_POINTER || nType == TYPE_BASE,
963 "set no base type to pointer" );
964 SetType( TYPE_POINTER );
968 int SvMetaType::GetCall1() const
970 if( aCall1.IsSet() || !GetRef() )
971 return aCall1;
972 else
973 return ((SvMetaType *)GetRef())->GetCall1();
976 const rtl::OString& SvMetaType::GetSvName() const
978 if( aSvName.IsSet() || !GetRef() )
979 return aSvName.getString();
980 else
981 return ((SvMetaType *)GetRef())->GetSvName();
984 const rtl::OString& SvMetaType::GetSbxName() const
986 if( aSbxName.IsSet() || !GetRef() )
987 return aSbxName.getString();
988 else
989 return ((SvMetaType *)GetRef())->GetSbxName();
992 const rtl::OString& SvMetaType::GetOdlName() const
994 if( aOdlName.IsSet() || !GetRef() )
995 return aOdlName.getString();
996 else
997 return ((SvMetaType *)GetRef())->GetOdlName();
1000 const rtl::OString& SvMetaType::GetCName() const
1002 if( aCName.IsSet() || !GetRef() )
1003 return aCName.getString();
1004 else
1005 return ((SvMetaType *)GetRef())->GetCName();
1008 sal_Bool SvMetaType::SetName( const rtl::OString& rName, SvIdlDataBase * pBase )
1010 aSvName.setString(rName);
1011 aSbxName.setString(rName);
1012 aCName.setString(rName);
1013 if( GetType() != TYPE_ENUM )
1014 aOdlName.setString(rName);
1015 return SvMetaReference::SetName( rName, pBase );
1018 rtl::OString SvMetaType::GetCString() const
1020 rtl::OStringBuffer out( GetSvName() );
1021 if( aCall0 == (int)CALL_POINTER )
1022 out.append(" *");
1023 else if( aCall0 == (int)CALL_REFERENCE )
1024 out.append(" &");
1025 if( aCall1 == (int)CALL_POINTER )
1026 out.append('*');
1027 else if( aCall1 == (int)CALL_REFERENCE )
1028 out.append('&');
1029 return out.makeStringAndClear();
1032 sal_Bool SvMetaType::ReadHeaderSvIdl( SvIdlDataBase & rBase,
1033 SvTokenStream & rInStm )
1035 sal_Bool bOk = sal_False;
1036 sal_uInt32 nTokPos = rInStm.Tell();
1037 SvToken * pTok = rInStm.GetToken_Next();
1039 if( pTok->Is( SvHash_interface() )
1040 || pTok->Is( SvHash_shell() ) )
1042 if( pTok->Is( SvHash_shell() ) )
1043 bIsShell = sal_True;
1044 SetType( TYPE_CLASS );
1045 bOk = ReadNamesSvIdl( rBase, rInStm );
1048 else if( pTok->Is( SvHash_struct() ) )
1050 SetType( TYPE_STRUCT );
1051 bOk = ReadNamesSvIdl( rBase, rInStm );
1053 else if( pTok->Is( SvHash_union() ) )
1055 SetType( TYPE_UNION );
1056 if( ReadNameSvIdl( rBase, rInStm ) )
1057 return sal_True;
1059 else if( pTok->Is( SvHash_enum() ) )
1061 SetType( TYPE_ENUM );
1062 bOk = ReadNameSvIdl( rBase, rInStm );
1064 else if( pTok->Is( SvHash_typedef() )
1065 || pTok->Is( SvHash_item() ) )
1067 if( pTok->Is( SvHash_item() ) )
1068 bIsItem = sal_True;
1070 SvMetaType * pType = rBase.ReadKnownType( rInStm );
1071 if( pType )
1073 SetRef( pType );
1074 if( ReadNameSvIdl( rBase, rInStm ) )
1076 if( rInStm.Read( '(' ) )
1078 DoReadContextSvIdl( rBase, rInStm );
1079 if( rInStm.Read( ')' ) )
1081 SetType( TYPE_METHOD );
1082 bOk = sal_True;
1085 else
1087 bOk = sal_True;
1091 else
1093 rtl::OString aStr("wrong typedef: ");
1094 rBase.SetError( aStr, rInStm.GetToken() );
1095 rBase.WriteError( rInStm );
1098 if( bOk )
1099 SetModule( rBase );
1100 else
1101 rInStm.Seek( nTokPos );
1102 return bOk;
1105 sal_Bool SvMetaType::ReadSvIdl( SvIdlDataBase & rBase,
1106 SvTokenStream & rInStm )
1108 if( ReadHeaderSvIdl( rBase, rInStm ) )
1110 rBase.Write(rtl::OString('.'));
1111 return SvMetaExtern::ReadSvIdl( rBase, rInStm );
1113 return sal_False;
1116 void SvMetaType::WriteSvIdl
1118 SvIdlDataBase & rBase,
1119 SvStream & rOutStm,
1120 sal_uInt16 nTab
1123 WriteHeaderSvIdl( rBase, rOutStm, nTab );
1124 if( GetType() == TYPE_METHOD )
1125 WriteMethodArgs( rBase, rOutStm, nTab, WRITE_IDL );
1127 sal_uLong nOldPos = rOutStm.Tell();
1128 rOutStm << endl;
1129 SvMetaExtern::WriteSvIdl( rBase, rOutStm, nTab );
1130 if( TestAndSeekSpaceOnly( rOutStm, nOldPos ) )
1131 // nothin written
1132 rOutStm.Seek( nOldPos );
1133 rOutStm << ';' << endl;
1136 void SvMetaType::WriteContext( SvIdlDataBase & rBase, SvStream & rOutStm,
1137 sal_uInt16 nTab,
1138 WriteType nT, WriteAttribute nA )
1140 if( GetAttrCount() )
1142 SvMetaAttribute * pAttr = pAttrList->First();
1143 while( pAttr )
1145 pAttr->Write( rBase, rOutStm, nTab, nT, nA );
1146 if( GetType() == TYPE_METHOD )
1147 rOutStm << ',' << endl;
1148 else
1149 rOutStm << ';' << endl;
1150 pAttr = pAttrList->Next();
1155 void SvMetaType::Write( SvIdlDataBase & rBase, SvStream & rOutStm,
1156 sal_uInt16 nTab,
1157 WriteType nT, WriteAttribute nA )
1159 if( nT == WRITE_C_HEADER && nType != TYPE_ENUM )
1160 // write only enum
1161 return;
1163 rtl::OString name = GetName().getString();
1164 if( nT == WRITE_ODL || nT == WRITE_C_HEADER || nT == WRITE_CXX_HEADER )
1166 switch( nType )
1168 case TYPE_CLASS:
1171 break;
1172 case TYPE_STRUCT:
1173 case TYPE_UNION:
1174 case TYPE_ENUM:
1176 WriteStars( rOutStm );
1177 if( nType == TYPE_STRUCT || nType == TYPE_UNION )
1178 nA = WA_STRUCT;
1180 if( nT == WRITE_ODL || nT == WRITE_C_HEADER)
1182 if ( nT == WRITE_C_HEADER )
1184 rtl::OString aStr = name.toAsciiUpperCase();
1185 rOutStm << "#ifndef " << C_PREF << aStr.getStr() << "_DEF " << endl;
1186 rOutStm << "#define " << C_PREF << aStr.getStr() << "_DEF " << endl;
1189 WriteTab( rOutStm, nTab );
1190 rOutStm << "typedef" << endl;
1191 if ( nT == WRITE_ODL )
1192 SvMetaName::Write( rBase, rOutStm, nTab, nT, nA );
1194 WriteTab( rOutStm, nTab );
1195 if( nType == TYPE_STRUCT )
1196 rOutStm << "struct";
1197 else if( nType == TYPE_UNION )
1198 rOutStm << "union";
1199 else
1200 rOutStm << "enum";
1201 if( nT != WRITE_ODL && nT != WRITE_C_HEADER)
1202 rOutStm << ' ' << name.getStr();
1204 rOutStm << endl;
1205 WriteTab( rOutStm, nTab );
1206 rOutStm << '{' << endl;
1207 WriteContext( rBase, rOutStm, nTab +1, nT, nA );
1208 WriteTab( rOutStm, nTab );
1209 rOutStm << '}';
1210 if( nT == WRITE_ODL || nT == WRITE_C_HEADER )
1212 rOutStm << ' ' << C_PREF << name.getStr();
1214 rOutStm << ';' << endl;
1216 if ( nT == WRITE_C_HEADER )
1217 rOutStm << "#endif";
1218 rOutStm << endl;
1220 break;
1221 case TYPE_POINTER:
1222 case TYPE_BASE:
1225 break;
1226 case TYPE_METHOD:
1229 break;
1234 sal_Bool SvMetaType::ReadNamesSvIdl( SvIdlDataBase & rBase,
1235 SvTokenStream & rInStm )
1237 sal_Bool bOk = ReadNameSvIdl( rBase, rInStm );
1239 return bOk;
1242 void SvMetaType::WriteHeaderSvIdl( SvIdlDataBase & rBase,
1243 SvStream & rOutStm,
1244 sal_uInt16 nTab )
1246 switch( nType )
1248 case TYPE_CLASS:
1250 if( IsShell() )
1251 rOutStm << SvHash_shell()->GetName().getStr();
1252 else
1253 rOutStm << SvHash_interface()->GetName().getStr();
1254 rOutStm << ' ' << GetName().getString().getStr();
1256 break;
1257 case TYPE_STRUCT:
1259 rOutStm << SvHash_struct()->GetName().getStr()
1260 << ' ' << GetName().getString().getStr();
1262 break;
1263 case TYPE_UNION:
1265 rOutStm << SvHash_union()->GetName().getStr()
1266 << ' ' << GetName().getString().getStr();
1268 break;
1269 case TYPE_ENUM:
1271 rOutStm << SvHash_enum()->GetName().getStr()
1272 << ' ' << GetName().getString().getStr();
1274 break;
1275 case TYPE_POINTER:
1276 case TYPE_BASE:
1278 if( IsItem() )
1279 rOutStm << SvHash_item()->GetName().getStr() << ' ';
1280 else
1281 rOutStm << SvHash_typedef()->GetName().getStr() << ' ';
1282 if( GetRef() )
1284 ((SvMetaType *)GetRef())->WriteTheType( rBase, rOutStm, nTab, WRITE_IDL );
1285 rOutStm << ' ';
1287 rOutStm << GetName().getString().getStr();
1289 break;
1290 case TYPE_METHOD:
1292 rOutStm << SvHash_typedef()->GetName().getStr() << ' ';
1293 ((SvMetaType *)GetRef())->WriteTheType( rBase, rOutStm, nTab, WRITE_IDL );
1294 rOutStm << ' ' << GetName().getString().getStr() << "( ";
1295 WriteContextSvIdl( rBase, rOutStm, nTab );
1296 rOutStm << " )";
1298 break;
1302 void SvMetaType::ReadAttributesSvIdl( SvIdlDataBase & rBase,
1303 SvTokenStream & rInStm )
1305 SvMetaExtern::ReadAttributesSvIdl( rBase, rInStm );
1306 aSvName.ReadSvIdl( SvHash_SvName(), rInStm );
1307 aSbxName.ReadSvIdl( SvHash_SbxName(), rInStm );
1308 aOdlName.ReadSvIdl( SvHash_OdlName(), rInStm );
1311 void SvMetaType::WriteAttributesSvIdl( SvIdlDataBase & rBase,
1312 SvStream & rOutStm,
1313 sal_uInt16 nTab )
1315 SvMetaExtern::WriteAttributesSvIdl( rBase, rOutStm, nTab );
1316 rtl::OString name = GetName().getString();
1317 if( aSvName.getString() != name || aSbxName.getString() != name || aOdlName.getString() != name )
1319 WriteTab( rOutStm, nTab );
1320 rOutStm << "class SvMetaType" << endl;
1321 if( aSvName.getString() != name )
1323 WriteTab( rOutStm, nTab );
1324 aSvName.WriteSvIdl( SvHash_SvName(), rOutStm, nTab );
1325 rOutStm << endl;
1327 if( aSbxName.getString() != name )
1329 WriteTab( rOutStm, nTab );
1330 aSbxName.WriteSvIdl( SvHash_SbxName(), rOutStm, nTab );
1331 rOutStm << endl;
1333 if( aOdlName.getString() != name )
1335 WriteTab( rOutStm, nTab );
1336 aOdlName.WriteSvIdl( SvHash_OdlName(), rOutStm, nTab );
1337 rOutStm << endl;
1342 void SvMetaType::ReadContextSvIdl( SvIdlDataBase & rBase,
1343 SvTokenStream & rInStm )
1345 SvMetaAttributeRef xAttr = new SvMetaAttribute();
1346 if( xAttr->ReadSvIdl( rBase, rInStm ) )
1348 if( xAttr->Test( rBase, rInStm ) )
1349 GetAttrList().Append( xAttr );
1353 void SvMetaType::WriteContextSvIdl
1355 SvIdlDataBase & rBase,
1356 SvStream & rOutStm,
1357 sal_uInt16 nTab
1360 if( GetAttrCount() )
1362 SvMetaAttribute * pAttr = pAttrList->First();
1363 while( pAttr )
1365 WriteTab( rOutStm, nTab );
1366 pAttr->WriteSvIdl( rBase, rOutStm, nTab );
1367 if( GetType() == TYPE_METHOD )
1368 rOutStm << ',' << endl;
1369 else
1370 rOutStm << ';' << endl;
1371 pAttr = pAttrList->Next();
1376 void SvMetaType::WriteAttributes( SvIdlDataBase & rBase, SvStream & rOutStm,
1377 sal_uInt16 nTab,
1378 WriteType nT, WriteAttribute nA )
1380 SvMetaExtern::WriteAttributes( rBase, rOutStm, nTab, nT, nA );
1383 sal_uLong SvMetaType::MakeSfx( rtl::OStringBuffer& rAttrArray )
1385 sal_uLong nC = 0;
1387 if( GetBaseType()->GetType() == TYPE_STRUCT )
1389 sal_uLong nAttrCount = GetAttrCount();
1390 // write the single attributes
1391 for( sal_uLong n = 0; n < nAttrCount; n++ )
1393 nC += pAttrList->GetObject( n )->MakeSfx( rAttrArray );
1394 if( n +1 < nAttrCount )
1395 rAttrArray.append(", ");
1398 return nC;
1401 void SvMetaType::WriteSfxItem(
1402 const rtl::OString& rItemName, SvIdlDataBase &, SvStream & rOutStm )
1404 WriteStars( rOutStm );
1405 rtl::OStringBuffer aVarName(RTL_CONSTASCII_STRINGPARAM(" a"));
1406 aVarName.append(rItemName).append(RTL_CONSTASCII_STRINGPARAM("_Impl"));
1408 rtl::OStringBuffer aTypeName(RTL_CONSTASCII_STRINGPARAM("SfxType"));
1409 rtl::OStringBuffer aAttrArray;
1410 sal_uLong nAttrCount = MakeSfx( aAttrArray );
1411 rtl::OString aAttrCount(
1412 rtl::OString::valueOf(static_cast<sal_Int32>(nAttrCount)));
1413 aTypeName.append(aAttrCount);
1415 rOutStm << "extern " << aTypeName.getStr()
1416 << aVarName.getStr() << ';' << endl;
1418 // write the implementation part
1419 rOutStm << "#ifdef SFX_TYPEMAP" << endl
1420 << aTypeName.getStr() << aVarName.getStr()
1421 << " = " << endl;
1422 rOutStm << '{' << endl
1423 << "\tTYPE(" << rItemName.getStr() << "), "
1424 << aAttrCount.getStr();
1425 if( nAttrCount )
1427 rOutStm << ", { ";
1428 // write the single attributes
1429 rOutStm << aAttrArray.getStr();
1430 rOutStm << " }";
1432 rOutStm << endl << "};" << endl
1433 << "#endif" << endl << endl;
1436 void SvMetaType::WriteSfx( SvIdlDataBase & rBase, SvStream & rOutStm )
1438 if( IsItem() )
1440 if( GetBaseType()->GetType() == TYPE_STRUCT )
1441 GetBaseType()->WriteSfxItem( GetName().getString(), rBase, rOutStm );
1442 else
1443 WriteSfxItem( GetName().getString(), rBase, rOutStm );
1447 sal_Bool SvMetaType::ReadMethodArgs( SvIdlDataBase & rBase,
1448 SvTokenStream & rInStm )
1450 sal_uInt32 nTokPos = rInStm.Tell();
1451 if( rInStm.Read( '(' ) )
1453 DoReadContextSvIdl( rBase, rInStm );
1454 if( rInStm.Read( ')' ) )
1456 SetType( TYPE_METHOD );
1457 return sal_True;
1460 rInStm.Seek( nTokPos );
1461 return sal_False;
1464 void SvMetaType::WriteMethodArgs
1466 SvIdlDataBase & rBase,
1467 SvStream & rOutStm,
1468 sal_uInt16 nTab, WriteType nT
1471 if( nT == WRITE_IDL )
1473 if( GetAttrCount() )
1475 rOutStm << endl;
1476 WriteTab( rOutStm, nTab );
1477 rOutStm << '(' << endl;
1479 SvMetaAttribute * pAttr = pAttrList->First();
1480 while( pAttr )
1482 WriteTab( rOutStm, nTab +1 );
1483 pAttr->WriteSvIdl( rBase, rOutStm, nTab +1 );
1484 pAttr = pAttrList->Next();
1485 if( pAttr )
1486 rOutStm << ',' << endl;
1488 rOutStm << endl;
1489 WriteTab( rOutStm, nTab );
1490 rOutStm << ')';
1492 else
1493 rOutStm << "()";
1495 else if ( nT == WRITE_DOCU )
1498 rOutStm << '(';
1499 if( GetAttrCount() )
1501 SvMetaAttribute * pAttr = pAttrList->First();
1502 while( pAttr )
1504 pAttr->WriteParam( rBase, rOutStm, nTab+1, nT );
1505 pAttr = pAttrList->Next();
1506 if( pAttr )
1507 rOutStm << ',';
1508 else
1509 rOutStm << ' ';
1512 rOutStm << ')' << endl;
1514 else
1516 rOutStm << '(';
1517 if( nT == WRITE_C_HEADER || nT == WRITE_C_SOURCE )
1519 rOutStm << ' ' << C_PREF << "Object h" << rBase.aIFaceName.getStr();
1520 if( GetAttrCount() )
1521 rOutStm << ',';
1522 else
1523 rOutStm << ' ';
1526 if( GetAttrCount() )
1528 rOutStm << endl;
1529 SvMetaAttribute * pAttr = pAttrList->First();
1530 while( pAttr )
1532 switch( nT )
1534 case WRITE_C_HEADER:
1535 case WRITE_C_SOURCE:
1536 case WRITE_ODL:
1538 pAttr->WriteParam( rBase, rOutStm, nTab +1, nT );
1540 break;
1542 default:
1544 DBG_ASSERT( sal_False, "WriteType not implemented" );
1547 pAttr = pAttrList->Next();
1548 if( pAttr )
1549 rOutStm << ',' << endl;
1551 if( nT != WRITE_C_HEADER && nT != WRITE_C_SOURCE )
1553 rOutStm << endl;
1554 WriteTab( rOutStm, nTab +1 );
1556 rOutStm << ' ';
1558 rOutStm << ')';
1562 void SvMetaType::WriteTypePrefix( SvIdlDataBase & rBase, SvStream & rOutStm,
1563 sal_uInt16 nTab, WriteType nT )
1565 switch( nT )
1567 case WRITE_IDL:
1569 if( GetIn() && GetOut() )
1570 rOutStm << SvHash_inout()->GetName().getStr() << ' ';
1571 else if( GetIn() )
1572 rOutStm << SvHash_in()->GetName().getStr() << ' ';
1573 else if( GetOut() )
1574 rOutStm << SvHash_out()->GetName().getStr() << ' ';
1575 rOutStm << GetCString().getStr();
1577 break;
1579 case WRITE_ODL:
1581 sal_Bool bIn = GetIn();
1582 sal_Bool bOut = GetOut();
1583 if( bIn || bOut )
1585 if( bIn && bOut )
1586 rOutStm << "[in,out] ";
1587 else if( bIn )
1588 rOutStm << "[in] ";
1589 else if( bOut )
1590 rOutStm << "[out] ";
1593 rtl::OString out;
1594 if( GetType() == TYPE_METHOD )
1595 out = GetReturnType()->GetBaseType()->GetOdlName();
1596 else
1598 SvMetaType * pBType = GetBaseType();
1599 out = pBType->GetOdlName();
1601 if( aCall0 == (int)CALL_POINTER
1602 || aCall0 == (int)CALL_REFERENCE )
1603 rOutStm << " *";
1604 if( aCall1 == (int)CALL_POINTER
1605 || aCall1 == (int)CALL_REFERENCE )
1606 rOutStm << " *";
1607 rOutStm << out.getStr();
1609 break;
1611 case WRITE_C_HEADER:
1612 case WRITE_C_SOURCE:
1613 case WRITE_CXX_HEADER:
1614 case WRITE_CXX_SOURCE:
1617 SvMetaType * pBaseType = GetBaseType();
1618 DBG_ASSERT( pBaseType, "no base type for attribute" );
1620 if( pBaseType->GetType() == TYPE_METHOD )
1621 pBaseType->GetReturnType()->WriteTypePrefix(
1622 rBase, rOutStm, nTab, nT );
1623 else if( nT == WRITE_C_HEADER || nT == WRITE_C_SOURCE )
1625 if( TYPE_STRUCT == pBaseType->GetType() )
1626 rOutStm << C_PREF << pBaseType->GetName().getString().getStr()
1627 << " *";
1628 else
1630 if ( pBaseType->GetType() == TYPE_ENUM )
1631 rOutStm << C_PREF;
1632 rOutStm << pBaseType->GetCName().getStr();
1635 else
1637 if( TYPE_STRUCT == pBaseType->GetType() )
1638 rOutStm << pBaseType->GetName().getString().getStr() << " *";
1639 else
1640 rOutStm << pBaseType->GetName().getString().getStr();
1643 break;
1645 case WRITE_DOCU:
1648 SvMetaType * pBaseType = GetBaseType();
1649 DBG_ASSERT( pBaseType, "no base type for attribute" );
1651 if( pBaseType->GetType() == TYPE_METHOD )
1653 pBaseType->GetReturnType()->WriteTypePrefix(
1654 rBase, rOutStm, nTab, nT );
1656 else
1658 if( TYPE_STRUCT == pBaseType->GetType() )
1659 rOutStm << "VARIANT" << pBaseType->GetName().getString().getStr();
1660 else if ( pBaseType->GetType() == TYPE_ENUM )
1661 rOutStm << "integer";
1662 else
1663 rOutStm << pBaseType->GetOdlName().getStr();
1667 default:
1669 DBG_ASSERT( sal_False, "WriteType not implemented" );
1674 void SvMetaType::WriteTheType( SvIdlDataBase & rBase, SvStream & rOutStm,
1675 sal_uInt16 nTab, WriteType nT )
1677 WriteTypePrefix( rBase, rOutStm, nTab, nT );
1678 if( GetType() == TYPE_METHOD )
1679 WriteMethodArgs( rBase, rOutStm, nTab +2, nT );
1682 rtl::OString SvMetaType::GetParserString() const
1684 SvMetaType * pBT = GetBaseType();
1685 if( pBT != this )
1686 return pBT->GetParserString();
1688 int type = GetType();
1689 rtl::OString aPStr;
1691 if( TYPE_METHOD == type || TYPE_STRUCT == type )
1693 sal_uLong nAttrCount = GetAttrCount();
1694 // write the single attributes
1695 for( sal_uLong n = 0; n < nAttrCount; n++ )
1697 SvMetaAttribute * pT = pAttrList->GetObject( n );
1698 aPStr += pT->GetType()->GetParserString();
1701 else
1702 aPStr = rtl::OString(GetParserChar());
1703 return aPStr;
1706 void SvMetaType::WriteParamNames( SvIdlDataBase & rBase,
1707 SvStream & rOutStm,
1708 const rtl::OString& rChief )
1710 SvMetaType * pBT = GetBaseType();
1711 if( pBT != this )
1712 pBT->WriteParamNames( rBase, rOutStm, rChief );
1713 else
1715 int type = GetType();
1717 if( TYPE_METHOD == type || TYPE_STRUCT == type )
1719 sal_uLong nAttrCount = GetAttrCount();
1720 // write the single attributes
1721 for( sal_uLong n = 0; n < nAttrCount; n++ )
1723 SvMetaAttribute * pA = pAttrList->GetObject( n );
1724 rtl::OString aStr = pA->GetName().getString();
1725 pA->GetType()->WriteParamNames( rBase, rOutStm, aStr );
1726 if( n +1 < nAttrCount )
1727 rOutStm << ", ";
1730 else
1731 rOutStm << rChief.getStr();
1735 SV_IMPL_META_FACTORY1( SvMetaTypeString, SvMetaType );
1736 SvMetaTypeString::SvMetaTypeString()
1737 : SvMetaType( "String", "SbxSTRING", "BSTR", 's', "char *", "String", "$" )
1741 void SvMetaTypeString::Load( SvPersistStream & rStm )
1743 SvMetaType::Load( rStm );
1746 void SvMetaTypeString::Save( SvPersistStream & rStm )
1748 SvMetaType::Save( rStm );
1751 SV_IMPL_META_FACTORY1( SvMetaEnumValue, SvMetaName );
1752 SvMetaEnumValue::SvMetaEnumValue()
1756 void SvMetaEnumValue::Load( SvPersistStream & rStm )
1758 SvMetaName::Load( rStm );
1760 sal_uInt8 nMask;
1761 rStm >> nMask;
1762 if( nMask >= 0x02 )
1764 rStm.SetError( SVSTREAM_FILEFORMAT_ERROR );
1765 OSL_FAIL( "wrong format" );
1766 return;
1768 if( nMask & 0x01 ) aEnumValue = read_lenPrefixed_uInt8s_ToOString<sal_uInt16>(rStm);
1771 void SvMetaEnumValue::Save( SvPersistStream & rStm )
1773 SvMetaName::Save( rStm );
1775 // create mask
1776 sal_uInt8 nMask = 0;
1777 if( !aEnumValue.isEmpty() ) nMask |= 0x01;
1779 // write data
1780 rStm << nMask;
1781 if( nMask & 0x01 ) write_lenPrefixed_uInt8s_FromOString<sal_uInt16>(rStm, aEnumValue);
1784 sal_Bool SvMetaEnumValue::ReadSvIdl( SvIdlDataBase & rBase,
1785 SvTokenStream & rInStm )
1787 if( !ReadNameSvIdl( rBase, rInStm ) )
1788 return sal_False;
1789 return sal_True;
1792 void SvMetaEnumValue::WriteSvIdl( SvIdlDataBase &, SvStream & rOutStm, sal_uInt16 )
1794 rOutStm << GetName().getString().getStr();
1797 void SvMetaEnumValue::Write( SvIdlDataBase &, SvStream & rOutStm, sal_uInt16,
1798 WriteType nT, WriteAttribute )
1800 if ( nT == WRITE_C_HEADER || nT == WRITE_C_SOURCE )
1801 rOutStm << C_PREF << GetName().getString().getStr();
1802 else
1803 rOutStm << GetName().getString().getStr();
1806 SV_IMPL_META_FACTORY1( SvMetaTypeEnum, SvMetaType );
1807 SvMetaTypeEnum::SvMetaTypeEnum()
1809 SetBasicName("Integer");
1812 void SvMetaTypeEnum::Load( SvPersistStream & rStm )
1814 SvMetaType::Load( rStm );
1816 sal_uInt8 nMask;
1817 rStm >> nMask;
1818 if( nMask >= 0x04 )
1820 rStm.SetError( SVSTREAM_FILEFORMAT_ERROR );
1821 OSL_FAIL( "wrong format" );
1822 return;
1824 if( nMask & 0x01 ) rStm >> aEnumValueList;
1825 if( nMask & 0x02 ) aPrefix = read_lenPrefixed_uInt8s_ToOString<sal_uInt16>(rStm);
1828 void SvMetaTypeEnum::Save( SvPersistStream & rStm )
1830 SvMetaType::Save( rStm );
1832 // create mask
1833 sal_uInt8 nMask = 0;
1834 if( aEnumValueList.Count() ) nMask |= 0x01;
1835 if( !aPrefix.isEmpty() ) nMask |= 0x02;
1837 // write data
1838 rStm << nMask;
1839 if( nMask & 0x01 ) rStm << aEnumValueList;
1840 if( nMask & 0x02 ) write_lenPrefixed_uInt8s_FromOString<sal_uInt16>(rStm, aPrefix);
1843 namespace
1845 rtl::OString getCommonSubPrefix(const rtl::OString &rA, const rtl::OString &rB)
1847 sal_Int32 nMax = std::min(rA.getLength(), rB.getLength());
1848 sal_Int32 nI = 0;
1849 while (nI < nMax)
1851 if (rA[nI] != rB[nI])
1852 break;
1853 ++nI;
1855 return rA.copy(0, nI);
1859 void SvMetaTypeEnum::ReadContextSvIdl( SvIdlDataBase & rBase,
1860 SvTokenStream & rInStm )
1862 sal_uInt32 nTokPos = rInStm.Tell();
1864 SvMetaEnumValueRef aEnumVal = new SvMetaEnumValue();
1865 sal_Bool bOk = aEnumVal->ReadSvIdl( rBase, rInStm );
1866 if( bOk )
1868 if( 0 == aEnumValueList.Count() )
1870 // the first
1871 aPrefix = aEnumVal->GetName().getString();
1873 else
1875 aPrefix = getCommonSubPrefix(aPrefix, aEnumVal->GetName().getString());
1877 aEnumValueList.Append( aEnumVal );
1879 if( !bOk )
1880 rInStm.Seek( nTokPos );
1883 void SvMetaTypeEnum::WriteContextSvIdl( SvIdlDataBase & rBase,
1884 SvStream & rOutStm,
1885 sal_uInt16 nTab )
1887 WriteTab( rOutStm, nTab +1 );
1888 for( sal_uLong n = 0; n < aEnumValueList.Count(); n++ )
1890 aEnumValueList.GetObject( n )->WriteSvIdl( rBase, rOutStm, nTab );
1891 if( n +1 != aEnumValueList.Count() )
1892 rOutStm << ", ";
1893 else
1894 rOutStm << endl;
1898 sal_Bool SvMetaTypeEnum::ReadSvIdl( SvIdlDataBase & rBase,
1899 SvTokenStream & rInStm )
1901 sal_uInt32 nTokPos = rInStm.Tell();
1902 if( SvMetaType::ReadHeaderSvIdl( rBase, rInStm )
1903 && GetType() == TYPE_ENUM )
1905 if( SvMetaName::ReadSvIdl( rBase, rInStm ) )
1906 return sal_True;
1908 rInStm.Seek( nTokPos );
1909 return sal_False;
1912 void SvMetaTypeEnum::WriteSvIdl( SvIdlDataBase & rBase, SvStream & rOutStm,
1913 sal_uInt16 nTab )
1915 WriteHeaderSvIdl( rBase, rOutStm, nTab );
1916 rOutStm << endl;
1917 SvMetaName::WriteSvIdl( rBase, rOutStm, nTab );
1918 rOutStm << endl;
1921 void SvMetaTypeEnum::Write( SvIdlDataBase & rBase, SvStream & rOutStm,
1922 sal_uInt16 nTab,
1923 WriteType nT, WriteAttribute nA )
1925 SvMetaType::Write( rBase, rOutStm, nTab, nT, nA );
1928 void SvMetaTypeEnum::WriteContext( SvIdlDataBase & rBase, SvStream & rOutStm,
1929 sal_uInt16 nTab,
1930 WriteType nT, WriteAttribute nA )
1932 WriteTab( rOutStm, nTab +1 );
1933 for( sal_uLong n = 0; n < aEnumValueList.Count(); n++ )
1935 aEnumValueList.GetObject( n )->Write( rBase, rOutStm, nTab +1, nT, nA );
1937 if( n +1 != aEnumValueList.Count() )
1939 if( 2 == n % 3 )
1941 rOutStm << ',' << endl;
1942 WriteTab( rOutStm, nTab +1 );
1944 else
1945 rOutStm << ",\t";
1947 else
1948 rOutStm << endl;
1950 rOutStm << endl;
1953 SV_IMPL_META_FACTORY1( SvMetaTypevoid, SvMetaType );
1954 SvMetaTypevoid::SvMetaTypevoid()
1955 : SvMetaType( "void", "SbxVOID", "void", 'v', "void", "", "" )
1959 void SvMetaTypevoid::Load( SvPersistStream & rStm )
1961 SvMetaType::Load( rStm );
1964 void SvMetaTypevoid::Save( SvPersistStream & rStm )
1966 SvMetaType::Save( rStm );
1969 rtl::OString SvMetaAttribute::Compare( SvMetaAttribute* pAttr )
1971 rtl::OStringBuffer aStr;
1973 if ( aType.Is() )
1975 if ( aType->GetType() == TYPE_METHOD )
1977 // Test only when the attribute is a method not if it has one!
1978 if ( !pAttr->GetType()->GetType() == TYPE_METHOD )
1979 aStr.append(" IsMethod\n");
1980 else if ( aType->GetReturnType() &&
1981 aType->GetReturnType()->GetType() != pAttr->GetType()->GetReturnType()->GetType() )
1983 aStr.append(" ReturnType\n");
1986 if ( aType->GetAttrCount() )
1988 sal_uLong nCount = aType->GetAttrCount();
1989 SvMetaAttributeMemberList& rList = aType->GetAttrList();
1990 SvMetaAttributeMemberList& rOtherList = pAttr->GetType()->GetAttrList();
1991 if ( pAttr->GetType()->GetAttrCount() != nCount )
1993 aStr.append(" AttributeCount\n");
1995 else
1997 for ( sal_uInt16 n=0; n<nCount; n++ )
1999 SvMetaAttribute *pAttr1 = rList.GetObject(n);
2000 SvMetaAttribute *pAttr2 = rOtherList.GetObject(n);
2001 pAttr1->Compare( pAttr2 );
2007 if ( GetType()->GetType() != pAttr->GetType()->GetType() )
2008 aStr.append(" Type\n");
2010 if ( !GetType()->GetSvName().equals( pAttr->GetType()->GetSvName() ) )
2011 aStr.append(" ItemType\n");
2014 if ( GetExport() != pAttr->GetExport() )
2015 aStr.append(" Export\n");
2017 if ( GetAutomation() != pAttr->GetAutomation() )
2018 aStr.append(" Automation\n");
2020 if ( GetIsCollection() != pAttr->GetIsCollection() )
2021 aStr.append(" IsCollection\n");
2023 if ( GetReadOnlyDoc() != pAttr->GetReadOnlyDoc() )
2024 aStr.append(" ReadOnlyDoc\n");
2026 if ( GetExport() && GetReadonly() != pAttr->GetReadonly() )
2027 aStr.append(" Readonly\n");
2029 return aStr.makeStringAndClear();
2032 void SvMetaAttribute::WriteCSV( SvIdlDataBase&, SvStream& rStrm )
2034 rStrm << GetType()->GetSvName().getStr() << ' ';
2035 rStrm << GetName().getString().getStr() << ' ';
2036 rStrm << GetSlotId().getString().getStr();
2040 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */