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 ************************************************************************/
33 #include <tools/debug.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
)
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
);
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
);
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;
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() )
138 else if( aHidden
.IsSet() || !GetRef() )
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
153 if( aIsCollection
.IsSet() || !GetRef() )
155 if ( aIsCollection
.IsSet() )
157 bRet
= aIsCollection
;
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
);
204 sal_Bool
SvMetaAttribute::ReadSvIdl( SvIdlDataBase
& rBase
,
205 SvTokenStream
& rInStm
)
207 sal_uInt32 nTokPos
= rInStm
.Tell();
209 // no type in ctor passed on
210 aType
= rBase
.ReadKnownType( rInStm
);
211 sal_Bool bOk
= sal_False
;
214 ReadNameSvIdl( rBase
, rInStm
);
215 aSlotId
.ReadSvIdl( rBase
, rInStm
);
218 SvToken
* pTok
= rInStm
.GetToken();
219 if( bOk
&& pTok
->IsChar() && pTok
->GetChar() == '(' )
221 SvMetaTypeRef xT
= new SvMetaType();
222 xT
->SetRef( GetType() );
224 bOk
= aType
->ReadMethodArgs( rBase
, rInStm
);
227 bOk
= SvMetaName::ReadSvIdl( rBase
, rInStm
);
230 rBase
.SetError( "unknown type", rInStm
.GetToken() );
233 rInStm
.Seek( nTokPos
);
237 void SvMetaAttribute::WriteSvIdl
239 SvIdlDataBase
& rBase
,
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();
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
)
272 rBase
.SetError( "Readonly in function attribute", rInStm
.GetToken() );
273 rBase
.WriteError( rInStm
);
278 void SvMetaAttribute::WriteAttributesSvIdl
280 SvIdlDataBase
& rBase
,
285 SvMetaReference::WriteAttributesSvIdl( rBase
, rOutStm
, nTab
);
287 if( !aExport
|| !aAutomation
|| aReadonly
)
289 WriteTab( rOutStm
, nTab
);
290 rOutStm
<< "//class SvMetaAttribute" << endl
;
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
;
305 WriteTab( rOutStm
, nTab
);
306 aReadonly
.WriteSvIdl( SvHash_Readonly(), rOutStm
);
307 rOutStm
<< ';' << endl
;
311 WriteTab( rOutStm
, nTab
);
312 aAutomation
.WriteSvIdl( SvHash_Automation(), rOutStm
);
313 rOutStm
<< ';' << endl
;
317 WriteTab( rOutStm
, nTab
);
318 aIsCollection
.WriteSvIdl( SvHash_IsCollection(), rOutStm
);
319 rOutStm
<< ';' << endl
;
323 WriteTab( rOutStm
, nTab
);
324 aReadOnlyDoc
.WriteSvIdl( SvHash_ReadOnlyDoc(), rOutStm
);
325 rOutStm
<< ';' << endl
;
330 void SvMetaAttribute::WriteParam( SvIdlDataBase
& rBase
,
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
);
358 if ( nT
!= WRITE_DOCU
)
360 WriteTab( rOutStm
, nTab
);
361 pBaseType
->WriteTypePrefix( rBase
, rOutStm
, nTab
, nT
);
364 if( !GetName().getString().isEmpty() )
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!" );
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() )
392 n
+= rBase
.aStructSlotId
.GetValue();
394 if( PTR_CAST( SvMetaSlot
, this ) )
398 else if ( GetIsCollection() )
403 void SvMetaAttribute::WriteAttributes( SvIdlDataBase
& rBase
, SvStream
& rOutStm
,
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
)
416 else if( nA
& WA_METHOD
)
419 WriteTab( rOutStm
, nTab
);
420 rOutStm
<< "//class SvMetaAttribute" << endl
;
421 if( rId
.IsSet() && !(nA
& WA_STRUCT
) )
423 WriteTab( rOutStm
, nTab
);
425 << rtl::OString::valueOf(static_cast<sal_Int32
>(MakeSlotValue(rBase
,bVar
))).getStr()
428 if( bVar
&& (bReadonly
|| IsMethod()) )
430 WriteTab( rOutStm
, nTab
);
431 rOutStm
<< "readonly," << endl
;
437 void SvMetaAttribute::WriteCSource( SvIdlDataBase
& rBase
, SvStream
& rOutStm
,
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 );
455 if ( pBaseType
->GetCName() == "double" )
457 rOutStm
<< "return *(double*)";
461 rOutStm
<< "return (";
462 pType
->WriteTypePrefix( rBase
, rOutStm
, 2, WRITE_C_SOURCE
);
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() )
478 rOutStm
<< aParserStr
.getStr();
484 if( pBaseType
->GetType() == TYPE_METHOD
&& !bVoid
)
487 rOutStm
<< pBaseType
->GetReturnType()->GetBaseType()->GetParserChar();
493 rOutStm
<< pBaseType
->GetParserChar();
499 if( !aParserStr
.isEmpty() )
503 pBaseType
->WriteParamNames( rBase
, rOutStm
, rtl::OString() );
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
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
,
542 WriteType nT
, WriteAttribute nA
)
544 // no attributes for automation
545 if( nT
== WRITE_DOCU
)
550 else if ( !GetAutomation() || !GetExport() )
554 if( nA
& WA_VARIABLE
)
555 bVariable
= sal_True
;
556 else if( nA
& WA_METHOD
)
557 bVariable
= sal_False
;
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
);
575 SvMetaReference::Write( rBase
, rOutStm
, nTab
, nT
, nA
);
576 WriteTab( rOutStm
, nTab
);
577 pBaseType
->WriteTypePrefix( rBase
, rOutStm
, nTab
, nT
);
579 if( !GetName().getString().isEmpty() )
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
;
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
);
615 rtl::OString name
= GetName().getString();
617 sal_Bool bReadonly
= GetReadonly() || ( nA
& WA_READONLY
);
618 if ( !bReadonly
&& !IsMethod() )
621 WriteTab( rOutStm
, nTab
);
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
;
632 WriteCSource( rBase
, rOutStm
, sal_True
);
636 WriteTab( rOutStm
, nTab
);
637 pBaseType
->WriteTypePrefix( rBase
, rOutStm
, nTab
, nT
);
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
;
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
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" );
667 rOutStm
<< GetName().getString().getStr();
668 pType2
->WriteMethodArgs( rBase
, rOutStm
, nTab
, nT
);
671 pBaseType2
->WriteTypePrefix( rBase
, rOutStm
, 0, WRITE_C_HEADER
);
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
;
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
);
691 rOutStm
<< "<PROPERTY>" << endl
692 << GetSlotId().getString().getStr() << endl
693 << GetName().getString().getStr() << endl
;
695 rOutStm
<< "(nur lesen)" << 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
709 pBaseType
->WriteTypePrefix( rBase
, rOutStm
, 0, WRITE_C_HEADER
);
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
);
730 rAttrArray
.append('{');
731 rAttrArray
.append(GetSlotId().getString());
732 rAttrArray
.append(",\"");
733 rAttrArray
.append(GetName().getString());
734 rAttrArray
.append("\"}");
739 void SvMetaAttribute::Insert (SvSlotElementList
&, const rtl::OString
&, SvIdlDataBase
&)
743 void SvMetaAttribute::WriteHelpId( SvIdlDataBase
&, SvStream
&, HelpIdTable
& )
747 SV_IMPL_META_FACTORY1( SvMetaType
, SvMetaExtern
);
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 ) \
758 SvMetaType::SvMetaType()
763 SvMetaType::SvMetaType( const rtl::OString
& rName
, char cPC
,
764 const rtl::OString
& rCName
)
769 aCName
.setString(rCName
);
772 SvMetaType::SvMetaType( const rtl::OString
& rName
,
773 const rtl::OString
& rSbxName
,
774 const rtl::OString
& rOdlName
,
776 const rtl::OString
& rCName
,
777 const rtl::OString
& rBasicName
,
778 const rtl::OString
& rBasicPostfix
)
782 aSbxName
.setString(rSbxName
);
783 aOdlName
.setString(rOdlName
);
785 aCName
.setString(rCName
);
786 aBasicName
.setString(rBasicName
);
787 aBasicPostfix
.setString(rBasicPostfix
);
790 void SvMetaType::Load( SvPersistStream
& rStm
)
792 SvMetaExtern::Load( rStm
);
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
;
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
);
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;
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
863 ((SvMetaType
*)this)->pAttrList
= new SvMetaAttributeMemberList();
867 void SvMetaType::SetType( int 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();
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() )
917 return ((SvMetaType
*)GetRef())->GetIn();
920 sal_Bool
SvMetaType::GetOut() const
922 if( aOut
.IsSet() || !GetRef() )
925 return ((SvMetaType
*)GetRef())->GetOut();
928 void SvMetaType::SetCall0( int e
)
931 if( aCall0
== CALL_VALUE
&& aCall1
== CALL_VALUE
)
933 if( GetType() == TYPE_POINTER
)
934 SetType( TYPE_BASE
);
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() )
949 return ((SvMetaType
*)GetRef())->GetCall0();
952 void SvMetaType::SetCall1( int e
)
955 if( aCall0
== CALL_VALUE
&& aCall1
== CALL_VALUE
)
957 if( GetType() == TYPE_POINTER
)
958 SetType( TYPE_BASE
);
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() )
973 return ((SvMetaType
*)GetRef())->GetCall1();
976 const rtl::OString
& SvMetaType::GetSvName() const
978 if( aSvName
.IsSet() || !GetRef() )
979 return aSvName
.getString();
981 return ((SvMetaType
*)GetRef())->GetSvName();
984 const rtl::OString
& SvMetaType::GetSbxName() const
986 if( aSbxName
.IsSet() || !GetRef() )
987 return aSbxName
.getString();
989 return ((SvMetaType
*)GetRef())->GetSbxName();
992 const rtl::OString
& SvMetaType::GetOdlName() const
994 if( aOdlName
.IsSet() || !GetRef() )
995 return aOdlName
.getString();
997 return ((SvMetaType
*)GetRef())->GetOdlName();
1000 const rtl::OString
& SvMetaType::GetCName() const
1002 if( aCName
.IsSet() || !GetRef() )
1003 return aCName
.getString();
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
)
1023 else if( aCall0
== (int)CALL_REFERENCE
)
1025 if( aCall1
== (int)CALL_POINTER
)
1027 else if( aCall1
== (int)CALL_REFERENCE
)
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
) )
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() ) )
1070 SvMetaType
* pType
= rBase
.ReadKnownType( rInStm
);
1074 if( ReadNameSvIdl( rBase
, rInStm
) )
1076 if( rInStm
.Read( '(' ) )
1078 DoReadContextSvIdl( rBase
, rInStm
);
1079 if( rInStm
.Read( ')' ) )
1081 SetType( TYPE_METHOD
);
1093 rtl::OString
aStr("wrong typedef: ");
1094 rBase
.SetError( aStr
, rInStm
.GetToken() );
1095 rBase
.WriteError( rInStm
);
1101 rInStm
.Seek( nTokPos
);
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
);
1116 void SvMetaType::WriteSvIdl
1118 SvIdlDataBase
& rBase
,
1123 WriteHeaderSvIdl( rBase
, rOutStm
, nTab
);
1124 if( GetType() == TYPE_METHOD
)
1125 WriteMethodArgs( rBase
, rOutStm
, nTab
, WRITE_IDL
);
1127 sal_uLong nOldPos
= rOutStm
.Tell();
1129 SvMetaExtern::WriteSvIdl( rBase
, rOutStm
, nTab
);
1130 if( TestAndSeekSpaceOnly( rOutStm
, nOldPos
) )
1132 rOutStm
.Seek( nOldPos
);
1133 rOutStm
<< ';' << endl
;
1136 void SvMetaType::WriteContext( SvIdlDataBase
& rBase
, SvStream
& rOutStm
,
1138 WriteType nT
, WriteAttribute nA
)
1140 if( GetAttrCount() )
1142 SvMetaAttribute
* pAttr
= pAttrList
->First();
1145 pAttr
->Write( rBase
, rOutStm
, nTab
, nT
, nA
);
1146 if( GetType() == TYPE_METHOD
)
1147 rOutStm
<< ',' << endl
;
1149 rOutStm
<< ';' << endl
;
1150 pAttr
= pAttrList
->Next();
1155 void SvMetaType::Write( SvIdlDataBase
& rBase
, SvStream
& rOutStm
,
1157 WriteType nT
, WriteAttribute nA
)
1159 if( nT
== WRITE_C_HEADER
&& nType
!= TYPE_ENUM
)
1163 rtl::OString name
= GetName().getString();
1164 if( nT
== WRITE_ODL
|| nT
== WRITE_C_HEADER
|| nT
== WRITE_CXX_HEADER
)
1176 WriteStars( rOutStm
);
1177 if( nType
== TYPE_STRUCT
|| nType
== TYPE_UNION
)
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
)
1201 if( nT
!= WRITE_ODL
&& nT
!= WRITE_C_HEADER
)
1202 rOutStm
<< ' ' << name
.getStr();
1205 WriteTab( rOutStm
, nTab
);
1206 rOutStm
<< '{' << endl
;
1207 WriteContext( rBase
, rOutStm
, nTab
+1, nT
, nA
);
1208 WriteTab( rOutStm
, nTab
);
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";
1234 sal_Bool
SvMetaType::ReadNamesSvIdl( SvIdlDataBase
& rBase
,
1235 SvTokenStream
& rInStm
)
1237 sal_Bool bOk
= ReadNameSvIdl( rBase
, rInStm
);
1242 void SvMetaType::WriteHeaderSvIdl( SvIdlDataBase
& rBase
,
1251 rOutStm
<< SvHash_shell()->GetName().getStr();
1253 rOutStm
<< SvHash_interface()->GetName().getStr();
1254 rOutStm
<< ' ' << GetName().getString().getStr();
1259 rOutStm
<< SvHash_struct()->GetName().getStr()
1260 << ' ' << GetName().getString().getStr();
1265 rOutStm
<< SvHash_union()->GetName().getStr()
1266 << ' ' << GetName().getString().getStr();
1271 rOutStm
<< SvHash_enum()->GetName().getStr()
1272 << ' ' << GetName().getString().getStr();
1279 rOutStm
<< SvHash_item()->GetName().getStr() << ' ';
1281 rOutStm
<< SvHash_typedef()->GetName().getStr() << ' ';
1284 ((SvMetaType
*)GetRef())->WriteTheType( rBase
, rOutStm
, nTab
, WRITE_IDL
);
1287 rOutStm
<< GetName().getString().getStr();
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
);
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
,
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
);
1327 if( aSbxName
.getString() != name
)
1329 WriteTab( rOutStm
, nTab
);
1330 aSbxName
.WriteSvIdl( SvHash_SbxName(), rOutStm
, nTab
);
1333 if( aOdlName
.getString() != name
)
1335 WriteTab( rOutStm
, nTab
);
1336 aOdlName
.WriteSvIdl( SvHash_OdlName(), rOutStm
, nTab
);
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
,
1360 if( GetAttrCount() )
1362 SvMetaAttribute
* pAttr
= pAttrList
->First();
1365 WriteTab( rOutStm
, nTab
);
1366 pAttr
->WriteSvIdl( rBase
, rOutStm
, nTab
);
1367 if( GetType() == TYPE_METHOD
)
1368 rOutStm
<< ',' << endl
;
1370 rOutStm
<< ';' << endl
;
1371 pAttr
= pAttrList
->Next();
1376 void SvMetaType::WriteAttributes( SvIdlDataBase
& rBase
, SvStream
& rOutStm
,
1378 WriteType nT
, WriteAttribute nA
)
1380 SvMetaExtern::WriteAttributes( rBase
, rOutStm
, nTab
, nT
, nA
);
1383 sal_uLong
SvMetaType::MakeSfx( rtl::OStringBuffer
& rAttrArray
)
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(", ");
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()
1422 rOutStm
<< '{' << endl
1423 << "\tTYPE(" << rItemName
.getStr() << "), "
1424 << aAttrCount
.getStr();
1428 // write the single attributes
1429 rOutStm
<< aAttrArray
.getStr();
1432 rOutStm
<< endl
<< "};" << endl
1433 << "#endif" << endl
<< endl
;
1436 void SvMetaType::WriteSfx( SvIdlDataBase
& rBase
, SvStream
& rOutStm
)
1440 if( GetBaseType()->GetType() == TYPE_STRUCT
)
1441 GetBaseType()->WriteSfxItem( GetName().getString(), rBase
, rOutStm
);
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
);
1460 rInStm
.Seek( nTokPos
);
1464 void SvMetaType::WriteMethodArgs
1466 SvIdlDataBase
& rBase
,
1468 sal_uInt16 nTab
, WriteType nT
1471 if( nT
== WRITE_IDL
)
1473 if( GetAttrCount() )
1476 WriteTab( rOutStm
, nTab
);
1477 rOutStm
<< '(' << endl
;
1479 SvMetaAttribute
* pAttr
= pAttrList
->First();
1482 WriteTab( rOutStm
, nTab
+1 );
1483 pAttr
->WriteSvIdl( rBase
, rOutStm
, nTab
+1 );
1484 pAttr
= pAttrList
->Next();
1486 rOutStm
<< ',' << endl
;
1489 WriteTab( rOutStm
, nTab
);
1495 else if ( nT
== WRITE_DOCU
)
1499 if( GetAttrCount() )
1501 SvMetaAttribute
* pAttr
= pAttrList
->First();
1504 pAttr
->WriteParam( rBase
, rOutStm
, nTab
+1, nT
);
1505 pAttr
= pAttrList
->Next();
1512 rOutStm
<< ')' << endl
;
1517 if( nT
== WRITE_C_HEADER
|| nT
== WRITE_C_SOURCE
)
1519 rOutStm
<< ' ' << C_PREF
<< "Object h" << rBase
.aIFaceName
.getStr();
1520 if( GetAttrCount() )
1526 if( GetAttrCount() )
1529 SvMetaAttribute
* pAttr
= pAttrList
->First();
1534 case WRITE_C_HEADER
:
1535 case WRITE_C_SOURCE
:
1538 pAttr
->WriteParam( rBase
, rOutStm
, nTab
+1, nT
);
1544 DBG_ASSERT( sal_False
, "WriteType not implemented" );
1547 pAttr
= pAttrList
->Next();
1549 rOutStm
<< ',' << endl
;
1551 if( nT
!= WRITE_C_HEADER
&& nT
!= WRITE_C_SOURCE
)
1554 WriteTab( rOutStm
, nTab
+1 );
1562 void SvMetaType::WriteTypePrefix( SvIdlDataBase
& rBase
, SvStream
& rOutStm
,
1563 sal_uInt16 nTab
, WriteType nT
)
1569 if( GetIn() && GetOut() )
1570 rOutStm
<< SvHash_inout()->GetName().getStr() << ' ';
1572 rOutStm
<< SvHash_in()->GetName().getStr() << ' ';
1574 rOutStm
<< SvHash_out()->GetName().getStr() << ' ';
1575 rOutStm
<< GetCString().getStr();
1581 sal_Bool bIn
= GetIn();
1582 sal_Bool bOut
= GetOut();
1586 rOutStm
<< "[in,out] ";
1590 rOutStm
<< "[out] ";
1594 if( GetType() == TYPE_METHOD
)
1595 out
= GetReturnType()->GetBaseType()->GetOdlName();
1598 SvMetaType
* pBType
= GetBaseType();
1599 out
= pBType
->GetOdlName();
1601 if( aCall0
== (int)CALL_POINTER
1602 || aCall0
== (int)CALL_REFERENCE
)
1604 if( aCall1
== (int)CALL_POINTER
1605 || aCall1
== (int)CALL_REFERENCE
)
1607 rOutStm
<< out
.getStr();
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()
1630 if ( pBaseType
->GetType() == TYPE_ENUM
)
1632 rOutStm
<< pBaseType
->GetCName().getStr();
1637 if( TYPE_STRUCT
== pBaseType
->GetType() )
1638 rOutStm
<< pBaseType
->GetName().getString().getStr() << " *";
1640 rOutStm
<< pBaseType
->GetName().getString().getStr();
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
);
1658 if( TYPE_STRUCT
== pBaseType
->GetType() )
1659 rOutStm
<< "VARIANT" << pBaseType
->GetName().getString().getStr();
1660 else if ( pBaseType
->GetType() == TYPE_ENUM
)
1661 rOutStm
<< "integer";
1663 rOutStm
<< pBaseType
->GetOdlName().getStr();
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();
1686 return pBT
->GetParserString();
1688 int type
= GetType();
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();
1702 aPStr
= rtl::OString(GetParserChar());
1706 void SvMetaType::WriteParamNames( SvIdlDataBase
& rBase
,
1708 const rtl::OString
& rChief
)
1710 SvMetaType
* pBT
= GetBaseType();
1712 pBT
->WriteParamNames( rBase
, rOutStm
, rChief
);
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
)
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
);
1764 rStm
.SetError( SVSTREAM_FILEFORMAT_ERROR
);
1765 OSL_FAIL( "wrong format" );
1768 if( nMask
& 0x01 ) aEnumValue
= read_lenPrefixed_uInt8s_ToOString
<sal_uInt16
>(rStm
);
1771 void SvMetaEnumValue::Save( SvPersistStream
& rStm
)
1773 SvMetaName::Save( rStm
);
1776 sal_uInt8 nMask
= 0;
1777 if( !aEnumValue
.isEmpty() ) nMask
|= 0x01;
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
) )
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();
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
);
1820 rStm
.SetError( SVSTREAM_FILEFORMAT_ERROR
);
1821 OSL_FAIL( "wrong format" );
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
);
1833 sal_uInt8 nMask
= 0;
1834 if( aEnumValueList
.Count() ) nMask
|= 0x01;
1835 if( !aPrefix
.isEmpty() ) nMask
|= 0x02;
1839 if( nMask
& 0x01 ) rStm
<< aEnumValueList
;
1840 if( nMask
& 0x02 ) write_lenPrefixed_uInt8s_FromOString
<sal_uInt16
>(rStm
, aPrefix
);
1845 rtl::OString
getCommonSubPrefix(const rtl::OString
&rA
, const rtl::OString
&rB
)
1847 sal_Int32 nMax
= std::min(rA
.getLength(), rB
.getLength());
1851 if (rA
[nI
] != rB
[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
);
1868 if( 0 == aEnumValueList
.Count() )
1871 aPrefix
= aEnumVal
->GetName().getString();
1875 aPrefix
= getCommonSubPrefix(aPrefix
, aEnumVal
->GetName().getString());
1877 aEnumValueList
.Append( aEnumVal
);
1880 rInStm
.Seek( nTokPos
);
1883 void SvMetaTypeEnum::WriteContextSvIdl( SvIdlDataBase
& rBase
,
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() )
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
) )
1908 rInStm
.Seek( nTokPos
);
1912 void SvMetaTypeEnum::WriteSvIdl( SvIdlDataBase
& rBase
, SvStream
& rOutStm
,
1915 WriteHeaderSvIdl( rBase
, rOutStm
, nTab
);
1917 SvMetaName::WriteSvIdl( rBase
, rOutStm
, nTab
);
1921 void SvMetaTypeEnum::Write( SvIdlDataBase
& rBase
, SvStream
& rOutStm
,
1923 WriteType nT
, WriteAttribute nA
)
1925 SvMetaType::Write( rBase
, rOutStm
, nTab
, nT
, nA
);
1928 void SvMetaTypeEnum::WriteContext( SvIdlDataBase
& rBase
, SvStream
& rOutStm
,
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() )
1941 rOutStm
<< ',' << endl
;
1942 WriteTab( rOutStm
, nTab
+1 );
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
;
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");
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: */