bump product version to 6.3.0.0.beta1
[LibreOffice.git] / idl / source / objects / object.cxx
blob4becd024028942d7114d27a8e46002c83dda6ce3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #include <algorithm>
24 #include <rtl/strbuf.hxx>
25 #include <osl/diagnose.h>
26 #include <sal/log.hxx>
28 #include <object.hxx>
29 #include <globals.hxx>
30 #include <database.hxx>
33 SvClassElement::SvClassElement()
37 SvMetaClass::SvMetaClass()
41 void SvMetaClass::ReadContextSvIdl( SvIdlDataBase & rBase,
42 SvTokenStream & rInStm )
44 sal_uInt32 nTokPos = rInStm.Tell();
45 SvToken& rTok = rInStm.GetToken_Next();
47 if( rTok.Is( SvHash_import() ) )
49 SvMetaClass * pClass = rBase.ReadKnownClass( rInStm );
50 if( !pClass )
51 throw SvParseException( rInStm, "unknown imported interface" );
52 SvClassElement aEle;
53 aEle.SetClass( pClass );
54 aClassElementList.push_back( aEle );
56 rTok = rInStm.GetToken();
57 if( rTok.IsString() )
59 aEle.SetPrefix( rTok.GetString() );
60 rInStm.GetToken_Next();
62 return;
64 else
66 rInStm.Seek( nTokPos );
67 SvMetaType * pType = rBase.ReadKnownType( rInStm );
69 bool bOk = false;
70 tools::SvRef<SvMetaAttribute> xAttr;
71 if( !pType || pType->IsItem() )
73 xAttr = new SvMetaSlot( pType );
74 if( xAttr->ReadSvIdl( rBase, rInStm ) )
75 bOk = xAttr->Test( rInStm );
77 else
79 xAttr = new SvMetaAttribute( pType );
80 if( xAttr->ReadSvIdl( rBase, rInStm ) )
81 bOk = xAttr->Test( rInStm );
84 if( bOk )
85 bOk = TestAttribute( rBase, rInStm, *xAttr );
86 if( bOk )
88 if( !xAttr->GetSlotId().IsSet() )
90 SvIdentifier aI;
91 aI.SetValue( rBase.GetUniqueId() );
92 xAttr->SetSlotId( aI );
94 aAttrList.push_back( xAttr.get() );
95 return;
98 rInStm.Seek( nTokPos );
101 bool SvMetaClass::TestAttribute( SvIdlDataBase & rBase, SvTokenStream & rInStm,
102 SvMetaAttribute & rAttr ) const
104 if ( !rAttr.GetRef() && dynamic_cast<const SvMetaSlot *>(&rAttr) )
106 SAL_WARN( "idl", "new slot : " << rAttr.GetSlotId().getString() );
109 for( sal_uLong n = 0; n < aAttrList.size(); n++ )
111 SvMetaAttribute * pS = aAttrList[n];
112 if( pS->GetName() == rAttr.GetName() )
114 // values have to match
115 if( pS->GetSlotId().GetValue() != rAttr.GetSlotId().GetValue() )
117 throw SvParseException( rInStm, "Attribute's " + pS->GetName() + " with different id's");
120 else
122 sal_uInt32 nId1 = pS->GetSlotId().GetValue();
123 sal_uInt32 nId2 = rAttr.GetSlotId().GetValue();
124 if( nId1 == nId2 && nId1 != 0 )
126 OString aStr = "Attribute " + pS->GetName() + " and Attribute " + rAttr.GetName() + " with equal id's";
127 throw SvParseException(rInStm, aStr);
131 SvMetaClass * pSC = aSuperClass.get();
132 if( pSC )
133 return pSC->TestAttribute( rBase, rInStm, rAttr );
134 return true;
137 sal_uInt16 SvMetaClass::WriteSlotParamArray( SvIdlDataBase & rBase,
138 SvSlotElementList & rSlotList,
139 SvStream & rOutStm )
141 sal_uInt16 nCount = 0;
142 for ( size_t i = 0, n = rSlotList.size(); i < n; ++i )
144 SvMetaSlot *pAttr = rSlotList[ i ];
145 nCount = nCount + pAttr->WriteSlotParamArray( rBase, rOutStm );
148 return nCount;
151 sal_uInt16 SvMetaClass::WriteSlots( const OString& rShellName,
152 SvSlotElementList & rSlotList,
153 SvIdlDataBase & rBase,
154 SvStream & rOutStm )
156 sal_uInt16 nSCount = 0;
157 for ( size_t i = 0, n = rSlotList.size(); i < n; ++i )
159 SvMetaSlot * pAttr = rSlotList[ i ];
160 nSCount = nSCount + pAttr->WriteSlotMap( rShellName, nSCount,
161 rSlotList, i, rBase,
162 rOutStm );
165 return nSCount;
168 void SvMetaClass::InsertSlots( SvSlotElementList& rList, std::vector<sal_uLong>& rSuperList,
169 SvMetaClassList &rClassList,
170 const OString& rPrefix, SvIdlDataBase& rBase)
172 // was this class already written?
173 for ( size_t i = 0, n = rClassList.size(); i < n ; ++i )
174 if ( rClassList[ i ] == this )
175 return;
177 rClassList.push_back( this );
179 // write all direct attributes
180 sal_uLong n;
181 for( n = 0; n < aAttrList.size(); n++ )
183 SvMetaAttribute * pAttr = aAttrList[n];
185 sal_uLong nId = pAttr->GetSlotId().GetValue();
187 std::vector<sal_uLong>::iterator iter = std::find(rSuperList.begin(),
188 rSuperList.end(),nId);
190 if( iter == rSuperList.end() )
192 // Write only if not already written by subclass or
193 // imported interface.
194 rSuperList.push_back(nId);
195 pAttr->Insert(rList);
199 // All Interfaces already imported by SuperShell should not be
200 // written any more.
201 // It is prohibited that Shell and SuperShell directly import the same
202 // class.
203 if( GetMetaTypeType() == MetaTypeType::Shell && aSuperClass.is() )
204 aSuperClass->FillClasses( rClassList );
206 // Write all attributes of the imported classes, as long as they have
207 // not already been imported by the superclass.
208 for( n = 0; n < aClassElementList.size(); n++ )
210 SvClassElement& rElement = aClassElementList[n];
211 SvMetaClass * pCl = rElement.GetClass();
212 OStringBuffer rPre(rPrefix);
213 if( !rPre.isEmpty() && !rElement.GetPrefix().isEmpty() )
214 rPre.append('.');
215 rPre.append(rElement.GetPrefix());
217 // first of all write direct imported interfaces
218 pCl->InsertSlots( rList, rSuperList, rClassList,
219 rPre.makeStringAndClear(), rBase );
222 // only write superclass if no shell and not in the list
223 if( GetMetaTypeType() != MetaTypeType::Shell && aSuperClass.is() )
225 aSuperClass->InsertSlots( rList, rSuperList, rClassList, rPrefix, rBase );
229 void SvMetaClass::FillClasses( SvMetaClassList & rList )
231 // Am I not yet in?
232 for ( size_t i = 0, n = rList.size(); i < n; ++i )
233 if ( rList[ i ] == this )
234 return;
236 rList.push_back( this );
238 // my imports
239 for( size_t n = 0; n < aClassElementList.size(); n++ )
241 SvClassElement& rElement = aClassElementList[n];
242 SvMetaClass * pCl = rElement.GetClass();
243 pCl->FillClasses( rList );
246 // my superclass
247 if( aSuperClass.is() )
248 aSuperClass->FillClasses( rList );
252 void SvMetaClass::WriteSlotStubs( const OString& rShellName,
253 SvSlotElementList & rSlotList,
254 std::vector<OString> & rList,
255 SvStream & rOutStm )
257 // write all attributes
258 for ( size_t i = 0, n = rSlotList.size(); i < n; ++i )
260 SvMetaSlot *pAttr = rSlotList[ i ];
261 pAttr->WriteSlotStubs( rShellName, rList, rOutStm );
265 void SvMetaClass::WriteSfx( SvIdlDataBase & rBase, SvStream & rOutStm )
267 WriteStars( rOutStm );
268 // define class
269 rOutStm.WriteCharPtr( "#ifdef ShellClass_" ).WriteOString( GetName() ) << endl;
270 rOutStm.WriteCharPtr( "#undef ShellClass" ) << endl;
271 rOutStm.WriteCharPtr( "#undef ShellClass_" ).WriteOString( GetName() ) << endl;
272 rOutStm.WriteCharPtr( "#define ShellClass " ).WriteOString( GetName() ) << endl;
274 // no slotmaps get written for interfaces
275 if( GetMetaTypeType() != MetaTypeType::Shell )
277 rOutStm.WriteCharPtr( "#endif" ) << endl << endl;
278 return;
280 // write parameter array
281 rOutStm.WriteCharPtr("static SfxFormalArgument a").WriteOString(GetName()).WriteCharPtr("Args_Impl[] =") << endl;
282 rOutStm.WriteChar('{') << endl;
284 std::vector<sal_uLong> aSuperList;
285 SvMetaClassList classList;
286 SvSlotElementList aSlotList;
287 InsertSlots(aSlotList, aSuperList, classList, OString(), rBase);
288 for ( size_t i = 0, n = aSlotList.size(); i < n; ++i )
290 SvMetaSlot *pSlot = aSlotList[ i ];
291 pSlot->SetListPos( i );
294 size_t nSlotCount = aSlotList.size();
296 // write all attributes
297 sal_uInt16 nArgCount = WriteSlotParamArray( rBase, aSlotList, rOutStm );
298 if( nArgCount )
299 Back2Delimiter( rOutStm );
300 else
302 // at least one dummy
303 WriteTab( rOutStm, 1 );
304 rOutStm.WriteCharPtr("{ (const SfxType*) &aSfxVoidItem_Impl, 0, 0 }" ) << endl;
306 rOutStm << endl;
307 rOutStm.WriteCharPtr( "};" ) << endl << endl;
309 std::vector<OString> aStringList;
310 WriteSlotStubs( GetName(), aSlotList, aStringList, rOutStm );
311 aStringList.clear();
313 rOutStm << endl;
315 // write slotmap
316 rOutStm.WriteCharPtr("static SfxSlot a").WriteOString(GetName()).WriteCharPtr("Slots_Impl[] =") << endl;
317 rOutStm.WriteChar( '{' ) << endl;
319 // write all attributes
320 WriteSlots( GetName(), aSlotList, rBase, rOutStm );
321 if( nSlotCount )
322 Back2Delimiter( rOutStm );
323 else
325 // at least one dummy
326 WriteTab( rOutStm, 1 );
327 rOutStm.WriteCharPtr( "SFX_SLOT_ARG(" ).WriteOString( GetName() )
328 .WriteCharPtr( ", 0, SfxGroupId::NONE, " )
329 .WriteCharPtr( "SFX_STUB_PTR_EXEC_NONE," )
330 .WriteCharPtr( "SFX_STUB_PTR_STATE_NONE," )
331 .WriteCharPtr( "SfxSlotMode::NONE, SfxVoidItem, 0, 0, \"\", SfxSlotMode::NONE )" ) << endl;
333 rOutStm << endl;
334 rOutStm.WriteCharPtr( "};" ) << endl;
335 rOutStm.WriteCharPtr( "#endif" ) << endl << endl;
337 for( size_t i = 0, n = aSlotList.size(); i < n; ++i )
339 SvMetaSlot* pAttr = aSlotList[ i ];
340 pAttr->ResetSlotPointer();
343 aSlotList.clear();
346 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */