LibreOffice Module sc (master)  1
funcdesc.hxx
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 #ifndef INCLUDED_SC_INC_FUNCDESC_HXX
21 #define INCLUDED_SC_INC_FUNCDESC_HXX
22 
23 /* Function descriptions for function wizard / autopilot */
24 
25 #include "scfuncs.hxx"
26 
28 #include <sal/types.h>
29 #include <rtl/ustring.hxx>
30 #include <optional>
31 #include <map>
32 #include <memory>
33 
34 #define MAX_FUNCCAT 12 /* maximum number of categories for functions */
35 #define LRU_MAX 10 /* maximal number of last recently used functions */
36 
42 {
43 public:
44  ScFuncDesc();
45  virtual ~ScFuncDesc();
46 
53  void Clear();
54 
65  virtual void fillVisibleArgumentMapping(::std::vector<sal_uInt16>& _rArguments) const override ;
66 
72  virtual const formula::IFunctionCategory* getCategory() const override ;
73 
79  virtual OUString getDescription() const override ;
80 
86  virtual OUString getFormula(const ::std::vector< OUString >& _aArguments) const override ;
87 
93  virtual OUString getFunctionName() const override ;
94 
100  virtual OString getHelpId() const override ;
101 
107  virtual bool isHidden() const override;
108 
114  virtual sal_uInt32 getParameterCount() const override ;
115 
121  virtual sal_uInt32 getVarArgsStart() const override ;
122 
128  virtual sal_uInt32 getVarArgsLimit() const override ;
129 
138  virtual OUString getParameterDescription(sal_uInt32 _nPos) const override ;
139 
148  virtual OUString getParameterName(sal_uInt32 _nPos) const override ;
149 
155  OUString GetParamList() const;
156 
162  virtual OUString getSignature() const override ;
163 
174  sal_uInt16 GetSuppressedArgCount() const;
175  virtual sal_Int32 getSuppressedArgumentCount() const override ;
176 
182  virtual void initArgumentInfo() const override;
183 
192  virtual bool isParameterOptional(sal_uInt32 _nPos) const override ;
193 
205  static bool compareByName(const ScFuncDesc* a, const ScFuncDesc* b);
206 
211  {
212  bool bOptional :1;
214  ParameterFlags() : bOptional(false) {}
215  };
216 
217  std::optional<OUString> mxFuncName;
218  std::optional<OUString> mxFuncDesc;
219  std::vector<OUString> maDefArgNames;
220  std::vector<OUString> maDefArgDescs;
222  sal_uInt16 nFIndex;
223  sal_uInt16 nCategory;
224  sal_uInt16 nArgCount;
225  sal_uInt16 nVarArgsStart;
226  sal_uInt16 nVarArgsLimit;
227  OString sHelpId;
228  bool bIncomplete :1;
229  bool mbHidden :1;
230 };
231 
243 {
244 public:
245  ScFunctionList();
246  ~ScFunctionList();
247 
248  sal_uInt32 GetCount() const
249  { return aFunctionList.size(); }
250 
251  const ScFuncDesc* First();
252 
253  const ScFuncDesc* Next();
254 
255  const ScFuncDesc* GetFunction( sal_uInt32 nIndex ) const;
256 
257 private:
258  ::std::vector<const ScFuncDesc*> aFunctionList;
259  ::std::vector<const ScFuncDesc*>::iterator aFunctionListIter;
260 };
261 
269 {
270 public:
271  ScFunctionCategory(::std::vector<const ScFuncDesc*>* _pCategory,sal_uInt32 _nCategory)
272  : m_pCategory(_pCategory),m_nCategory(_nCategory){}
274 
278  virtual sal_uInt32 getCount() const override;
279 
288  virtual const formula::IFunctionDescription* getFunction(sal_uInt32 _nPos) const override;
289 
293  virtual sal_uInt32 getNumber() const override;
294  virtual OUString getName() const override;
295 
296 private:
297  ::std::vector<const ScFuncDesc*>* m_pCategory;
298  mutable OUString m_sName;
299  sal_uInt32 m_nCategory;
300 };
301 
302 #define SC_FUNCGROUP_COUNT ID_FUNCTION_GRP_ADDINS
303 
307 {
308 public:
314  ScFunctionMgr();
315  virtual ~ScFunctionMgr();
316 
325  static OUString GetCategoryName(sal_uInt32 _nCategoryNumber );
326 
337  const ScFuncDesc* Get( sal_uInt16 nFIndex ) const;
338 
349  const ScFuncDesc* First( sal_uInt16 nCategory = 0 ) const;
350 
356  const ScFuncDesc* Next() const;
357 
361  virtual sal_uInt32 getCount() const override;
362 
373  virtual const formula::IFunctionCategory* getCategory(sal_uInt32 nPos) const override;
374 
383  virtual void fillLastRecentlyUsedFunctions(::std::vector< const formula::IFunctionDescription*>& _rLastRUFunctions) const override;
384 
395  virtual sal_Unicode getSingleToken(const formula::IFunctionManager::EToken _eToken) const override;
396 
397 private:
398  std::unique_ptr<std::vector<const ScFuncDesc*>> aCatLists[MAX_FUNCCAT];
399  mutable std::map< sal_uInt32, std::shared_ptr<ScFunctionCategory> > m_aCategories;
400  mutable std::vector<const ScFuncDesc*>::iterator pCurCatListIter;
401  mutable std::vector<const ScFuncDesc*>::iterator pCurCatListEnd;
402 };
403 
404 #endif // INCLUDED_SC_INC_FUNCDESC_HXX
405 
406 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual sal_uInt32 getCount() const override
Definition: funcdesc.cxx:1139
sal_uInt32 m_nCategory
index number of this category
Definition: funcdesc.hxx:299
virtual bool isHidden() const override
Returns whether function is hidden and not offered in the Function Wizard unless used in an expressio...
Definition: funcdesc.cxx:358
List of spreadsheet functions.
Definition: funcdesc.hxx:242
OUString m_sName
name of this category
Definition: funcdesc.hxx:298
virtual sal_uInt32 getVarArgsStart() const override
Returns start of variable arguments.
Definition: funcdesc.cxx:368
std::map< sal_uInt32, std::shared_ptr< ScFunctionCategory > > m_aCategories
map of category pos to IFunctionCategory
Definition: funcdesc.hxx:399
sal_uInt16 GetSuppressedArgCount() const
Returns the number of non-suppressed arguments.
Definition: funcdesc.cxx:278
bool bOptional
Parameter is optional.
Definition: funcdesc.hxx:212
virtual sal_Int32 getSuppressedArgumentCount() const override
Definition: funcdesc.cxx:304
const ScFuncDesc * Get(sal_uInt16 nFIndex) const
Returns function by index.
Definition: funcdesc.cxx:1099
const ScFuncDesc * Next() const
Returns the next function of the current category.
Definition: funcdesc.cxx:1126
Stores whether a parameter is optional or suppressed.
Definition: funcdesc.hxx:210
virtual sal_uInt32 getVarArgsLimit() const override
Returns maximum number of (variable) arguments.
Definition: funcdesc.cxx:373
virtual OUString getName() const override
Definition: funcdesc.cxx:1030
virtual bool isParameterOptional(sal_uInt32 _nPos) const override
Returns true if parameter at given position is optional.
Definition: funcdesc.cxx:388
virtual const formula::IFunctionCategory * getCategory(sal_uInt32 nPos) const override
Returns a category.
Definition: funcdesc.cxx:1144
virtual sal_Unicode getSingleToken(const formula::IFunctionManager::EToken _eToken) const override
Maps Etoken to character.
Definition: funcdesc.cxx:1182
virtual sal_uInt32 getNumber() const override
Definition: funcdesc.cxx:1045
virtual OUString getParameterDescription(sal_uInt32 _nPos) const override
Returns description of parameter at given position.
Definition: funcdesc.cxx:383
Stores spreadsheet functions in categories, including a cumulative ('All') category and makes them ac...
Definition: funcdesc.hxx:306
virtual ~ScFunctionMgr()
Definition: funcdesc.cxx:1094
bool mbHidden
Whether function is hidden.
Definition: funcdesc.hxx:229
virtual const formula::IFunctionDescription * getFunction(sal_uInt32 _nPos) const override
Gives the _nPos'th function in this category.
Definition: funcdesc.cxx:1037
virtual ~ScFunctionCategory()
Definition: funcdesc.hxx:273
sal_uInt16 sal_Unicode
::std::vector< const ScFuncDesc * > * m_pCategory
list of functions in this category
Definition: funcdesc.hxx:297
Category of spreadsheet functions.
Definition: funcdesc.hxx:268
const ScFuncDesc * First()
Definition: funcdesc.cxx:994
ParameterFlags * pDefArgFlags
Flags for each parameter.
Definition: funcdesc.hxx:221
virtual OUString getFormula(const ::std::vector< OUString > &_aArguments) const override
Returns the function signature with parameters from the passed string array.
Definition: funcdesc.cxx:247
OUString GetParamList() const
Returns list of all parameter names.
Definition: funcdesc.cxx:146
sal_uInt16 nCategory
Function category.
Definition: funcdesc.hxx:223
virtual OUString getSignature() const override
Returns the full function signature.
Definition: funcdesc.cxx:224
uno_Any a
virtual sal_uInt32 getParameterCount() const override
Returns number of arguments.
Definition: funcdesc.cxx:363
std::vector< OUString > maDefArgDescs
Description(s) of parameter(s)
Definition: funcdesc.hxx:220
static bool compareByName(const ScFuncDesc *a, const ScFuncDesc *b)
Compares functions by name, respecting special characters.
Definition: funcdesc.cxx:393
virtual void fillVisibleArgumentMapping(::std::vector< sal_uInt16 > &_rArguments) const override
Fills a mapping with indexes for non-suppressed arguments.
Definition: funcdesc.cxx:309
std::optional< OUString > mxFuncDesc
Description of function.
Definition: funcdesc.hxx:218
std::vector< const ScFuncDesc * >::iterator pCurCatListIter
position in current category
Definition: funcdesc.hxx:400
static OUString GetCategoryName(sal_uInt32 _nCategoryNumber)
Returns name of category.
Definition: funcdesc.cxx:1171
virtual OString getHelpId() const override
Returns the help id of the function.
Definition: funcdesc.cxx:353
const ScFuncDesc * GetFunction(sal_uInt32 nIndex) const
Definition: funcdesc.cxx:1015
virtual const formula::IFunctionCategory * getCategory() const override
Returns the category of the function.
Definition: funcdesc.cxx:291
virtual sal_uInt32 getCount() const override
Definition: funcdesc.cxx:1025
std::unique_ptr< std::vector< const ScFuncDesc * > > aCatLists[MAX_FUNCCAT]
array of all categories, 0 is the cumulative ('All') category
Definition: funcdesc.hxx:398
ScFunctionCategory(::std::vector< const ScFuncDesc * > *_pCategory, sal_uInt32 _nCategory)
Definition: funcdesc.hxx:271
virtual void fillLastRecentlyUsedFunctions(::std::vector< const formula::IFunctionDescription * > &_rLastRUFunctions) const override
Appends the last recently used functions.
Definition: funcdesc.cxx:1155
sal_uInt16 nVarArgsStart
Start of variable arguments, for numbering.
Definition: funcdesc.hxx:225
sal_uInt16 nVarArgsLimit
Limit maximum of (variable) arguments, for numbering.
Definition: funcdesc.hxx:226
std::optional< OUString > mxFuncName
Function name.
Definition: funcdesc.hxx:217
void Clear()
Clears the object.
Definition: funcdesc.cxx:118
ScFunctionMgr()
Retrieves all calc functions, generates cumulative ('All') category, and the categories.
Definition: funcdesc.cxx:1051
#define MAX_FUNCCAT
Definition: funcdesc.hxx:34
virtual void initArgumentInfo() const override
Requests function data from AddInCollection.
Definition: funcdesc.cxx:327
const ScFuncDesc * Next()
Definition: funcdesc.cxx:1004
sal_Int32 _nPos
sal_uInt16 nFIndex
Unique function index.
Definition: funcdesc.hxx:222
sal_uInt32 GetCount() const
Definition: funcdesc.hxx:248
virtual OUString getDescription() const override
Returns the description of the function.
Definition: funcdesc.cxx:296
OString sHelpId
HelpId of function.
Definition: funcdesc.hxx:227
virtual OUString getFunctionName() const override
Returns the name of the function.
Definition: funcdesc.cxx:283
std::vector< OUString > maDefArgNames
Parameter name(s)
Definition: funcdesc.hxx:219
::std::vector< const ScFuncDesc * >::iterator aFunctionListIter
position in function list
Definition: funcdesc.hxx:259
virtual OUString getParameterName(sal_uInt32 _nPos) const override
Returns name of parameter at given position.
Definition: funcdesc.cxx:378
bool bIncomplete
Incomplete argument info (set for add-in info from configuration)
Definition: funcdesc.hxx:228
Stores and generates human readable descriptions for spreadsheet-functions, e.g. functions used in fo...
Definition: funcdesc.hxx:41
sal_uInt16 nArgCount
All parameter count, suppressed and unsuppressed.
Definition: funcdesc.hxx:224
std::vector< const ScFuncDesc * >::iterator pCurCatListEnd
end of current category
Definition: funcdesc.hxx:401
virtual ~ScFuncDesc()
Definition: funcdesc.cxx:113
::std::vector< const ScFuncDesc * > aFunctionList
List of functions.
Definition: funcdesc.hxx:258
sal_uInt16 nPos
const ScFuncDesc * First(sal_uInt16 nCategory=0) const
Returns the first function in category nCategory.
Definition: funcdesc.cxx:1108