Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include <ctype.h>
22 : #include <stdio.h>
23 :
24 : #include <tools/debug.hxx>
25 :
26 : #include <types.hxx>
27 : #include <globals.hxx>
28 : #include <database.hxx>
29 :
30 4863 : SV_IMPL_META_FACTORY1( SvMetaAttribute, SvMetaReference );
31 17948 : SvMetaAttribute::SvMetaAttribute()
32 : : aAutomation( sal_True, sal_False )
33 : , aExport( sal_True, sal_False )
34 : , aIsCollection ( sal_False, sal_False )
35 : , aReadOnlyDoc ( sal_True, sal_False )
36 : , aHidden( sal_False, sal_False )
37 17948 : , bNewAttr( sal_False )
38 : {
39 17948 : }
40 :
41 4233 : SvMetaAttribute::SvMetaAttribute( SvMetaType * pType )
42 : : aType( pType )
43 : , aAutomation( sal_True, sal_False )
44 : , aExport( sal_True, sal_False )
45 : , aIsCollection ( sal_False, sal_False)
46 : , aReadOnlyDoc ( sal_True, sal_False)
47 : , aHidden( sal_False, sal_False )
48 4233 : , bNewAttr( sal_False )
49 : {
50 4233 : }
51 :
52 0 : void SvMetaAttribute::Load( SvPersistStream & rStm )
53 : {
54 0 : SvMetaReference::Load( rStm );
55 :
56 : sal_uInt8 nMask;
57 0 : rStm >> nMask;
58 0 : if( nMask & 0x01 )
59 : {
60 : SvMetaType * pType;
61 0 : rStm >> pType;
62 0 : aType = pType;
63 : }
64 0 : if( nMask & 0x02 ) rStm >> aSlotId;
65 0 : if( nMask & 0x04 ) rStm >> aExport;
66 0 : if( nMask & 0x08 ) rStm >> aReadonly;
67 0 : if( nMask & 0x10 ) rStm >> aAutomation;
68 0 : if( nMask & 0x20 ) rStm >> aIsCollection;
69 0 : if( nMask & 0x40 ) rStm >> aReadOnlyDoc;
70 0 : if( nMask & 0x80 ) rStm >> aHidden;
71 0 : }
72 :
73 17109 : void SvMetaAttribute::Save( SvPersistStream & rStm )
74 : {
75 17109 : SvMetaReference::Save( rStm );
76 :
77 : // create mask
78 17109 : sal_uInt8 nMask = 0;
79 17109 : if( aType.Is() ) nMask |= 0x1;
80 17109 : if( aSlotId.IsSet() ) nMask |= 0x2;
81 17109 : if( aExport.IsSet() ) nMask |= 0x4;
82 17109 : if( aReadonly.IsSet() ) nMask |= 0x8;
83 17109 : if( aAutomation.IsSet() ) nMask |= 0x10;
84 17109 : if( aIsCollection.IsSet() ) nMask |= 0x20;
85 17109 : if( aReadOnlyDoc.IsSet() ) nMask |= 0x40;
86 17109 : if( aHidden.IsSet() ) nMask |= 0x80;
87 :
88 : // write data
89 17109 : rStm << nMask;
90 17109 : if( nMask & 0x1 ) rStm << aType;
91 17109 : if( nMask & 0x2 ) rStm << aSlotId;
92 17109 : if( nMask & 0x4 ) rStm << aExport;
93 17109 : if( nMask & 0x8 ) rStm << aReadonly;
94 17109 : if( nMask & 0x10 ) rStm << aAutomation;
95 17109 : if( nMask & 0x20 ) rStm << aIsCollection;
96 17109 : if( nMask & 0x40 ) rStm << aReadOnlyDoc;
97 17109 : if( nMask & 0x80 ) rStm << aHidden;
98 17109 : }
99 :
100 276581 : SvMetaType * SvMetaAttribute::GetType() const
101 : {
102 276581 : if( aType.Is() || !GetRef() ) return aType;
103 81607 : return ((SvMetaAttribute *)GetRef())->GetType();
104 : }
105 :
106 9487711 : const SvNumberIdentifier & SvMetaAttribute::GetSlotId() const
107 : {
108 9487711 : if( aSlotId.IsSet() || !GetRef() ) return aSlotId;
109 933028 : return ((SvMetaAttribute *)GetRef())->GetSlotId();
110 : }
111 :
112 4920 : sal_Bool SvMetaAttribute::GetReadonly() const
113 : {
114 4920 : if( aReadonly.IsSet() || !GetRef() ) return aReadonly;
115 2460 : return ((SvMetaAttribute *)GetRef())->GetReadonly();
116 : }
117 :
118 44048 : sal_Bool SvMetaAttribute::GetExport() const
119 : {
120 44048 : if( aExport.IsSet() || !GetRef() ) return aExport;
121 20760 : return ((SvMetaAttribute *)GetRef())->GetExport();
122 : }
123 :
124 1677 : sal_Bool SvMetaAttribute::GetHidden() const
125 : {
126 : // when export is set, but hidden is not the default is used
127 1677 : if ( aExport.IsSet() && !aHidden.IsSet() )
128 1677 : return !aExport;
129 0 : else if( aHidden.IsSet() || !GetRef() )
130 0 : return aHidden;
131 : else
132 0 : return ((SvMetaAttribute *)GetRef())->GetHidden();
133 : }
134 :
135 0 : sal_Bool SvMetaAttribute::GetAutomation() const
136 : {
137 0 : if( aAutomation.IsSet() || !GetRef() ) return aAutomation;
138 0 : return ((SvMetaAttribute *)GetRef())->GetAutomation();
139 : }
140 :
141 0 : sal_Bool SvMetaAttribute::GetIsCollection() const
142 : {
143 : sal_Bool bRet;
144 0 : if( aIsCollection.IsSet() || !GetRef() )
145 : {
146 0 : if ( aIsCollection.IsSet() )
147 : {
148 0 : bRet = aIsCollection;
149 0 : return bRet;
150 : }
151 :
152 0 : return aIsCollection;
153 : }
154 :
155 0 : return ((SvMetaSlot *)GetRef())->GetIsCollection();
156 : }
157 :
158 11592 : sal_Bool SvMetaAttribute::GetReadOnlyDoc() const
159 : {
160 11592 : if( aReadOnlyDoc.IsSet() || !GetRef() ) return aReadOnlyDoc;
161 5753 : return ((SvMetaSlot *)GetRef())->GetReadOnlyDoc();
162 : }
163 :
164 23246 : sal_Bool SvMetaAttribute::IsMethod() const
165 : {
166 23246 : SvMetaType * pType = GetType();
167 : DBG_ASSERT( pType, "no type for attribute" );
168 23246 : return pType->GetType() == TYPE_METHOD;
169 : }
170 :
171 16266 : sal_Bool SvMetaAttribute::IsVariable() const
172 : {
173 16266 : SvMetaType * pType = GetType();
174 16266 : return pType->GetType() != TYPE_METHOD;
175 : }
176 :
177 0 : OString SvMetaAttribute::GetMangleName( sal_Bool ) const
178 : {
179 0 : return GetName().getString();
180 : }
181 :
182 17109 : sal_Bool SvMetaAttribute::Test( SvIdlDataBase & rBase,
183 : SvTokenStream & rInStm )
184 : {
185 17109 : sal_Bool bOk = sal_True;
186 17109 : if( GetType()->IsItem() && !GetSlotId().IsSet() )
187 : {
188 0 : rBase.SetError( "slot without id declared", rInStm.GetToken() );
189 0 : rBase.WriteError( rInStm );
190 0 : bOk = sal_False;
191 : }
192 17109 : return bOk;
193 : }
194 :
195 18185 : sal_Bool SvMetaAttribute::ReadSvIdl( SvIdlDataBase & rBase,
196 : SvTokenStream & rInStm )
197 : {
198 18185 : sal_uInt32 nTokPos = rInStm.Tell();
199 18185 : if( !GetType() )
200 : // no type in ctor passed on
201 18143 : aType = rBase.ReadKnownType( rInStm );
202 18185 : sal_Bool bOk = sal_False;
203 18185 : if( GetType() )
204 : {
205 13113 : ReadNameSvIdl( rBase, rInStm );
206 13113 : aSlotId.ReadSvIdl( rBase, rInStm );
207 :
208 13113 : bOk = sal_True;
209 13113 : SvToken * pTok = rInStm.GetToken();
210 13113 : if( bOk && pTok->IsChar() && pTok->GetChar() == '(' )
211 : {
212 4428 : SvMetaTypeRef xT = new SvMetaType();
213 4428 : xT->SetRef( GetType() );
214 4428 : aType = xT;
215 4428 : bOk = aType->ReadMethodArgs( rBase, rInStm );
216 : }
217 13113 : if( bOk )
218 13113 : bOk = SvMetaName::ReadSvIdl( rBase, rInStm );
219 : }
220 : else
221 : {
222 5072 : SvToken *pTok = rInStm.GetToken();
223 : rBase.SetError( "unknown type of token. Each new SID needs an "
224 : "item statement in an SDI file, eg. "
225 10144 : "SfxVoidItem FooItem " + pTok->GetTokenAsString() +
226 5072 : " ... which describes the slot more fully", pTok );
227 : }
228 :
229 18185 : if( !bOk )
230 5072 : rInStm.Seek( nTokPos );
231 18185 : return bOk;
232 : }
233 :
234 18657 : void SvMetaAttribute::WriteSvIdl
235 : (
236 : SvIdlDataBase & rBase,
237 : SvStream & rOutStm,
238 : sal_uInt16 nTab
239 : )
240 : {
241 18657 : SvMetaType * pType = GetType();
242 18657 : pType->WriteTypePrefix( rBase, rOutStm, nTab, WRITE_IDL );
243 18657 : rOutStm << ' ' << GetName().getString().getStr();
244 18657 : if( aSlotId.IsSet() )
245 14661 : rOutStm << ' ' << aSlotId.getString().getStr();
246 18657 : if( pType->GetType() == TYPE_METHOD )
247 6735 : pType->WriteMethodArgs( rBase, rOutStm, nTab, WRITE_IDL );
248 18657 : sal_uLong nPos = rOutStm.Tell();
249 18657 : rOutStm << endl;
250 18657 : SvMetaName::WriteSvIdl( rBase, rOutStm, nTab );
251 18657 : TestAndSeekSpaceOnly( rOutStm, nPos );
252 18657 : }
253 :
254 165612 : void SvMetaAttribute::ReadAttributesSvIdl( SvIdlDataBase & rBase,
255 : SvTokenStream & rInStm )
256 : {
257 165612 : SvMetaReference::ReadAttributesSvIdl( rBase, rInStm );
258 165612 : aSlotId.ReadSvIdl( rBase, SvHash_SlotId(), rInStm );
259 165612 : aExport.ReadSvIdl( SvHash_Export(), rInStm );
260 165612 : aHidden.ReadSvIdl( SvHash_Hidden(), rInStm );
261 165612 : aAutomation.ReadSvIdl( SvHash_Automation(), rInStm );
262 165612 : aIsCollection.ReadSvIdl( SvHash_IsCollection(), rInStm );
263 165612 : aReadOnlyDoc.ReadSvIdl( SvHash_ReadOnlyDoc(), rInStm );
264 165612 : if( aReadonly.ReadSvIdl( SvHash_Readonly(), rInStm ) )
265 : {
266 3582 : if( GetType()->GetType() == TYPE_METHOD )
267 : {
268 : // set error
269 0 : rBase.SetError( "Readonly in function attribute", rInStm.GetToken() );
270 0 : rBase.WriteError( rInStm );
271 : }
272 : }
273 165612 : }
274 :
275 18657 : void SvMetaAttribute::WriteAttributesSvIdl
276 : (
277 : SvIdlDataBase & rBase,
278 : SvStream & rOutStm,
279 : sal_uInt16 nTab
280 : )
281 : {
282 18657 : SvMetaReference::WriteAttributesSvIdl( rBase, rOutStm, nTab );
283 :
284 18657 : if( !aExport || !aAutomation || aReadonly )
285 : {
286 771 : WriteTab( rOutStm, nTab );
287 771 : rOutStm << "//class SvMetaAttribute" << endl;
288 771 : if( !aExport )
289 : {
290 479 : WriteTab( rOutStm, nTab );
291 479 : aExport.WriteSvIdl( SvHash_Export(), rOutStm );
292 479 : rOutStm << ';' << endl;
293 : }
294 771 : if ( aHidden != aExport )
295 : {
296 292 : WriteTab( rOutStm, nTab );
297 292 : aExport.WriteSvIdl( SvHash_Hidden(), rOutStm );
298 292 : rOutStm << ';' << endl;
299 : }
300 771 : if( aReadonly )
301 : {
302 292 : WriteTab( rOutStm, nTab );
303 292 : aReadonly.WriteSvIdl( SvHash_Readonly(), rOutStm );
304 292 : rOutStm << ';' << endl;
305 : }
306 771 : if( !aAutomation )
307 : {
308 0 : WriteTab( rOutStm, nTab );
309 0 : aAutomation.WriteSvIdl( SvHash_Automation(), rOutStm );
310 0 : rOutStm << ';' << endl;
311 : }
312 771 : if( aIsCollection )
313 : {
314 1 : WriteTab( rOutStm, nTab );
315 1 : aIsCollection.WriteSvIdl( SvHash_IsCollection(), rOutStm );
316 1 : rOutStm << ';' << endl;
317 : }
318 771 : if( !aReadOnlyDoc )
319 : {
320 34 : WriteTab( rOutStm, nTab );
321 34 : aReadOnlyDoc.WriteSvIdl( SvHash_ReadOnlyDoc(), rOutStm );
322 34 : rOutStm << ';' << endl;
323 : }
324 : }
325 18657 : }
326 :
327 0 : void SvMetaAttribute::WriteParam( SvIdlDataBase & rBase,
328 : SvStream & rOutStm,
329 : sal_uInt16 nTab,
330 : WriteType nT )
331 : {
332 0 : SvMetaType * pType = GetType();
333 : DBG_ASSERT( pType, "no type for attribute" );
334 0 : SvMetaType * pBaseType = pType->GetBaseType();
335 : DBG_ASSERT( pBaseType, "no base type for attribute" );
336 :
337 0 : if( nT == WRITE_ODL || nT == WRITE_DOCU
338 0 : || nT == WRITE_C_HEADER || nT == WRITE_C_SOURCE )
339 : {
340 0 : if( pBaseType->GetType() == TYPE_STRUCT )
341 : {
342 0 : const SvMetaAttributeMemberList & rList = pBaseType->GetAttrList();
343 0 : sal_uLong nCount = rList.size();
344 0 : for( sal_uLong i = 0; i < nCount; i++ )
345 : {
346 0 : rList[i]->WriteParam( rBase, rOutStm, nTab, nT );
347 0 : if( i+1<nCount )
348 : {
349 0 : rOutStm << ',';
350 : }
351 : }
352 : }
353 : else
354 : {
355 0 : if ( nT != WRITE_DOCU )
356 : {
357 0 : WriteTab( rOutStm, nTab );
358 0 : pBaseType->WriteTypePrefix( rBase, rOutStm, nTab, nT );
359 : }
360 :
361 0 : if( !GetName().getString().isEmpty() )
362 : {
363 0 : rOutStm << ' ';
364 0 : rOutStm << GetName().getString().getStr();
365 : }
366 :
367 0 : if ( nT == WRITE_DOCU )
368 : {
369 0 : if( pBaseType->GetType() == TYPE_METHOD ||
370 0 : pBaseType->GetType() == TYPE_STRUCT ||
371 0 : pBaseType->GetType() == TYPE_ENUM )
372 : {
373 : OSL_FAIL( "Falscher Parametertyp!" );
374 : }
375 : else
376 0 : rOutStm << pBaseType->GetBasicPostfix().getStr();
377 : }
378 : }
379 : }
380 0 : }
381 :
382 0 : sal_uLong SvMetaAttribute::MakeSlotValue( SvIdlDataBase & rBase, sal_Bool bVar ) const
383 : {
384 0 : const SvNumberIdentifier & rId = GetSlotId();
385 0 : sal_uLong n = rId.GetValue();
386 0 : if( !rBase.aStructSlotId.getString().isEmpty() )
387 : {
388 0 : n = n << 20;
389 0 : n += rBase.aStructSlotId.GetValue();
390 : }
391 0 : if( PTR_CAST( SvMetaSlot, this ) )
392 0 : n |= 0x20000;
393 0 : if( !bVar )
394 0 : n += 0x10000;
395 0 : else if ( GetIsCollection() )
396 0 : n += 0x40000;
397 0 : return n;
398 : }
399 :
400 0 : void SvMetaAttribute::WriteAttributes( SvIdlDataBase & rBase, SvStream & rOutStm,
401 : sal_uInt16 nTab,
402 : WriteType nT, WriteAttribute nA )
403 : {
404 0 : if( nT == WRITE_ODL )
405 : {
406 0 : const SvNumberIdentifier & rId = GetSlotId();
407 0 : sal_Bool bReadonly = GetReadonly() || ( nA & WA_READONLY );
408 0 : if( (rId.IsSet() && !(nA & WA_STRUCT)) || bReadonly )
409 : {
410 0 : sal_Bool bVar = IsVariable();
411 0 : if( nA & WA_VARIABLE )
412 0 : bVar = sal_True;
413 0 : else if( nA & WA_METHOD )
414 0 : bVar = sal_False;
415 :
416 0 : WriteTab( rOutStm, nTab );
417 0 : rOutStm << "//class SvMetaAttribute" << endl;
418 0 : if( rId.IsSet() && !(nA & WA_STRUCT) )
419 : {
420 0 : WriteTab( rOutStm, nTab );
421 0 : rOutStm << "id("
422 0 : << OString::valueOf(static_cast<sal_Int32>(MakeSlotValue(rBase,bVar))).getStr()
423 0 : << ")," << endl;
424 : }
425 0 : if( bVar && (bReadonly || IsMethod()) )
426 : {
427 0 : WriteTab( rOutStm, nTab );
428 0 : rOutStm << "readonly," << endl;
429 : }
430 : }
431 : }
432 0 : }
433 :
434 0 : void SvMetaAttribute::WriteCSource( SvIdlDataBase & rBase, SvStream & rOutStm,
435 : sal_Bool bSet )
436 : {
437 0 : rOutStm << endl;
438 0 : SvMetaType * pType = GetType();
439 0 : SvMetaType * pBaseType = pType->GetBaseType();
440 :
441 : // for Set the return is always void
442 0 : sal_Bool bVoid = bSet;
443 0 : if( pBaseType->GetType() == TYPE_METHOD )
444 0 : bVoid = pBaseType->GetReturnType()->GetBaseType()->GetName().getString() == "void";
445 :
446 : // emit methods/functions body
447 0 : rOutStm << '{' << endl;
448 0 : WriteTab( rOutStm, 1 );
449 :
450 0 : if( !bVoid )
451 : {
452 0 : if ( pBaseType->GetCName() == "double" )
453 : {
454 0 : rOutStm << "return *(double*)";
455 : }
456 : else
457 : {
458 0 : rOutStm << "return (";
459 0 : pType->WriteTypePrefix( rBase, rOutStm, 2, WRITE_C_SOURCE );
460 0 : rOutStm << ") ";
461 : }
462 : }
463 0 : rOutStm << "pODKCallFunction( "
464 0 : << OString::valueOf(static_cast<sal_Int32>(MakeSlotValue(rBase, IsVariable()))).getStr();
465 0 : rOutStm << ',' << endl;
466 0 : WriteTab( rOutStm, 3 );
467 0 : rOutStm << " h" << rBase.aIFaceName.getStr() << " , ";
468 :
469 0 : OString aParserStr;
470 0 : if( pBaseType->GetType() == TYPE_METHOD || bSet )
471 0 : aParserStr = pBaseType->GetParserString();
472 0 : if( !aParserStr.isEmpty() )
473 : {
474 0 : rOutStm << '\"';
475 0 : rOutStm << aParserStr.getStr();
476 0 : rOutStm << "\", ";
477 : }
478 : else
479 0 : rOutStm << "NULL, ";
480 :
481 0 : if( pBaseType->GetType() == TYPE_METHOD && !bVoid )
482 : {
483 0 : rOutStm << "'";
484 0 : rOutStm << pBaseType->GetReturnType()->GetBaseType()->GetParserChar();
485 0 : rOutStm << "'";
486 : }
487 0 : else if ( !bSet )
488 : {
489 0 : rOutStm << "'";
490 0 : rOutStm << pBaseType->GetParserChar();
491 0 : rOutStm << "'";
492 : }
493 : else
494 0 : rOutStm << '0';
495 :
496 0 : if( !aParserStr.isEmpty() )
497 : {
498 0 : rOutStm << ", ";
499 0 : if( IsMethod() )
500 0 : pBaseType->WriteParamNames( rBase, rOutStm, OString() );
501 0 : else if( bSet )
502 0 : pBaseType->WriteParamNames( rBase, rOutStm, GetName().getString() );
503 : }
504 :
505 0 : rOutStm << " );" << endl;
506 0 : rOutStm << '}' << endl;
507 0 : }
508 :
509 0 : void SvMetaAttribute::WriteRecursiv_Impl( SvIdlDataBase & rBase,
510 : SvStream & rOutStm, sal_uInt16 nTab,
511 : WriteType nT, WriteAttribute nA )
512 : {
513 0 : const SvMetaAttributeMemberList & rList = GetType()->GetBaseType()->GetAttrList();
514 0 : sal_uLong nCount = rList.size();
515 :
516 0 : SvNumberIdentifier slotId = rBase.aStructSlotId;
517 0 : if ( !GetSlotId().getString().isEmpty() )
518 0 : rBase.aStructSlotId = GetSlotId();
519 :
520 : // offial hack interface by MM: special controls get passed with the WriteAttribute
521 0 : if ( GetReadonly() )
522 0 : nA |= WA_READONLY;
523 :
524 0 : for( sal_uLong i = 0; i < nCount; i++ )
525 : {
526 0 : SvMetaAttribute *pAttr = rList[i];
527 0 : if ( nT == WRITE_DOCU )
528 0 : pAttr->SetDescription( GetDescription().getString() );
529 0 : pAttr->Write( rBase, rOutStm, nTab, nT, nA );
530 0 : if( nT == WRITE_ODL && i +1 < nCount )
531 0 : rOutStm << ';' << endl;
532 : }
533 :
534 0 : rBase.aStructSlotId = slotId;
535 0 : }
536 :
537 0 : void SvMetaAttribute::Write( SvIdlDataBase & rBase, SvStream & rOutStm,
538 : sal_uInt16 nTab,
539 : WriteType nT, WriteAttribute nA )
540 : {
541 : // no attributes for automation
542 0 : if( nT == WRITE_DOCU )
543 : {
544 0 : if ( GetHidden() )
545 0 : return;
546 : }
547 0 : else if ( !GetAutomation() || !GetExport() )
548 0 : return;
549 :
550 : sal_Bool bVariable;
551 0 : if( nA & WA_VARIABLE )
552 0 : bVariable = sal_True;
553 0 : else if( nA & WA_METHOD )
554 0 : bVariable = sal_False;
555 : else
556 0 : bVariable = IsVariable();
557 :
558 0 : SvMetaType * pType = GetType();
559 : DBG_ASSERT( pType, "no type for attribute" );
560 0 : SvMetaType * pBaseType = pType->GetBaseType();
561 : DBG_ASSERT( pBaseType, "no base type for attribute" );
562 0 : int nBType = pBaseType->GetType();
563 :
564 0 : if( nT == WRITE_ODL )
565 : {
566 0 : if( (bVariable && IsVariable()) || (!bVariable && IsMethod()) )
567 : {
568 0 : if( nBType == TYPE_STRUCT )
569 0 : WriteRecursiv_Impl( rBase, rOutStm, nTab, nT, nA );
570 : else
571 : {
572 0 : SvMetaReference::Write( rBase, rOutStm, nTab, nT, nA );
573 0 : WriteTab( rOutStm, nTab );
574 0 : pBaseType->WriteTypePrefix( rBase, rOutStm, nTab, nT );
575 :
576 0 : if( !GetName().getString().isEmpty() )
577 : {
578 0 : rOutStm << ' ';
579 0 : rOutStm << GetName().getString().getStr();
580 : }
581 0 : if( pType->GetType() == TYPE_METHOD )
582 0 : pType->WriteMethodArgs( rBase, rOutStm, nTab, nT );
583 : }
584 : }
585 : }
586 0 : else if( nT == WRITE_C_HEADER || nT == WRITE_C_SOURCE )
587 : {
588 0 : if( !bVariable && IsMethod() )
589 : {
590 0 : OString name = rBase.aIFaceName + GetName().getString();
591 0 : const char * pName = name.getStr();
592 0 : WriteTab( rOutStm, nTab );
593 0 : pBaseType->WriteTypePrefix( rBase, rOutStm, nTab, nT );
594 0 : rOutStm << ' ' << pName;
595 0 : pType->WriteMethodArgs( rBase, rOutStm, nTab, nT );
596 0 : if( nT == WRITE_C_HEADER )
597 0 : rOutStm << ';' << endl << endl;
598 : else
599 0 : WriteCSource( rBase, rOutStm, sal_False );
600 : }
601 0 : else if ( bVariable && IsVariable() )
602 : {
603 0 : if( nBType == TYPE_STRUCT )
604 : {
605 : // for assistance emit the name of the property as acomment
606 0 : rOutStm << "/* " << GetName().getString().getStr() << " */" << endl;
607 :
608 0 : WriteRecursiv_Impl( rBase, rOutStm, nTab, nT, nA );
609 : }
610 : else
611 : {
612 0 : OString name = GetName().getString();
613 :
614 0 : sal_Bool bReadonly = GetReadonly() || ( nA & WA_READONLY );
615 0 : if ( !bReadonly && !IsMethod() )
616 : {
617 : // allocation
618 0 : WriteTab( rOutStm, nTab );
619 0 : rOutStm << "void ";
620 0 : rOutStm << rBase.aIFaceName.getStr()
621 0 : << "Set" << name.getStr() << "( " << C_PREF
622 0 : << "Object h" << rBase.aIFaceName.getStr() << ", " << endl;
623 0 : WriteTab( rOutStm, nTab+1 );
624 0 : pBaseType->WriteTypePrefix( rBase, rOutStm, nTab, nT );
625 0 : rOutStm << ' ' << name.getStr() << " )";
626 0 : if( nT == WRITE_C_HEADER )
627 0 : rOutStm << ';' << endl << endl;
628 : else
629 0 : WriteCSource( rBase, rOutStm, sal_True );
630 : }
631 :
632 : // access
633 0 : WriteTab( rOutStm, nTab );
634 0 : pBaseType->WriteTypePrefix( rBase, rOutStm, nTab, nT );
635 0 : rOutStm << ' ';
636 0 : rOutStm << rBase.aIFaceName.getStr()
637 0 : << "Get" << name.getStr() << "( " << C_PREF
638 0 : << "Object h" << rBase.aIFaceName.getStr() << " )";
639 0 : if( nT == WRITE_C_HEADER )
640 0 : rOutStm << ';' << endl << endl;
641 : else
642 0 : WriteCSource( rBase, rOutStm, sal_False );
643 : }
644 0 : }
645 : }
646 0 : else if ( nT == WRITE_DOCU )
647 : {
648 0 : if( !bVariable && IsMethod() )
649 : {
650 0 : rOutStm << "<METHOD>" << endl
651 0 : << GetSlotId().getString().getStr() << endl
652 0 : << GetName().getString().getStr() << endl
653 0 : << endl; // readonly
654 :
655 : // return type
656 0 : SvMetaType* pType2 = GetType();
657 0 : SvMetaType* pBaseType2 = pType2->GetBaseType();
658 0 : rOutStm << pBaseType2->GetReturnType()->GetBaseType()->GetBasicName().getStr() << endl;
659 :
660 : DBG_ASSERT( !pBaseType2->GetReturnType()->GetBaseType()->GetBasicName().isEmpty(),
661 : "Leerer BasicName" );
662 :
663 : // syntax
664 0 : rOutStm << GetName().getString().getStr();
665 0 : pType2->WriteMethodArgs( rBase, rOutStm, nTab, nT );
666 :
667 : // C return type
668 0 : pBaseType2->WriteTypePrefix( rBase, rOutStm, 0, WRITE_C_HEADER );
669 0 : rOutStm << endl;
670 :
671 : // for methods also C syntax
672 0 : rOutStm << "<C-SYNTAX>" << endl;
673 0 : Write( rBase, rOutStm, 0, WRITE_C_HEADER, nA );
674 0 : rOutStm << "</C-SYNTAX>" << endl;
675 :
676 : // description
677 0 : WriteDescription( rOutStm );
678 0 : rOutStm << "</METHOD>" << endl << endl;
679 : }
680 0 : else if( bVariable && IsVariable() )
681 : {
682 0 : if( nBType == TYPE_STRUCT )
683 : {
684 0 : WriteRecursiv_Impl( rBase, rOutStm, nTab, nT, nA );
685 : }
686 : else
687 : {
688 0 : rOutStm << "<PROPERTY>" << endl
689 0 : << GetSlotId().getString().getStr() << endl
690 0 : << GetName().getString().getStr() << endl;
691 0 : if ( GetReadonly() )
692 0 : rOutStm << "(nur lesen)" << endl;
693 : else
694 0 : rOutStm << endl;
695 :
696 : // for properties type instead of the return value
697 0 : rOutStm << pBaseType->GetBasicName().getStr() << endl;
698 :
699 : DBG_ASSERT( !pBaseType->GetBasicName().isEmpty(),
700 : "Leerer BasicName" );
701 :
702 : // for properties no syntax
703 0 : rOutStm << endl;
704 :
705 : // C return type
706 0 : pBaseType->WriteTypePrefix( rBase, rOutStm, 0, WRITE_C_HEADER );
707 0 : rOutStm << endl;
708 :
709 : // description
710 0 : WriteDescription( rOutStm );
711 0 : rOutStm << "</PROPERTY>" << endl << endl;
712 : }
713 : }
714 : }
715 : }
716 :
717 673 : sal_uLong SvMetaAttribute::MakeSfx( OStringBuffer& rAttrArray )
718 : {
719 673 : SvMetaType * pType = GetType();
720 : DBG_ASSERT( pType, "no type for attribute" );
721 673 : SvMetaType * pBaseType = pType->GetBaseType();
722 : DBG_ASSERT( pBaseType, "no base type for attribute" );
723 673 : if( pBaseType->GetType() == TYPE_STRUCT )
724 0 : return pBaseType->MakeSfx( rAttrArray );
725 : else
726 : {
727 673 : rAttrArray.append('{');
728 673 : rAttrArray.append(GetSlotId().getString());
729 673 : rAttrArray.append(",\"");
730 673 : rAttrArray.append(GetName().getString());
731 673 : rAttrArray.append("\"}");
732 673 : return 1;
733 : }
734 : }
735 :
736 9 : void SvMetaAttribute::Insert (SvSlotElementList&, const OString&, SvIdlDataBase&)
737 : {
738 9 : }
739 :
740 16 : void SvMetaAttribute::WriteHelpId( SvIdlDataBase &, SvStream &, HelpIdTable& )
741 : {
742 16 : }
743 :
744 75605 : SV_IMPL_META_FACTORY1( SvMetaType, SvMetaExtern );
745 : #define CTOR \
746 : : aCall0( CALL_VALUE, sal_False ) \
747 : , aCall1( CALL_VALUE, sal_False ) \
748 : , aSbxDataType( 0, sal_False ) \
749 : , pAttrList( NULL ) \
750 : , nType( TYPE_BASE ) \
751 : , bIsItem( sal_False ) \
752 : , bIsShell( sal_False ) \
753 : , cParserChar( 'h' )
754 :
755 6315 : SvMetaType::SvMetaType()
756 6315 : CTOR
757 : {
758 6315 : }
759 :
760 0 : SvMetaType::SvMetaType( const OString& rName, char cPC,
761 : const OString& rCName )
762 0 : CTOR
763 : {
764 0 : SetName( rName );
765 0 : cParserChar = cPC;
766 0 : aCName.setString(rCName);
767 0 : }
768 :
769 104 : SvMetaType::SvMetaType( const OString& rName,
770 : const OString& rSbxName,
771 : const OString& rOdlName,
772 : char cPc,
773 : const OString& rCName,
774 : const OString& rBasicName,
775 : const OString& rBasicPostfix )
776 104 : CTOR
777 : {
778 104 : SetName( rName );
779 104 : aSbxName.setString(rSbxName);
780 104 : aOdlName.setString(rOdlName);
781 104 : cParserChar = cPc;
782 104 : aCName.setString(rCName);
783 104 : aBasicName.setString(rBasicName);
784 104 : aBasicPostfix.setString(rBasicPostfix);
785 104 : }
786 :
787 0 : void SvMetaType::Load( SvPersistStream & rStm )
788 : {
789 0 : SvMetaExtern::Load( rStm );
790 :
791 : sal_uInt16 nMask;
792 0 : rStm >> nMask;
793 0 : if( nMask & 0x0001 ) rStm >> aIn;
794 0 : if( nMask & 0x0002 ) rStm >> aOut;
795 0 : if( nMask & 0x0004 ) rStm >> aCall0;
796 0 : if( nMask & 0x0008 ) rStm >> aCall1;
797 0 : if( nMask & 0x0010 ) rStm >> aSbxDataType;
798 0 : if( nMask & 0x0020 ) rStm >> aSvName;
799 0 : if( nMask & 0x0040 ) rStm >> aSbxName;
800 0 : if( nMask & 0x0080 ) rStm >> aOdlName;
801 0 : if( nMask & 0x0100 ) rStm >> GetAttrList();
802 0 : if( nMask & 0x0200 ) bIsItem = sal_True;
803 0 : if( nMask & 0x0400 ) bIsShell = sal_True;
804 0 : if( nMask & 0x0800 )
805 : {
806 : sal_uInt16 nT;
807 0 : rStm >> nT;
808 0 : nType = nT;
809 : }
810 0 : if( nMask & 0x1000 ) rStm >> cParserChar;
811 0 : if( nMask & 0x2000 ) rStm >> aCName;
812 0 : if( nMask & 0x4000 ) rStm >> aBasicName;
813 0 : if( nMask & 0x8000 ) rStm >> aBasicPostfix;
814 0 : }
815 :
816 6419 : void SvMetaType::Save( SvPersistStream & rStm )
817 : {
818 6419 : SvMetaExtern::Save( rStm );
819 :
820 : // create mask
821 6419 : sal_uInt16 nMask = 0;
822 6419 : if( aIn.IsSet() ) nMask |= 0x0001;
823 6419 : if( aOut.IsSet() ) nMask |= 0x0002;
824 6419 : if( aCall0.IsSet() ) nMask |= 0x0004;
825 6419 : if( aCall1.IsSet() ) nMask |= 0x0008;
826 6419 : if( aSbxDataType.IsSet() ) nMask |= 0x0010;
827 6419 : if( aSvName.IsSet() ) nMask |= 0x0020;
828 6419 : if( aSbxName.IsSet() ) nMask |= 0x0040;
829 6419 : if( aOdlName.IsSet() ) nMask |= 0x0080;
830 6419 : if( GetAttrCount() ) nMask |= 0x0100;
831 6419 : if( bIsItem ) nMask |= 0x0200;
832 6419 : if( bIsShell ) nMask |= 0x0400;
833 6419 : if( nType != TYPE_BASE ) nMask |= 0x0800;
834 6419 : if( cParserChar != 'h' ) nMask |= 0x1000;
835 6419 : if( aCName.IsSet() ) nMask |= 0x2000;
836 6419 : if( aBasicName.IsSet() ) nMask |= 0x4000;
837 6419 : if( aBasicPostfix.IsSet() ) nMask |= 0x8000;
838 :
839 : // write data
840 6419 : rStm << nMask;
841 6419 : if( nMask & 0x0001 ) rStm << aIn;
842 6419 : if( nMask & 0x0002 ) rStm << aOut;
843 6419 : if( nMask & 0x0004 ) rStm << aCall0;
844 6419 : if( nMask & 0x0008 ) rStm << aCall1;
845 6419 : if( nMask & 0x0010 ) rStm << aSbxDataType;
846 6419 : if( nMask & 0x0020 ) rStm << aSvName;
847 6419 : if( nMask & 0x0040 ) rStm << aSbxName;
848 6419 : if( nMask & 0x0080 ) rStm << aOdlName;
849 6419 : if( nMask & 0x0100 ) rStm << *pAttrList;
850 6419 : if( nMask & 0x0800 ) rStm << (sal_uInt16)nType;
851 6419 : if( nMask & 0x1000 ) rStm << cParserChar;
852 6419 : if( nMask & 0x2000 ) rStm << aCName;
853 6419 : if( nMask & 0x4000 ) rStm << aBasicName;
854 6419 : if( nMask & 0x8000 ) rStm << aBasicPostfix;
855 6419 : }
856 :
857 8154 : SvMetaAttributeMemberList & SvMetaType::GetAttrList() const
858 : {
859 8154 : if( !pAttrList )
860 3073 : ((SvMetaType *)this)->pAttrList = new SvMetaAttributeMemberList();
861 8154 : return *pAttrList;
862 : }
863 :
864 5149 : void SvMetaType::SetType( int nT )
865 : {
866 5149 : nType = nT;
867 5149 : if( nType == TYPE_ENUM )
868 : {
869 219 : aOdlName.setString("short");
870 : }
871 4930 : else if( nType == TYPE_CLASS )
872 : {
873 195 : OStringBuffer aTmp(C_PREF);
874 195 : aTmp.append(RTL_CONSTASCII_STRINGPARAM("Object *"));
875 195 : aCName.setString(aTmp.makeStringAndClear());
876 : }
877 5149 : }
878 :
879 15311 : SvMetaType * SvMetaType::GetBaseType() const
880 : {
881 15311 : if( GetRef() && GetType() == TYPE_BASE )
882 5595 : return ((SvMetaType *)GetRef())->GetBaseType();
883 9716 : return (SvMetaType *)this;
884 : }
885 :
886 6731 : SvMetaType * SvMetaType::GetReturnType() const
887 : {
888 : DBG_ASSERT( GetType() == TYPE_METHOD, "no method" );
889 : DBG_ASSERT( GetRef(), "no return type" );
890 6731 : return (SvMetaType *)GetRef();
891 : }
892 :
893 0 : const OString& SvMetaType::GetBasicName() const
894 : {
895 0 : if( aBasicName.IsSet() || !GetRef() )
896 0 : return aBasicName.getString();
897 : else
898 0 : return ((SvMetaType*)GetRef())->GetBasicName();
899 : }
900 :
901 0 : OString SvMetaType::GetBasicPostfix() const
902 : {
903 : // MBN and Co always want "As xxx"
904 : return OStringBuffer(RTL_CONSTASCII_STRINGPARAM(" As ")).
905 0 : append(GetBasicName()).
906 0 : makeStringAndClear();
907 : }
908 :
909 91202 : sal_Bool SvMetaType::GetIn() const
910 : {
911 91202 : if( aIn.IsSet() || !GetRef() )
912 41286 : return aIn;
913 : else
914 49916 : return ((SvMetaType *)GetRef())->GetIn();
915 : }
916 :
917 45601 : sal_Bool SvMetaType::GetOut() const
918 : {
919 45601 : if( aOut.IsSet() || !GetRef() )
920 20643 : return aOut;
921 : else
922 24958 : return ((SvMetaType *)GetRef())->GetOut();
923 : }
924 :
925 0 : void SvMetaType::SetCall0( int e )
926 : {
927 0 : aCall0 = (int)e;
928 0 : if( aCall0 == CALL_VALUE && aCall1 == CALL_VALUE )
929 : {
930 0 : if( GetType() == TYPE_POINTER )
931 0 : SetType( TYPE_BASE );
932 : }
933 : else
934 : {
935 : DBG_ASSERT( nType == TYPE_POINTER || nType == TYPE_BASE,
936 : "set no base type to pointer" );
937 0 : SetType( TYPE_POINTER );
938 : }
939 0 : }
940 :
941 0 : int SvMetaType::GetCall0() const
942 : {
943 0 : if( aCall0.IsSet() || !GetRef() )
944 0 : return aCall0;
945 : else
946 0 : return ((SvMetaType *)GetRef())->GetCall0();
947 : }
948 :
949 0 : void SvMetaType::SetCall1( int e )
950 : {
951 0 : aCall1 = (int)e;
952 0 : if( aCall0 == CALL_VALUE && aCall1 == CALL_VALUE )
953 : {
954 0 : if( GetType() == TYPE_POINTER )
955 0 : SetType( TYPE_BASE );
956 : }
957 : else
958 : {
959 : DBG_ASSERT( nType == TYPE_POINTER || nType == TYPE_BASE,
960 : "set no base type to pointer" );
961 0 : SetType( TYPE_POINTER );
962 : }
963 0 : }
964 :
965 0 : int SvMetaType::GetCall1() const
966 : {
967 0 : if( aCall1.IsSet() || !GetRef() )
968 0 : return aCall1;
969 : else
970 0 : return ((SvMetaType *)GetRef())->GetCall1();
971 : }
972 :
973 27378 : const OString& SvMetaType::GetSvName() const
974 : {
975 27378 : if( aSvName.IsSet() || !GetRef() )
976 20643 : return aSvName.getString();
977 : else
978 6735 : return ((SvMetaType *)GetRef())->GetSvName();
979 : }
980 :
981 0 : const OString& SvMetaType::GetSbxName() const
982 : {
983 0 : if( aSbxName.IsSet() || !GetRef() )
984 0 : return aSbxName.getString();
985 : else
986 0 : return ((SvMetaType *)GetRef())->GetSbxName();
987 : }
988 :
989 0 : const OString& SvMetaType::GetOdlName() const
990 : {
991 0 : if( aOdlName.IsSet() || !GetRef() )
992 0 : return aOdlName.getString();
993 : else
994 0 : return ((SvMetaType *)GetRef())->GetOdlName();
995 : }
996 :
997 0 : const OString& SvMetaType::GetCName() const
998 : {
999 0 : if( aCName.IsSet() || !GetRef() )
1000 0 : return aCName.getString();
1001 : else
1002 0 : return ((SvMetaType *)GetRef())->GetCName();
1003 : }
1004 :
1005 1991 : sal_Bool SvMetaType::SetName( const OString& rName, SvIdlDataBase * pBase )
1006 : {
1007 1991 : aSvName.setString(rName);
1008 1991 : aSbxName.setString(rName);
1009 1991 : aCName.setString(rName);
1010 1991 : if( GetType() != TYPE_ENUM )
1011 1772 : aOdlName.setString(rName);
1012 1991 : return SvMetaReference::SetName( rName, pBase );
1013 : }
1014 :
1015 20643 : OString SvMetaType::GetCString() const
1016 : {
1017 20643 : OStringBuffer out( GetSvName() );
1018 20643 : if( aCall0 == (int)CALL_POINTER )
1019 0 : out.append(" *");
1020 20643 : else if( aCall0 == (int)CALL_REFERENCE )
1021 0 : out.append(" &");
1022 20643 : if( aCall1 == (int)CALL_POINTER )
1023 0 : out.append('*');
1024 20643 : else if( aCall1 == (int)CALL_REFERENCE )
1025 0 : out.append('&');
1026 20643 : return out.makeStringAndClear();
1027 : }
1028 :
1029 1887 : sal_Bool SvMetaType::ReadHeaderSvIdl( SvIdlDataBase & rBase,
1030 : SvTokenStream & rInStm )
1031 : {
1032 1887 : sal_Bool bOk = sal_False;
1033 1887 : sal_uInt32 nTokPos = rInStm.Tell();
1034 1887 : SvToken * pTok = rInStm.GetToken_Next();
1035 :
1036 3774 : if( pTok->Is( SvHash_interface() )
1037 1887 : || pTok->Is( SvHash_shell() ) )
1038 : {
1039 195 : if( pTok->Is( SvHash_shell() ) )
1040 86 : bIsShell = sal_True;
1041 195 : SetType( TYPE_CLASS );
1042 195 : bOk = ReadNamesSvIdl( rBase, rInStm );
1043 :
1044 : }
1045 1692 : else if( pTok->Is( SvHash_struct() ) )
1046 : {
1047 307 : SetType( TYPE_STRUCT );
1048 307 : bOk = ReadNamesSvIdl( rBase, rInStm );
1049 : }
1050 1385 : else if( pTok->Is( SvHash_union() ) )
1051 : {
1052 0 : SetType( TYPE_UNION );
1053 0 : if( ReadNameSvIdl( rBase, rInStm ) )
1054 0 : return sal_True;
1055 : }
1056 1385 : else if( pTok->Is( SvHash_enum() ) )
1057 : {
1058 219 : SetType( TYPE_ENUM );
1059 219 : bOk = ReadNameSvIdl( rBase, rInStm );
1060 : }
1061 2332 : else if( pTok->Is( SvHash_typedef() )
1062 1166 : || pTok->Is( SvHash_item() ) )
1063 : {
1064 1166 : if( pTok->Is( SvHash_item() ) )
1065 1166 : bIsItem = sal_True;
1066 :
1067 1166 : SvMetaType * pType = rBase.ReadKnownType( rInStm );
1068 1166 : if( pType )
1069 : {
1070 1166 : SetRef( pType );
1071 1166 : if( ReadNameSvIdl( rBase, rInStm ) )
1072 : {
1073 1166 : if( rInStm.Read( '(' ) )
1074 : {
1075 0 : DoReadContextSvIdl( rBase, rInStm );
1076 0 : if( rInStm.Read( ')' ) )
1077 : {
1078 0 : SetType( TYPE_METHOD );
1079 0 : bOk = sal_True;
1080 : }
1081 : }
1082 : else
1083 : {
1084 1166 : bOk = sal_True;
1085 : }
1086 : }
1087 : }
1088 : else
1089 : {
1090 0 : OString aStr("wrong typedef: ");
1091 0 : rBase.SetError( aStr, rInStm.GetToken() );
1092 0 : rBase.WriteError( rInStm );
1093 : }
1094 : }
1095 1887 : if( bOk )
1096 1887 : SetModule( rBase );
1097 : else
1098 0 : rInStm.Seek( nTokPos );
1099 1887 : return bOk;
1100 : }
1101 :
1102 1473 : sal_Bool SvMetaType::ReadSvIdl( SvIdlDataBase & rBase,
1103 : SvTokenStream & rInStm )
1104 : {
1105 1473 : if( ReadHeaderSvIdl( rBase, rInStm ) )
1106 : {
1107 1473 : rBase.Write(OString('.'));
1108 1473 : return SvMetaExtern::ReadSvIdl( rBase, rInStm );
1109 : }
1110 0 : return sal_False;
1111 : }
1112 :
1113 1473 : void SvMetaType::WriteSvIdl
1114 : (
1115 : SvIdlDataBase & rBase,
1116 : SvStream & rOutStm,
1117 : sal_uInt16 nTab
1118 : )
1119 : {
1120 1473 : WriteHeaderSvIdl( rBase, rOutStm, nTab );
1121 1473 : if( GetType() == TYPE_METHOD )
1122 0 : WriteMethodArgs( rBase, rOutStm, nTab, WRITE_IDL );
1123 :
1124 1473 : sal_uLong nOldPos = rOutStm.Tell();
1125 1473 : rOutStm << endl;
1126 1473 : SvMetaExtern::WriteSvIdl( rBase, rOutStm, nTab );
1127 1473 : if( TestAndSeekSpaceOnly( rOutStm, nOldPos ) )
1128 : // nothin written
1129 1166 : rOutStm.Seek( nOldPos );
1130 1473 : rOutStm << ';' << endl;
1131 1473 : }
1132 :
1133 0 : void SvMetaType::WriteContext( SvIdlDataBase & rBase, SvStream & rOutStm,
1134 : sal_uInt16 nTab,
1135 : WriteType nT, WriteAttribute nA )
1136 : {
1137 0 : if( GetAttrCount() )
1138 : {
1139 0 : SvMetaAttributeMemberList::const_iterator it = pAttrList->begin();
1140 0 : while( it != pAttrList->end() )
1141 : {
1142 0 : SvMetaAttribute * pAttr = *it;
1143 0 : pAttr->Write( rBase, rOutStm, nTab, nT, nA );
1144 0 : if( GetType() == TYPE_METHOD )
1145 0 : rOutStm << ',' << endl;
1146 : else
1147 0 : rOutStm << ';' << endl;
1148 0 : ++it;
1149 : }
1150 : }
1151 0 : }
1152 :
1153 0 : void SvMetaType::Write( SvIdlDataBase & rBase, SvStream & rOutStm,
1154 : sal_uInt16 nTab,
1155 : WriteType nT, WriteAttribute nA )
1156 : {
1157 0 : if( nT == WRITE_C_HEADER && nType != TYPE_ENUM )
1158 : // write only enum
1159 0 : return;
1160 :
1161 0 : OString name = GetName().getString();
1162 0 : if( nT == WRITE_ODL || nT == WRITE_C_HEADER || nT == WRITE_CXX_HEADER )
1163 : {
1164 0 : switch( nType )
1165 : {
1166 : case TYPE_CLASS:
1167 : {
1168 : }
1169 0 : break;
1170 : case TYPE_STRUCT:
1171 : case TYPE_UNION:
1172 : case TYPE_ENUM:
1173 : {
1174 0 : WriteStars( rOutStm );
1175 0 : if( nType == TYPE_STRUCT || nType == TYPE_UNION )
1176 0 : nA = WA_STRUCT;
1177 :
1178 0 : if( nT == WRITE_ODL || nT == WRITE_C_HEADER)
1179 : {
1180 0 : if ( nT == WRITE_C_HEADER )
1181 : {
1182 0 : OString aStr = name.toAsciiUpperCase();
1183 0 : rOutStm << "#ifndef " << C_PREF << aStr.getStr() << "_DEF " << endl;
1184 0 : rOutStm << "#define " << C_PREF << aStr.getStr() << "_DEF " << endl;
1185 : }
1186 :
1187 0 : WriteTab( rOutStm, nTab );
1188 0 : rOutStm << "typedef" << endl;
1189 0 : if ( nT == WRITE_ODL )
1190 0 : SvMetaName::Write( rBase, rOutStm, nTab, nT, nA );
1191 : }
1192 0 : WriteTab( rOutStm, nTab );
1193 0 : if( nType == TYPE_STRUCT )
1194 0 : rOutStm << "struct";
1195 0 : else if( nType == TYPE_UNION )
1196 0 : rOutStm << "union";
1197 : else
1198 0 : rOutStm << "enum";
1199 0 : if( nT != WRITE_ODL && nT != WRITE_C_HEADER)
1200 0 : rOutStm << ' ' << name.getStr();
1201 :
1202 0 : rOutStm << endl;
1203 0 : WriteTab( rOutStm, nTab );
1204 0 : rOutStm << '{' << endl;
1205 0 : WriteContext( rBase, rOutStm, nTab +1, nT, nA );
1206 0 : WriteTab( rOutStm, nTab );
1207 0 : rOutStm << '}';
1208 0 : if( nT == WRITE_ODL || nT == WRITE_C_HEADER )
1209 : {
1210 0 : rOutStm << ' ' << C_PREF << name.getStr();
1211 : }
1212 0 : rOutStm << ';' << endl;
1213 :
1214 0 : if ( nT == WRITE_C_HEADER )
1215 0 : rOutStm << "#endif";
1216 0 : rOutStm << endl;
1217 : }
1218 0 : break;
1219 : case TYPE_POINTER:
1220 : case TYPE_BASE:
1221 : {
1222 : }
1223 0 : break;
1224 : case TYPE_METHOD:
1225 : {
1226 : }
1227 0 : break;
1228 : }
1229 0 : }
1230 : }
1231 :
1232 502 : sal_Bool SvMetaType::ReadNamesSvIdl( SvIdlDataBase & rBase,
1233 : SvTokenStream & rInStm )
1234 : {
1235 502 : sal_Bool bOk = ReadNameSvIdl( rBase, rInStm );
1236 :
1237 502 : return bOk;
1238 : }
1239 :
1240 1887 : void SvMetaType::WriteHeaderSvIdl( SvIdlDataBase & rBase,
1241 : SvStream & rOutStm,
1242 : sal_uInt16 nTab )
1243 : {
1244 1887 : switch( nType )
1245 : {
1246 : case TYPE_CLASS:
1247 : {
1248 195 : if( IsShell() )
1249 86 : rOutStm << SvHash_shell()->GetName().getStr();
1250 : else
1251 109 : rOutStm << SvHash_interface()->GetName().getStr();
1252 195 : rOutStm << ' ' << GetName().getString().getStr();
1253 : }
1254 195 : break;
1255 : case TYPE_STRUCT:
1256 : {
1257 307 : rOutStm << SvHash_struct()->GetName().getStr()
1258 614 : << ' ' << GetName().getString().getStr();
1259 : }
1260 307 : break;
1261 : case TYPE_UNION:
1262 : {
1263 0 : rOutStm << SvHash_union()->GetName().getStr()
1264 0 : << ' ' << GetName().getString().getStr();
1265 : }
1266 0 : break;
1267 : case TYPE_ENUM:
1268 : {
1269 219 : rOutStm << SvHash_enum()->GetName().getStr()
1270 438 : << ' ' << GetName().getString().getStr();
1271 : }
1272 219 : break;
1273 : case TYPE_POINTER:
1274 : case TYPE_BASE:
1275 : {
1276 1166 : if( IsItem() )
1277 1166 : rOutStm << SvHash_item()->GetName().getStr() << ' ';
1278 : else
1279 0 : rOutStm << SvHash_typedef()->GetName().getStr() << ' ';
1280 1166 : if( GetRef() )
1281 : {
1282 1166 : ((SvMetaType *)GetRef())->WriteTheType( rBase, rOutStm, nTab, WRITE_IDL );
1283 1166 : rOutStm << ' ';
1284 : }
1285 1166 : rOutStm << GetName().getString().getStr();
1286 : }
1287 1166 : break;
1288 : case TYPE_METHOD:
1289 : {
1290 0 : rOutStm << SvHash_typedef()->GetName().getStr() << ' ';
1291 0 : ((SvMetaType *)GetRef())->WriteTheType( rBase, rOutStm, nTab, WRITE_IDL );
1292 0 : rOutStm << ' ' << GetName().getString().getStr() << "( ";
1293 0 : WriteContextSvIdl( rBase, rOutStm, nTab );
1294 0 : rOutStm << " )";
1295 : }
1296 0 : break;
1297 : }
1298 1887 : }
1299 :
1300 184 : void SvMetaType::ReadAttributesSvIdl( SvIdlDataBase & rBase,
1301 : SvTokenStream & rInStm )
1302 : {
1303 184 : SvMetaExtern::ReadAttributesSvIdl( rBase, rInStm );
1304 184 : aSvName.ReadSvIdl( SvHash_SvName(), rInStm );
1305 184 : aSbxName.ReadSvIdl( SvHash_SbxName(), rInStm );
1306 184 : aOdlName.ReadSvIdl( SvHash_OdlName(), rInStm );
1307 184 : }
1308 :
1309 1887 : void SvMetaType::WriteAttributesSvIdl( SvIdlDataBase & rBase,
1310 : SvStream & rOutStm,
1311 : sal_uInt16 nTab )
1312 : {
1313 1887 : SvMetaExtern::WriteAttributesSvIdl( rBase, rOutStm, nTab );
1314 1887 : OString name = GetName().getString();
1315 1887 : if( aSvName.getString() != name || aSbxName.getString() != name || aOdlName.getString() != name )
1316 : {
1317 219 : WriteTab( rOutStm, nTab );
1318 219 : rOutStm << "class SvMetaType" << endl;
1319 219 : if( aSvName.getString() != name )
1320 : {
1321 0 : WriteTab( rOutStm, nTab );
1322 0 : aSvName.WriteSvIdl( SvHash_SvName(), rOutStm, nTab );
1323 0 : rOutStm << endl;
1324 : }
1325 219 : if( aSbxName.getString() != name )
1326 : {
1327 0 : WriteTab( rOutStm, nTab );
1328 0 : aSbxName.WriteSvIdl( SvHash_SbxName(), rOutStm, nTab );
1329 0 : rOutStm << endl;
1330 : }
1331 219 : if( aOdlName.getString() != name )
1332 : {
1333 219 : WriteTab( rOutStm, nTab );
1334 219 : aOdlName.WriteSvIdl( SvHash_OdlName(), rOutStm, nTab );
1335 219 : rOutStm << endl;
1336 : }
1337 1887 : }
1338 1887 : }
1339 :
1340 9534 : void SvMetaType::ReadContextSvIdl( SvIdlDataBase & rBase,
1341 : SvTokenStream & rInStm )
1342 : {
1343 9534 : SvMetaAttributeRef xAttr = new SvMetaAttribute();
1344 9534 : if( xAttr->ReadSvIdl( rBase, rInStm ) )
1345 : {
1346 4799 : if( xAttr->Test( rBase, rInStm ) )
1347 4799 : GetAttrList().push_back( xAttr );
1348 9534 : }
1349 9534 : }
1350 :
1351 1473 : void SvMetaType::WriteContextSvIdl
1352 : (
1353 : SvIdlDataBase & rBase,
1354 : SvStream & rOutStm,
1355 : sal_uInt16 nTab
1356 : )
1357 : {
1358 1473 : if( GetAttrCount() )
1359 : {
1360 307 : SvMetaAttributeMemberList::const_iterator it = pAttrList->begin();
1361 1902 : while( it != pAttrList->end() )
1362 : {
1363 1288 : SvMetaAttribute * pAttr = *it;
1364 1288 : WriteTab( rOutStm, nTab );
1365 1288 : pAttr->WriteSvIdl( rBase, rOutStm, nTab );
1366 1288 : if( GetType() == TYPE_METHOD )
1367 0 : rOutStm << ',' << endl;
1368 : else
1369 1288 : rOutStm << ';' << endl;
1370 1288 : ++it;
1371 : }
1372 : }
1373 1473 : }
1374 :
1375 0 : void SvMetaType::WriteAttributes( SvIdlDataBase & rBase, SvStream & rOutStm,
1376 : sal_uInt16 nTab,
1377 : WriteType nT, WriteAttribute nA )
1378 : {
1379 0 : SvMetaExtern::WriteAttributes( rBase, rOutStm, nTab, nT, nA );
1380 0 : }
1381 :
1382 426 : sal_uLong SvMetaType::MakeSfx( OStringBuffer& rAttrArray )
1383 : {
1384 426 : sal_uLong nC = 0;
1385 :
1386 426 : if( GetBaseType()->GetType() == TYPE_STRUCT )
1387 : {
1388 145 : sal_uLong nAttrCount = GetAttrCount();
1389 : // write the single attributes
1390 818 : for( sal_uLong n = 0; n < nAttrCount; n++ )
1391 : {
1392 673 : nC += (*pAttrList)[n]->MakeSfx( rAttrArray );
1393 673 : if( n +1 < nAttrCount )
1394 528 : rAttrArray.append(", ");
1395 : }
1396 : }
1397 426 : return nC;
1398 : }
1399 :
1400 426 : void SvMetaType::WriteSfxItem(
1401 : const OString& rItemName, SvIdlDataBase &, SvStream & rOutStm )
1402 : {
1403 426 : WriteStars( rOutStm );
1404 426 : OStringBuffer aVarName(RTL_CONSTASCII_STRINGPARAM(" a"));
1405 426 : aVarName.append(rItemName).append(RTL_CONSTASCII_STRINGPARAM("_Impl"));
1406 :
1407 852 : OStringBuffer aTypeName(RTL_CONSTASCII_STRINGPARAM("SfxType"));
1408 852 : OStringBuffer aAttrArray;
1409 426 : sal_uLong nAttrCount = MakeSfx( aAttrArray );
1410 : OString aAttrCount(
1411 852 : OString::number(nAttrCount));
1412 426 : aTypeName.append(aAttrCount);
1413 :
1414 426 : rOutStm << "extern " << aTypeName.getStr()
1415 852 : << aVarName.getStr() << ';' << endl;
1416 :
1417 : // write the implementation part
1418 426 : rOutStm << "#ifdef SFX_TYPEMAP" << endl
1419 426 : << "#if defined(DISABLE_DYNLOADING) && (defined(ANDROID) || defined(IOS)) || defined(LIBO_MERGELIBS)" << endl
1420 426 : << "__attribute__((__weak__))" << endl
1421 426 : << "#endif" << endl
1422 852 : << aTypeName.getStr() << aVarName.getStr()
1423 426 : << " = " << endl;
1424 426 : rOutStm << '{' << endl
1425 852 : << "\tTYPE(" << rItemName.getStr() << "), "
1426 852 : << aAttrCount.getStr();
1427 426 : if( nAttrCount )
1428 : {
1429 145 : rOutStm << ", { ";
1430 : // write the single attributes
1431 145 : rOutStm << aAttrArray.getStr();
1432 145 : rOutStm << " }";
1433 : }
1434 426 : rOutStm << endl << "};" << endl
1435 852 : << "#endif" << endl << endl;
1436 426 : }
1437 :
1438 2286 : void SvMetaType::WriteSfx( SvIdlDataBase & rBase, SvStream & rOutStm )
1439 : {
1440 2286 : if( IsItem() )
1441 : {
1442 426 : if( GetBaseType()->GetType() == TYPE_STRUCT )
1443 145 : GetBaseType()->WriteSfxItem( GetName().getString(), rBase, rOutStm );
1444 : else
1445 281 : WriteSfxItem( GetName().getString(), rBase, rOutStm );
1446 : }
1447 2286 : }
1448 :
1449 4428 : sal_Bool SvMetaType::ReadMethodArgs( SvIdlDataBase & rBase,
1450 : SvTokenStream & rInStm )
1451 : {
1452 4428 : sal_uInt32 nTokPos = rInStm.Tell();
1453 4428 : if( rInStm.Read( '(' ) )
1454 : {
1455 4428 : DoReadContextSvIdl( rBase, rInStm );
1456 4428 : if( rInStm.Read( ')' ) )
1457 : {
1458 4428 : SetType( TYPE_METHOD );
1459 4428 : return sal_True;
1460 : }
1461 : }
1462 0 : rInStm.Seek( nTokPos );
1463 0 : return sal_False;
1464 : }
1465 :
1466 6735 : void SvMetaType::WriteMethodArgs
1467 : (
1468 : SvIdlDataBase & rBase,
1469 : SvStream & rOutStm,
1470 : sal_uInt16 nTab, WriteType nT
1471 : )
1472 : {
1473 6735 : if( nT == WRITE_IDL )
1474 : {
1475 6735 : if( GetAttrCount() )
1476 : {
1477 2131 : rOutStm << endl;
1478 2131 : WriteTab( rOutStm, nTab );
1479 2131 : rOutStm << '(' << endl;
1480 :
1481 2131 : SvMetaAttributeMemberList::const_iterator it = pAttrList->begin();
1482 9321 : while( it != pAttrList->end() )
1483 : {
1484 5059 : SvMetaAttribute * pAttr = *it;
1485 5059 : WriteTab( rOutStm, nTab +1 );
1486 5059 : pAttr->WriteSvIdl( rBase, rOutStm, nTab +1 );
1487 5059 : ++it;
1488 5059 : if( it != pAttrList->end() )
1489 2928 : rOutStm << ',' << endl;
1490 : }
1491 2131 : rOutStm << endl;
1492 2131 : WriteTab( rOutStm, nTab );
1493 2131 : rOutStm << ')';
1494 : }
1495 : else
1496 4604 : rOutStm << "()";
1497 : }
1498 0 : else if ( nT == WRITE_DOCU )
1499 : {
1500 :
1501 0 : rOutStm << '(';
1502 0 : if( GetAttrCount() )
1503 : {
1504 0 : SvMetaAttributeMemberList::const_iterator it = pAttrList->begin();
1505 0 : while( it != pAttrList->end() )
1506 : {
1507 0 : SvMetaAttribute * pAttr = *it;
1508 0 : pAttr->WriteParam( rBase, rOutStm, nTab+1, nT );
1509 0 : ++it;
1510 0 : if( it != pAttrList->end() )
1511 0 : rOutStm << ',';
1512 : else
1513 0 : rOutStm << ' ';
1514 : }
1515 : }
1516 0 : rOutStm << ')' << endl;
1517 : }
1518 : else
1519 : {
1520 0 : rOutStm << '(';
1521 0 : if( nT == WRITE_C_HEADER || nT == WRITE_C_SOURCE )
1522 : {
1523 0 : rOutStm << ' ' << C_PREF << "Object h" << rBase.aIFaceName.getStr();
1524 0 : if( GetAttrCount() )
1525 0 : rOutStm << ',';
1526 : else
1527 0 : rOutStm << ' ';
1528 : }
1529 :
1530 0 : if( GetAttrCount() )
1531 : {
1532 0 : rOutStm << endl;
1533 0 : SvMetaAttributeMemberList::const_iterator it = pAttrList->begin();
1534 0 : while( it != pAttrList->end() )
1535 : {
1536 0 : SvMetaAttribute* pAttr = *it;
1537 0 : switch( nT )
1538 : {
1539 : case WRITE_C_HEADER:
1540 : case WRITE_C_SOURCE:
1541 : case WRITE_ODL:
1542 : {
1543 0 : pAttr->WriteParam( rBase, rOutStm, nTab +1, nT );
1544 : }
1545 0 : break;
1546 :
1547 : default:
1548 : {
1549 : DBG_ASSERT( sal_False, "WriteType not implemented" );
1550 : }
1551 : }
1552 0 : ++it;
1553 0 : if( it != pAttrList->end() )
1554 0 : rOutStm << ',' << endl;
1555 : }
1556 0 : if( nT != WRITE_C_HEADER && nT != WRITE_C_SOURCE )
1557 : {
1558 0 : rOutStm << endl;
1559 0 : WriteTab( rOutStm, nTab +1 );
1560 : }
1561 0 : rOutStm << ' ';
1562 : }
1563 0 : rOutStm << ')';
1564 : }
1565 6735 : }
1566 :
1567 20643 : void SvMetaType::WriteTypePrefix( SvIdlDataBase & rBase, SvStream & rOutStm,
1568 : sal_uInt16 nTab, WriteType nT )
1569 : {
1570 20643 : switch( nT )
1571 : {
1572 : case WRITE_IDL:
1573 : {
1574 20643 : if( GetIn() && GetOut() )
1575 0 : rOutStm << SvHash_inout()->GetName().getStr() << ' ';
1576 20643 : else if( GetIn() )
1577 0 : rOutStm << SvHash_in()->GetName().getStr() << ' ';
1578 20643 : else if( GetOut() )
1579 0 : rOutStm << SvHash_out()->GetName().getStr() << ' ';
1580 20643 : rOutStm << GetCString().getStr();
1581 : }
1582 20643 : break;
1583 :
1584 : case WRITE_ODL:
1585 : {
1586 0 : sal_Bool bIn = GetIn();
1587 0 : sal_Bool bOut = GetOut();
1588 0 : if( bIn || bOut )
1589 : {
1590 0 : if( bIn && bOut )
1591 0 : rOutStm << "[in,out] ";
1592 0 : else if( bIn )
1593 0 : rOutStm << "[in] ";
1594 0 : else if( bOut )
1595 0 : rOutStm << "[out] ";
1596 : }
1597 :
1598 0 : OString out;
1599 0 : if( GetType() == TYPE_METHOD )
1600 0 : out = GetReturnType()->GetBaseType()->GetOdlName();
1601 : else
1602 : {
1603 0 : SvMetaType * pBType = GetBaseType();
1604 0 : out = pBType->GetOdlName();
1605 : }
1606 0 : if( aCall0 == (int)CALL_POINTER
1607 0 : || aCall0 == (int)CALL_REFERENCE )
1608 0 : rOutStm << " *";
1609 0 : if( aCall1 == (int)CALL_POINTER
1610 0 : || aCall1 == (int)CALL_REFERENCE )
1611 0 : rOutStm << " *";
1612 0 : rOutStm << out.getStr();
1613 : }
1614 0 : break;
1615 :
1616 : case WRITE_C_HEADER:
1617 : case WRITE_C_SOURCE:
1618 : case WRITE_CXX_HEADER:
1619 : case WRITE_CXX_SOURCE:
1620 : {
1621 :
1622 0 : SvMetaType * pBaseType = GetBaseType();
1623 : DBG_ASSERT( pBaseType, "no base type for attribute" );
1624 :
1625 0 : if( pBaseType->GetType() == TYPE_METHOD )
1626 : pBaseType->GetReturnType()->WriteTypePrefix(
1627 0 : rBase, rOutStm, nTab, nT );
1628 0 : else if( nT == WRITE_C_HEADER || nT == WRITE_C_SOURCE )
1629 : {
1630 0 : if( TYPE_STRUCT == pBaseType->GetType() )
1631 0 : rOutStm << C_PREF << pBaseType->GetName().getString().getStr()
1632 0 : << " *";
1633 : else
1634 : {
1635 0 : if ( pBaseType->GetType() == TYPE_ENUM )
1636 0 : rOutStm << C_PREF;
1637 0 : rOutStm << pBaseType->GetCName().getStr();
1638 : }
1639 : }
1640 : else
1641 : {
1642 0 : if( TYPE_STRUCT == pBaseType->GetType() )
1643 0 : rOutStm << pBaseType->GetName().getString().getStr() << " *";
1644 : else
1645 0 : rOutStm << pBaseType->GetName().getString().getStr();
1646 : }
1647 : }
1648 0 : break;
1649 :
1650 : case WRITE_DOCU:
1651 : {
1652 :
1653 0 : SvMetaType * pBaseType = GetBaseType();
1654 : DBG_ASSERT( pBaseType, "no base type for attribute" );
1655 :
1656 0 : if( pBaseType->GetType() == TYPE_METHOD )
1657 : {
1658 : pBaseType->GetReturnType()->WriteTypePrefix(
1659 0 : rBase, rOutStm, nTab, nT );
1660 : }
1661 : else
1662 : {
1663 0 : if( TYPE_STRUCT == pBaseType->GetType() )
1664 0 : rOutStm << "VARIANT" << pBaseType->GetName().getString().getStr();
1665 0 : else if ( pBaseType->GetType() == TYPE_ENUM )
1666 0 : rOutStm << "integer";
1667 : else
1668 0 : rOutStm << pBaseType->GetOdlName().getStr();
1669 : }
1670 : }
1671 :
1672 : default:
1673 : {
1674 : DBG_ASSERT( sal_False, "WriteType not implemented" );
1675 : }
1676 : }
1677 20643 : }
1678 :
1679 1986 : void SvMetaType::WriteTheType( SvIdlDataBase & rBase, SvStream & rOutStm,
1680 : sal_uInt16 nTab, WriteType nT )
1681 : {
1682 1986 : WriteTypePrefix( rBase, rOutStm, nTab, nT );
1683 1986 : if( GetType() == TYPE_METHOD )
1684 0 : WriteMethodArgs( rBase, rOutStm, nTab +2, nT );
1685 1986 : }
1686 :
1687 0 : OString SvMetaType::GetParserString() const
1688 : {
1689 0 : SvMetaType * pBT = GetBaseType();
1690 0 : if( pBT != this )
1691 0 : return pBT->GetParserString();
1692 :
1693 0 : int type = GetType();
1694 0 : OString aPStr;
1695 :
1696 0 : if( TYPE_METHOD == type || TYPE_STRUCT == type )
1697 : {
1698 0 : sal_uLong nAttrCount = GetAttrCount();
1699 : // write the single attributes
1700 0 : for( sal_uLong n = 0; n < nAttrCount; n++ )
1701 : {
1702 0 : SvMetaAttribute * pT = (*pAttrList)[n];
1703 0 : aPStr += pT->GetType()->GetParserString();
1704 0 : }
1705 : }
1706 : else
1707 0 : aPStr = OString(GetParserChar());
1708 0 : return aPStr;
1709 : }
1710 :
1711 0 : void SvMetaType::WriteParamNames( SvIdlDataBase & rBase,
1712 : SvStream & rOutStm,
1713 : const OString& rChief )
1714 : {
1715 0 : SvMetaType * pBT = GetBaseType();
1716 0 : if( pBT != this )
1717 0 : pBT->WriteParamNames( rBase, rOutStm, rChief );
1718 : else
1719 : {
1720 0 : int type = GetType();
1721 :
1722 0 : if( TYPE_METHOD == type || TYPE_STRUCT == type )
1723 : {
1724 0 : sal_uLong nAttrCount = GetAttrCount();
1725 : // write the single attributes
1726 0 : for( sal_uLong n = 0; n < nAttrCount; n++ )
1727 : {
1728 0 : SvMetaAttribute * pA = (*pAttrList)[n];
1729 0 : OString aStr = pA->GetName().getString();
1730 0 : pA->GetType()->WriteParamNames( rBase, rOutStm, aStr );
1731 0 : if( n +1 < nAttrCount )
1732 0 : rOutStm << ", ";
1733 0 : }
1734 : }
1735 : else
1736 0 : rOutStm << rChief.getStr();
1737 : }
1738 0 : }
1739 :
1740 1156 : SV_IMPL_META_FACTORY1( SvMetaTypeString, SvMetaType );
1741 8 : SvMetaTypeString::SvMetaTypeString()
1742 8 : : SvMetaType( "String", "SbxSTRING", "BSTR", 's', "char *", "String", "$" )
1743 : {
1744 8 : }
1745 :
1746 0 : void SvMetaTypeString::Load( SvPersistStream & rStm )
1747 : {
1748 0 : SvMetaType::Load( rStm );
1749 0 : }
1750 :
1751 8 : void SvMetaTypeString::Save( SvPersistStream & rStm )
1752 : {
1753 8 : SvMetaType::Save( rStm );
1754 8 : }
1755 :
1756 1480 : SV_IMPL_META_FACTORY1( SvMetaEnumValue, SvMetaName );
1757 1699 : SvMetaEnumValue::SvMetaEnumValue()
1758 : {
1759 1699 : }
1760 :
1761 0 : void SvMetaEnumValue::Load( SvPersistStream & rStm )
1762 : {
1763 0 : SvMetaName::Load( rStm );
1764 :
1765 : sal_uInt8 nMask;
1766 0 : rStm >> nMask;
1767 0 : if( nMask >= 0x02 )
1768 : {
1769 0 : rStm.SetError( SVSTREAM_FILEFORMAT_ERROR );
1770 : OSL_FAIL( "wrong format" );
1771 0 : return;
1772 : }
1773 0 : if( nMask & 0x01 ) aEnumValue = read_lenPrefixed_uInt8s_ToOString<sal_uInt16>(rStm);
1774 : }
1775 :
1776 1480 : void SvMetaEnumValue::Save( SvPersistStream & rStm )
1777 : {
1778 1480 : SvMetaName::Save( rStm );
1779 :
1780 : // create mask
1781 1480 : sal_uInt8 nMask = 0;
1782 1480 : if( !aEnumValue.isEmpty() ) nMask |= 0x01;
1783 :
1784 : // write data
1785 1480 : rStm << nMask;
1786 1480 : if( nMask & 0x01 ) write_lenPrefixed_uInt8s_FromOString<sal_uInt16>(rStm, aEnumValue);
1787 1480 : }
1788 :
1789 1699 : sal_Bool SvMetaEnumValue::ReadSvIdl( SvIdlDataBase & rBase,
1790 : SvTokenStream & rInStm )
1791 : {
1792 1699 : if( !ReadNameSvIdl( rBase, rInStm ) )
1793 219 : return sal_False;
1794 1480 : return sal_True;
1795 : }
1796 :
1797 1480 : void SvMetaEnumValue::WriteSvIdl( SvIdlDataBase &, SvStream & rOutStm, sal_uInt16 )
1798 : {
1799 1480 : rOutStm << GetName().getString().getStr();
1800 1480 : }
1801 :
1802 0 : void SvMetaEnumValue::Write( SvIdlDataBase &, SvStream & rOutStm, sal_uInt16,
1803 : WriteType nT, WriteAttribute )
1804 : {
1805 0 : if ( nT == WRITE_C_HEADER || nT == WRITE_C_SOURCE )
1806 0 : rOutStm << C_PREF << GetName().getString().getStr();
1807 : else
1808 0 : rOutStm << GetName().getString().getStr();
1809 0 : }
1810 :
1811 19061 : SV_IMPL_META_FACTORY1( SvMetaTypeEnum, SvMetaType );
1812 219 : SvMetaTypeEnum::SvMetaTypeEnum()
1813 : {
1814 219 : SetBasicName("Integer");
1815 219 : }
1816 :
1817 0 : void SvMetaTypeEnum::Load( SvPersistStream & rStm )
1818 : {
1819 0 : SvMetaType::Load( rStm );
1820 :
1821 : sal_uInt8 nMask;
1822 0 : rStm >> nMask;
1823 0 : if( nMask >= 0x04 )
1824 : {
1825 0 : rStm.SetError( SVSTREAM_FILEFORMAT_ERROR );
1826 : OSL_FAIL( "wrong format" );
1827 0 : return;
1828 : }
1829 0 : if( nMask & 0x01 ) rStm >> aEnumValueList;
1830 0 : if( nMask & 0x02 ) aPrefix = read_lenPrefixed_uInt8s_ToOString<sal_uInt16>(rStm);
1831 : }
1832 :
1833 219 : void SvMetaTypeEnum::Save( SvPersistStream & rStm )
1834 : {
1835 219 : SvMetaType::Save( rStm );
1836 :
1837 : // create mask
1838 219 : sal_uInt8 nMask = 0;
1839 219 : if( !aEnumValueList.empty() ) nMask |= 0x01;
1840 219 : if( !aPrefix.isEmpty() ) nMask |= 0x02;
1841 :
1842 : // write data
1843 219 : rStm << nMask;
1844 219 : if( nMask & 0x01 ) rStm << aEnumValueList;
1845 219 : if( nMask & 0x02 ) write_lenPrefixed_uInt8s_FromOString<sal_uInt16>(rStm, aPrefix);
1846 219 : }
1847 :
1848 : namespace
1849 : {
1850 1261 : OString getCommonSubPrefix(const OString &rA, const OString &rB)
1851 : {
1852 1261 : sal_Int32 nMax = std::min(rA.getLength(), rB.getLength());
1853 1261 : sal_Int32 nI = 0;
1854 16333 : while (nI < nMax)
1855 : {
1856 14044 : if (rA[nI] != rB[nI])
1857 233 : break;
1858 13811 : ++nI;
1859 : }
1860 1261 : return rA.copy(0, nI);
1861 : }
1862 : }
1863 :
1864 1699 : void SvMetaTypeEnum::ReadContextSvIdl( SvIdlDataBase & rBase,
1865 : SvTokenStream & rInStm )
1866 : {
1867 1699 : sal_uInt32 nTokPos = rInStm.Tell();
1868 :
1869 1699 : SvMetaEnumValueRef aEnumVal = new SvMetaEnumValue();
1870 1699 : sal_Bool bOk = aEnumVal->ReadSvIdl( rBase, rInStm );
1871 1699 : if( bOk )
1872 : {
1873 1480 : if( aEnumValueList.empty() )
1874 : {
1875 : // the first
1876 219 : aPrefix = aEnumVal->GetName().getString();
1877 : }
1878 : else
1879 : {
1880 1261 : aPrefix = getCommonSubPrefix(aPrefix, aEnumVal->GetName().getString());
1881 : }
1882 1480 : aEnumValueList.push_back( aEnumVal );
1883 : }
1884 1699 : if( !bOk )
1885 219 : rInStm.Seek( nTokPos );
1886 1699 : }
1887 :
1888 219 : void SvMetaTypeEnum::WriteContextSvIdl( SvIdlDataBase & rBase,
1889 : SvStream & rOutStm,
1890 : sal_uInt16 nTab )
1891 : {
1892 219 : WriteTab( rOutStm, nTab +1 );
1893 1699 : for( sal_uLong n = 0; n < aEnumValueList.size(); n++ )
1894 : {
1895 1480 : aEnumValueList[n]->WriteSvIdl( rBase, rOutStm, nTab );
1896 1480 : if( n + 1 != aEnumValueList.size() )
1897 1261 : rOutStm << ", ";
1898 : else
1899 219 : rOutStm << endl;
1900 : }
1901 219 : }
1902 :
1903 219 : sal_Bool SvMetaTypeEnum::ReadSvIdl( SvIdlDataBase & rBase,
1904 : SvTokenStream & rInStm )
1905 : {
1906 219 : sal_uInt32 nTokPos = rInStm.Tell();
1907 438 : if( SvMetaType::ReadHeaderSvIdl( rBase, rInStm )
1908 219 : && GetType() == TYPE_ENUM )
1909 : {
1910 219 : if( SvMetaName::ReadSvIdl( rBase, rInStm ) )
1911 219 : return sal_True;
1912 : }
1913 0 : rInStm.Seek( nTokPos );
1914 0 : return sal_False;
1915 : }
1916 :
1917 219 : void SvMetaTypeEnum::WriteSvIdl( SvIdlDataBase & rBase, SvStream & rOutStm,
1918 : sal_uInt16 nTab )
1919 : {
1920 219 : WriteHeaderSvIdl( rBase, rOutStm, nTab );
1921 219 : rOutStm << endl;
1922 219 : SvMetaName::WriteSvIdl( rBase, rOutStm, nTab );
1923 219 : rOutStm << endl;
1924 219 : }
1925 :
1926 0 : void SvMetaTypeEnum::Write( SvIdlDataBase & rBase, SvStream & rOutStm,
1927 : sal_uInt16 nTab,
1928 : WriteType nT, WriteAttribute nA )
1929 : {
1930 0 : SvMetaType::Write( rBase, rOutStm, nTab, nT, nA );
1931 0 : }
1932 :
1933 0 : void SvMetaTypeEnum::WriteContext( SvIdlDataBase & rBase, SvStream & rOutStm,
1934 : sal_uInt16 nTab,
1935 : WriteType nT, WriteAttribute nA )
1936 : {
1937 0 : WriteTab( rOutStm, nTab +1 );
1938 0 : for( sal_uLong n = 0; n < aEnumValueList.size(); n++ )
1939 : {
1940 0 : aEnumValueList[n]->Write( rBase, rOutStm, nTab +1, nT, nA );
1941 :
1942 0 : if( n + 1 != aEnumValueList.size() )
1943 : {
1944 0 : if( 2 == n % 3 )
1945 : {
1946 0 : rOutStm << ',' << endl;
1947 0 : WriteTab( rOutStm, nTab +1 );
1948 : }
1949 : else
1950 0 : rOutStm << ",\t";
1951 : }
1952 : else
1953 0 : rOutStm << endl;
1954 : }
1955 0 : rOutStm << endl;
1956 0 : }
1957 :
1958 253 : SV_IMPL_META_FACTORY1( SvMetaTypevoid, SvMetaType );
1959 8 : SvMetaTypevoid::SvMetaTypevoid()
1960 8 : : SvMetaType( "void", "SbxVOID", "void", 'v', "void", "", "" )
1961 : {
1962 8 : }
1963 :
1964 0 : void SvMetaTypevoid::Load( SvPersistStream & rStm )
1965 : {
1966 0 : SvMetaType::Load( rStm );
1967 0 : }
1968 :
1969 8 : void SvMetaTypevoid::Save( SvPersistStream & rStm )
1970 : {
1971 8 : SvMetaType::Save( rStm );
1972 8 : }
1973 :
1974 0 : OString SvMetaAttribute::Compare( SvMetaAttribute* pAttr )
1975 : {
1976 0 : OStringBuffer aStr;
1977 :
1978 0 : if ( aType.Is() )
1979 : {
1980 0 : if ( aType->GetType() == TYPE_METHOD )
1981 : {
1982 : // Test only when the attribute is a method not if it has one!
1983 0 : if ( !pAttr->GetType()->GetType() == TYPE_METHOD )
1984 0 : aStr.append(" IsMethod\n");
1985 0 : else if ( aType->GetReturnType() &&
1986 0 : aType->GetReturnType()->GetType() != pAttr->GetType()->GetReturnType()->GetType() )
1987 : {
1988 0 : aStr.append(" ReturnType\n");
1989 : }
1990 :
1991 0 : if ( aType->GetAttrCount() )
1992 : {
1993 0 : sal_uLong nCount = aType->GetAttrCount();
1994 0 : SvMetaAttributeMemberList& rList = aType->GetAttrList();
1995 0 : SvMetaAttributeMemberList& rOtherList = pAttr->GetType()->GetAttrList();
1996 0 : if ( pAttr->GetType()->GetAttrCount() != nCount )
1997 : {
1998 0 : aStr.append(" AttributeCount\n");
1999 : }
2000 : else
2001 : {
2002 0 : for ( sal_uInt16 n=0; n<nCount; n++ )
2003 : {
2004 0 : SvMetaAttribute *pAttr1 = rList[n];
2005 0 : SvMetaAttribute *pAttr2 = rOtherList[n];
2006 0 : pAttr1->Compare( pAttr2 );
2007 : }
2008 : }
2009 : }
2010 : }
2011 :
2012 0 : if ( GetType()->GetType() != pAttr->GetType()->GetType() )
2013 0 : aStr.append(" Type\n");
2014 :
2015 0 : if ( !GetType()->GetSvName().equals( pAttr->GetType()->GetSvName() ) )
2016 0 : aStr.append(" ItemType\n");
2017 : }
2018 :
2019 0 : if ( GetExport() != pAttr->GetExport() )
2020 0 : aStr.append(" Export\n");
2021 :
2022 0 : if ( GetAutomation() != pAttr->GetAutomation() )
2023 0 : aStr.append(" Automation\n");
2024 :
2025 0 : if ( GetIsCollection() != pAttr->GetIsCollection() )
2026 0 : aStr.append(" IsCollection\n");
2027 :
2028 0 : if ( GetReadOnlyDoc() != pAttr->GetReadOnlyDoc() )
2029 0 : aStr.append(" ReadOnlyDoc\n");
2030 :
2031 0 : if ( GetExport() && GetReadonly() != pAttr->GetReadonly() )
2032 0 : aStr.append(" Readonly\n");
2033 :
2034 0 : return aStr.makeStringAndClear();
2035 : }
2036 :
2037 0 : void SvMetaAttribute::WriteCSV( SvIdlDataBase&, SvStream& rStrm )
2038 : {
2039 0 : rStrm << GetType()->GetSvName().getStr() << ' ';
2040 0 : rStrm << GetName().getString().getStr() << ' ';
2041 0 : rStrm << GetSlotId().getString().getStr();
2042 0 : }
2043 :
2044 :
2045 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|