Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/basic/sbx.hxx
Line
Count
Source
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
#pragma once
21
22
#include <config_options.h>
23
#include <tools/ref.hxx>
24
#include <svl/hint.hxx>
25
26
#include <basic/sbxdef.hxx>
27
#include <basic/sbxobj.hxx>
28
#include <basic/basicdllapi.h>
29
30
#include <utility>
31
#include <vector>
32
#include <memory>
33
34
class SvStream;
35
36
// Parameter information
37
struct SbxParamInfo
38
{
39
    const OUString aName;          // Name of the parameter
40
    SbxDataType    eType;          // Data type
41
    SbxFlagBits    nFlags;         // Flag-Bits
42
    sal_uInt32     nUserData;      // IDs etc.
43
    SbxParamInfo( OUString s, SbxDataType t, SbxFlagBits n )
44
0
        : aName(std::move( s )), eType( t ), nFlags( n ), nUserData( 0 ) {}
45
};
46
47
typedef std::vector<std::unique_ptr<SbxParamInfo>> SbxParams;
48
49
class UNLESS_MERGELIBS(BASIC_DLLPUBLIC) SbxInfo final : public SvRefBase
50
{
51
    friend class SbxVariable;
52
    friend class SbMethod;
53
54
    OUString        aComment;
55
    OUString        aHelpFile;
56
    sal_uInt32      nHelpId;
57
    SbxParams       m_Params;
58
59
    SbxInfo(SbxInfo const&) = delete;
60
    void operator=(SbxInfo const&) = delete;
61
62
    void LoadData( SvStream&, sal_uInt16 );
63
    void StoreData( SvStream& ) const;
64
    virtual ~SbxInfo() override;
65
public:
66
    SbxInfo();
67
    SbxInfo( OUString , sal_uInt32 );
68
69
    void                AddParam( const OUString&, SbxDataType, SbxFlagBits=SbxFlagBits::Read );
70
    const SbxParamInfo* GetParam( sal_uInt16 n ) const; // index starts with 1!
71
0
    const OUString&     GetComment() const              { return aComment; }
72
0
    const OUString&     GetHelpFile() const             { return aHelpFile; }
73
0
    sal_uInt32          GetHelpId() const               { return nHelpId;   }
74
75
0
    void                SetComment( const OUString& r )   { aComment = r; }
76
};
77
78
class BASIC_DLLPUBLIC SbxHint final : public SfxHint
79
{
80
    SbxVariable* pVar;
81
public:
82
0
    SbxHint( SfxHintId n, SbxVariable* v ) : SfxHint( n ), pVar( v ) {}
83
    ~SbxHint() override;
84
0
    SbxVariable* GetVar() const { return pVar; }
85
};
86
87
// SbxArray is an unidimensional, dynamic Array
88
// The variables convert from SbxVariablen. Put()/Insert() into the
89
// declared datatype, if they are not SbxVARIANT.
90
91
struct SbxVarEntry;
92
93
class BASIC_DLLPUBLIC SbxArray : public SbxBase
94
{
95
// #100883 Method to set method directly to parameter array
96
    friend class SbMethod;
97
    friend class SbClassModuleObject;
98
    friend SbxObjectRef cloneTypeObjectImpl( const SbxObject& rTypeObj );
99
    BASIC_DLLPRIVATE void PutDirect( SbxVariable* pVar, sal_uInt32 nIdx );
100
101
    std::vector<SbxVarEntry> mVarEntries;          // The variables
102
    SbxDataType eType;            // Data type of the array
103
104
protected:
105
    virtual ~SbxArray() override;
106
    virtual bool LoadData( SvStream&, sal_uInt16 ) override;
107
    virtual std::pair<bool, sal_uInt32> StoreData( SvStream& ) const override;
108
109
public:
110
    SBX_DECL_PERSIST_NODATA(SBXID_ARRAY,1);
111
    SbxArray( SbxDataType=SbxVARIANT );
112
    SbxArray( const SbxArray& ) = delete;
113
    SbxArray& operator=( const SbxArray& );
114
    virtual void Clear() override;
115
    sal_uInt32 Count() const;
116
    virtual SbxDataType  GetType() const override;
117
    SbxVariableRef& GetRef(sal_uInt32);
118
    SbxVariable* Get(sal_uInt32);
119
    void Put(SbxVariable*, sal_uInt32);
120
    void Insert(SbxVariable*, sal_uInt32);
121
    void                 Remove( sal_uInt32 );
122
    void                 Remove( SbxVariable const * );
123
    void                 Merge( SbxArray* );
124
    const OUString & GetAlias(sal_uInt32);
125
    void PutAlias(const OUString&, sal_uInt32);
126
    SbxVariable* Find( const OUString&, SbxClassType );
127
};
128
129
// SbxDimArray is an array that can dimensioned using BASIC conventions.
130
struct SbxDim {                 // an array-dimension:
131
    sal_Int32 nLbound, nUbound; // Limitations
132
    sal_Int32 nSize;            // Number of elements
133
};
134
135
class BASIC_DLLPUBLIC SbxDimArray final : public SbxArray
136
{
137
    std::vector<SbxDim> m_vDimensions;     // Dimension table
138
    BASIC_DLLPRIVATE void AddDimImpl(sal_Int32, sal_Int32, bool bAllowSize0);
139
    bool mbHasFixedSize;
140
141
    sal_uInt32 Offset(const sal_Int32*);
142
    sal_uInt32 Offset(SbxArray*);
143
    virtual bool LoadData( SvStream&, sal_uInt16 ) override;
144
    virtual std::pair<bool, sal_uInt32> StoreData( SvStream& ) const override;
145
    virtual ~SbxDimArray() override;
146
public:
147
    SBX_DECL_PERSIST_NODATA(SBXID_DIMARRAY,1);
148
    SbxDimArray( SbxDataType=SbxVARIANT );
149
    SbxDimArray( const SbxDimArray& ) = delete;
150
    SbxDimArray& operator=( const SbxDimArray& );
151
    virtual void Clear() override;
152
    SbxVariable* Get( SbxArray* );
153
154
    using SbxArray::GetRef;
155
    using SbxArray::Get;
156
    SbxVariable* Get(const sal_Int32*);
157
    using SbxArray::Put;
158
    void Put(SbxVariable*, const sal_Int32*);
159
0
    sal_Int32 GetDims() const { return m_vDimensions.size(); }
160
    void AddDim(sal_Int32, sal_Int32);
161
    void unoAddDim(sal_Int32, sal_Int32);
162
    bool GetDim(sal_Int32, sal_Int32&, sal_Int32&) const;
163
0
    bool hasFixedSize() const { return mbHasFixedSize; };
164
0
    void setHasFixedSize( bool bHasFixedSize ) {mbHasFixedSize = bHasFixedSize; };
165
};
166
167
class SbxCollection : public SbxObject
168
{
169
    void Initialize();
170
protected:
171
    virtual ~SbxCollection() override;
172
    virtual bool LoadData( SvStream&, sal_uInt16 ) override;
173
    virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
174
    // Overridable methods (why not pure virtual?):
175
    virtual void CollAdd( SbxArray* pPar );
176
    void CollItem( SbxArray* pPar );
177
    virtual void CollRemove( SbxArray* pPar );
178
179
public:
180
    SBX_DECL_PERSIST_NODATA(SBXID_COLLECTION,1);
181
    SbxCollection();
182
    SbxCollection( const SbxCollection& );
183
    SbxCollection& operator=( const SbxCollection& );
184
    virtual SbxVariable* Find( const OUString&, SbxClassType ) override;
185
    virtual void Clear() override;
186
};
187
188
class SbxStdCollection final : public SbxCollection
189
{
190
    OUString aElemClass;
191
    bool bAddRemoveOk;
192
    virtual ~SbxStdCollection() override;
193
    virtual bool LoadData( SvStream&, sal_uInt16 ) override;
194
    virtual std::pair<bool, sal_uInt32> StoreData( SvStream& ) const override;
195
    virtual void CollAdd( SbxArray* pPar ) override;
196
    virtual void CollRemove( SbxArray* pPar ) override;
197
public:
198
    SBX_DECL_PERSIST_NODATA(SBXID_FIXCOLLECTION,1);
199
    SbxStdCollection();
200
    SbxStdCollection( const SbxStdCollection& );
201
    SbxStdCollection& operator=( const SbxStdCollection& );
202
    virtual void Insert( SbxVariable* ) override;
203
};
204
205
typedef tools::SvRef<SbxArray> SbxArrayRef;
206
typedef tools::SvRef<SbxInfo> SbxInfoRef;
207
typedef tools::SvRef<SbxDimArray> SbxDimArrayRef;
208
209
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */