LibreOffice Module idl (master) 1
object.cxx
Go to the documentation of this file.
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#include <sal/config.h>
21
22#include <algorithm>
23
24#include <rtl/strbuf.hxx>
25#include <sal/log.hxx>
26
27#include <object.hxx>
28#include <globals.hxx>
29#include <database.hxx>
30#include <slot.hxx>
31
32
34{
35};
36
38{
39}
40
42 SvTokenStream & rInStm )
43{
44 sal_uInt32 nTokPos = rInStm.Tell();
45 SvToken& rTok = rInStm.GetToken_Next();
46
47 if( rTok.Is( SvHash_import() ) )
48 {
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 );
55
56 rTok = rInStm.GetToken();
57 if( rTok.IsString() )
58 {
59 aEle.SetPrefix( rTok.GetString() );
60 rInStm.GetToken_Next();
61 }
62 return;
63 }
64 else
65 {
66 rInStm.Seek( nTokPos );
67 SvMetaType * pType = rBase.ReadKnownType( rInStm );
68
69 bool bOk = false;
71 if( !pType || pType->IsItem() )
72 {
73 xAttr = new SvMetaSlot( pType );
74 if( xAttr->ReadSvIdl( rBase, rInStm ) )
75 bOk = xAttr->Test( rInStm );
76 }
77 else
78 {
79 xAttr = new SvMetaAttribute( pType );
80 if( xAttr->ReadSvIdl( rBase, rInStm ) )
81 bOk = xAttr->Test( rInStm );
82 }
83
84 if( bOk )
85 bOk = TestAttribute( rBase, rInStm, *xAttr );
86 if( bOk )
87 {
88 if( !xAttr->GetSlotId().IsSet() )
89 {
90 SvIdentifier aI;
91 aI.SetValue( rBase.GetUniqueId() );
92 xAttr->SetSlotId( aI );
93 }
94 aAttrList.push_back( xAttr.get() );
95 return;
96 }
97 }
98 rInStm.Seek( nTokPos );
99}
100
102 SvMetaAttribute & rAttr ) const
103{
104 if ( !rAttr.GetRef() && dynamic_cast<const SvMetaSlot *>(&rAttr) )
105 {
106 SAL_WARN( "idl", "new slot : " << rAttr.GetSlotId().getString() );
107 }
108
109 for( const auto &pS : aAttrList )
110 {
111 if( pS->GetName() == rAttr.GetName() )
112 {
113 // values have to match
114 if( pS->GetSlotId().GetValue() != rAttr.GetSlotId().GetValue() )
115 {
116 throw SvParseException( rInStm, "Attribute's " + pS->GetName() + " with different id's");
117 }
118 }
119 else
120 {
121 sal_uInt32 nId1 = pS->GetSlotId().GetValue();
122 sal_uInt32 nId2 = rAttr.GetSlotId().GetValue();
123 if( nId1 == nId2 && nId1 != 0 )
124 {
125 OString aStr = "Attribute " + pS->GetName() + " and Attribute " + rAttr.GetName() + " with equal id's";
126 throw SvParseException(rInStm, aStr);
127 }
128 }
129 }
130 SvMetaClass * pSC = aSuperClass.get();
131 if( pSC )
132 return pSC->TestAttribute( rBase, rInStm, rAttr );
133 return true;
134}
135
137 SvSlotElementList & rSlotList,
138 SvStream & rOutStm )
139{
140 sal_uInt16 nCount = 0;
141 for ( size_t i = 0, n = rSlotList.size(); i < n; ++i )
142 {
143 SvMetaSlot *pAttr = rSlotList[ i ];
144 nCount = nCount + pAttr->WriteSlotParamArray( rBase, rOutStm );
145 }
146
147 return nCount;
148}
149
150sal_uInt16 SvMetaClass::WriteSlots( std::string_view rShellName,
151 SvSlotElementList & rSlotList,
152 SvIdlDataBase & rBase,
153 SvStream & rOutStm )
154{
155 sal_uInt16 nSCount = 0;
156 for ( size_t i = 0, n = rSlotList.size(); i < n; ++i )
157 {
158 SvMetaSlot * pAttr = rSlotList[ i ];
159 nSCount = nSCount + pAttr->WriteSlotMap( rShellName, nSCount,
160 rSlotList, i, rBase,
161 rOutStm );
162 }
163
164 return nSCount;
165}
166
167void SvMetaClass::InsertSlots( SvSlotElementList& rList, std::vector<sal_uInt32>& rSuperList,
168 SvMetaClassList &rClassList,
169 const OString& rPrefix, SvIdlDataBase& rBase)
170{
171 // was this class already written?
172 for ( size_t i = 0, n = rClassList.size(); i < n ; ++i )
173 if ( rClassList[ i ] == this )
174 return;
175
176 rClassList.push_back( this );
177
178 // write all direct attributes
179 size_t n;
180 for( n = 0; n < aAttrList.size(); n++ )
181 {
182 SvMetaAttribute * pAttr = aAttrList[n];
183
184 sal_uInt32 nId = pAttr->GetSlotId().GetValue();
185
186 std::vector<sal_uInt32>::iterator iter = std::find(rSuperList.begin(),
187 rSuperList.end(),nId);
188
189 if( iter == rSuperList.end() )
190 {
191 // Write only if not already written by subclass or
192 // imported interface.
193 rSuperList.push_back(nId);
194 pAttr->Insert(rList);
195 }
196 }
197
198 // All Interfaces already imported by SuperShell should not be
199 // written any more.
200 // It is prohibited that Shell and SuperShell directly import the same
201 // class.
203 aSuperClass->FillClasses( rClassList );
204
205 // Write all attributes of the imported classes, as long as they have
206 // not already been imported by the superclass.
207 for( n = 0; n < aClassElementList.size(); n++ )
208 {
210 SvMetaClass * pCl = rElement.GetClass();
211 OStringBuffer rPre(rPrefix.getLength() + 1 + rElement.GetPrefix().getLength());
212 rPre.append(rPrefix);
213 if( !rPre.isEmpty() && !rElement.GetPrefix().isEmpty() )
214 rPre.append('.');
215 rPre.append(rElement.GetPrefix());
216
217 // first of all write direct imported interfaces
218 pCl->InsertSlots( rList, rSuperList, rClassList,
219 rPre.makeStringAndClear(), rBase );
220 }
221
222 // only write superclass if no shell and not in the list
224 {
225 aSuperClass->InsertSlots( rList, rSuperList, rClassList, rPrefix, rBase );
226 }
227}
228
230{
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;
235
236 rList.push_back( this );
237
238 // my imports
239 for( size_t n = 0; n < aClassElementList.size(); n++ )
240 {
242 SvMetaClass * pCl = rElement.GetClass();
243 pCl->FillClasses( rList );
244 }
245
246 // my superclass
247 if( aSuperClass.is() )
248 aSuperClass->FillClasses( rList );
249}
250
251
252void SvMetaClass::WriteSlotStubs( std::string_view rShellName,
253 SvSlotElementList & rSlotList,
254 std::vector<OString> & rList,
255 SvStream & rOutStm )
256{
257 // write all attributes
258 for ( size_t i = 0, n = rSlotList.size(); i < n; ++i )
259 {
260 SvMetaSlot *pAttr = rSlotList[ i ];
261 pAttr->WriteSlotStubs( rShellName, rList, rOutStm );
262 }
263}
264
266{
267 WriteStars( rOutStm );
268 // define class
269 rOutStm.WriteOString( "#ifdef ShellClass_" ).WriteOString( GetName() ) << endl;
270 rOutStm.WriteOString( "#undef ShellClass" ) << endl;
271 rOutStm.WriteOString( "#undef ShellClass_" ).WriteOString( GetName() ) << endl;
272 rOutStm.WriteOString( "#define ShellClass " ).WriteOString( GetName() ) << endl;
273
274 // no slotmaps get written for interfaces
276 {
277 rOutStm.WriteOString( "#endif" ) << endl << endl;
278 return;
279 }
280 // write parameter array
281 rOutStm.WriteOString("static SfxFormalArgument a").WriteOString(GetName()).WriteOString("Args_Impl[] =") << endl;
282 rOutStm.WriteChar('{') << endl;
283
284 std::vector<sal_uInt32> 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 )
289 {
290 SvMetaSlot *pSlot = aSlotList[ i ];
291 pSlot->SetListPos( i );
292 }
293
294 size_t nSlotCount = aSlotList.size();
295
296 // write all attributes
297 sal_uInt16 nArgCount = WriteSlotParamArray( rBase, aSlotList, rOutStm );
298 if( nArgCount )
299 Back2Delimiter( rOutStm );
300 else
301 {
302 // at least one dummy
303 WriteTab( rOutStm, 1 );
304 rOutStm.WriteOString("{ (const SfxType*) &aSfxVoidItem_Impl, 0, 0 }" ) << endl;
305 }
306 rOutStm << endl;
307 rOutStm.WriteOString( "};" ) << endl << endl;
308
309 std::vector<OString> aStringList;
310 WriteSlotStubs( GetName(), aSlotList, aStringList, rOutStm );
311 aStringList.clear();
312
313 rOutStm << endl;
314
315 // write slotmap
316 rOutStm.WriteOString("static SfxSlot a").WriteOString(GetName()).WriteOString("Slots_Impl[] =") << endl;
317 rOutStm.WriteChar( '{' ) << endl;
318
319 // write all attributes
320 WriteSlots( GetName(), aSlotList, rBase, rOutStm );
321 if( nSlotCount )
322 Back2Delimiter( rOutStm );
323 else
324 {
325 // at least one dummy
326 WriteTab( rOutStm, 1 );
327 rOutStm.WriteOString( "SFX_SLOT_ARG(" ).WriteOString( GetName() )
328 .WriteOString( ", 0, SfxGroupId::NONE, " )
329 .WriteOString( "SFX_STUB_PTR_EXEC_NONE," )
330 .WriteOString( "SFX_STUB_PTR_STATE_NONE," )
331 .WriteOString( "SfxSlotMode::NONE, SfxVoidItem, 0, 0, \"\", SfxSlotMode::NONE )" ) << endl;
332 }
333 rOutStm << endl;
334 rOutStm.WriteOString( "};" ) << endl;
335 rOutStm.WriteOString( "#endif" ) << endl << endl;
336
337 for( size_t i = 0, n = aSlotList.size(); i < n; ++i )
338 {
339 SvMetaSlot* pAttr = aSlotList[ i ];
340 pAttr->ResetSlotPointer();
341 }
342
343 aSlotList.clear();
344}
345
346/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const OString & GetPrefix() const
Definition: object.hxx:42
void SetClass(SvMetaClass *pClass)
Definition: object.hxx:45
void SetPrefix(const OString &rPrefix)
Definition: object.hxx:40
SvMetaClass * GetClass() const
Definition: object.hxx:47
void SetValue(sal_uInt32 bVal)
Definition: bastype.hxx:65
const OString & getString() const
Definition: bastype.hxx:57
sal_uInt32 GetValue() const
Definition: bastype.hxx:64
SvMetaClass * ReadKnownClass(SvTokenStream &rInStm)
Definition: database.cxx:367
sal_uInt32 GetUniqueId()
Definition: database.hxx:113
SvMetaType * ReadKnownType(SvTokenStream &rInStm)
Definition: database.cxx:294
const SvIdentifier & GetSlotId() const
Definition: types.cxx:45
virtual void Insert(SvSlotElementList &)
Definition: types.cxx:118
SvRefMemberList< SvMetaAttribute * > aAttrList
Definition: object.hxx:57
bool TestAttribute(SvIdlDataBase &rBase, SvTokenStream &rInStm, SvMetaAttribute &rAttr) const
Definition: object.cxx:101
void FillClasses(SvMetaClassList &rList)
Definition: object.cxx:229
virtual void WriteSfx(SvIdlDataBase &rBase, SvStream &rOutStm) override
Definition: object.cxx:265
static void WriteSlotStubs(std::string_view rShellName, SvSlotElementList &rSlotList, std::vector< OString > &rList, SvStream &rOutStm)
Definition: object.cxx:252
void InsertSlots(SvSlotElementList &rList, std::vector< sal_uInt32 > &rSuperList, SvMetaClassList &rClassList, const OString &rPrefix, SvIdlDataBase &rBase)
Definition: object.cxx:167
static sal_uInt16 WriteSlots(std::string_view rShellName, SvSlotElementList &rSlotList, SvIdlDataBase &rBase, SvStream &rOutStm)
Definition: object.cxx:150
virtual void ReadContextSvIdl(SvIdlDataBase &, SvTokenStream &rInStm) override
Definition: object.cxx:41
std::vector< SvClassElement > aClassElementList
Definition: object.hxx:56
static sal_uInt16 WriteSlotParamArray(SvIdlDataBase &rBase, SvSlotElementList &rSlotList, SvStream &rOutStm)
Definition: object.cxx:136
SvMetaClass()
Definition: object.cxx:37
tools::SvRef< SvMetaClass > aSuperClass
Definition: object.hxx:55
static void WriteStars(SvStream &)
Definition: basobj.cxx:33
static void WriteTab(SvStream &rOutStm, sal_uInt16 nTab)
Definition: basobj.cxx:27
static void Back2Delimiter(SvStream &)
Definition: basobj.cxx:41
SvMetaReference * GetRef() const
Definition: basobj.hxx:120
const OString & GetName() const override
Definition: basobj.hxx:112
void ResetSlotPointer()
Definition: slot.hxx:111
void WriteSlotStubs(std::string_view rShellName, std::vector< OString > &rList, SvStream &rOutStm) const
Definition: slot.cxx:335
sal_uInt16 WriteSlotMap(std::string_view rShellName, sal_uInt16 nCount, SvSlotElementList &, size_t nStart, SvIdlDataBase &rBase, SvStream &rOutStm)
Definition: slot.cxx:600
sal_uInt16 WriteSlotParamArray(SvIdlDataBase &rBase, SvStream &rOutStm) const
Definition: slot.cxx:570
void SetListPos(sal_uInt32 n)
Definition: slot.hxx:109
bool IsItem() const
Definition: types.hxx:79
MetaTypeType GetMetaTypeType() const
Definition: types.hxx:75
void clear()
Definition: basobj.hxx:51
void push_back(T p)
Definition: basobj.hxx:62
SvStream & WriteOString(std::string_view rStr)
SvStream & WriteChar(char nChar)
void Seek(sal_uInt32 nPos)
Definition: lex.hxx:202
SvToken & GetToken() const
Definition: lex.hxx:177
SvToken & GetToken_Next()
Definition: lex.hxx:165
sal_uInt32 Tell() const
Definition: lex.hxx:200
Definition: lex.hxx:36
bool IsString() const
Definition: lex.hxx:64
bool Is(SvStringHashEntry const *pEntry) const
Definition: lex.hxx:88
const OString & GetString() const
Definition: lex.hxx:76
T * get() const
bool is() const
int nCount
const char * pS
sal_Int64 n
#define SAL_WARN(area, stream)
aStr
int i
::std::vector< SvMetaClass * > SvMetaClassList
Definition: object.hxx:29
sal_Int16 nId
TOOLS_DLLPUBLIC SvStream & endl(SvStream &rStr)
@ Shell
Definition: types.hxx:50
const std::u16string_view aStringList[]