merge the formfield patch from ooo-build
[ooovba.git] / sc / source / core / inc / parclass.hxx
blob1ff64651d2ca4207e0de9aaea4af4bf3647eda49
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: parclass.hxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SC_PARCLASS_HXX
32 #define SC_PARCLASS_HXX
34 #include "formula/opcode.hxx"
35 #include <sys/types.h> // size_t
37 namespace formula
39 class FormulaToken;
42 class ScParameterClassification
44 public:
46 enum Type
48 Unknown = 0, // MUST be zero for initialization mechanism!
50 /** Out of bounds, function doesn't expect that many parameters.
51 However, not necessarily returned. */
52 Bounds,
54 /** In array formula: single value to be passed. Results in JumpMatrix
55 being created and multiple calls to function. Functions handling a
56 formula::svDoubleRef by means of DoubleRefToPosSingleRef() or
57 PopDoubleRefOrSingleRef() or GetDouble() or GetString() should have
58 this. */
59 Value,
61 /** In array formula: area reference must stay reference. Otherwise
62 don't care. Functions handling a formula::svDoubleRef by means of
63 PopDoubleRefOrSingleRef() should not have this. */
64 Reference,
66 /** In array formula: convert area reference to array. Function will be
67 called only once if no Value type is involved. Functions able to
68 handle a svMatrix parameter but not a formula::svDoubleRef parameter as area
69 should have this. */
70 Array,
72 /** Area reference must be converted to array in any case, and must
73 also be propagated to subsequent operators and functions being part
74 of a parameter of this function. */
75 ForceArray,
77 /** Area reference is not converted to array, but ForceArray must be
78 propagated to subsequent operators and functions being part of a
79 parameter of this function. Used with functions that treat
80 references separately from arrays, but need the forced array
81 calculation of parameters that are not references.*/
82 ReferenceOrForceArray
85 /// MUST be called once before any other method.
86 static void Init();
88 static void Exit();
90 /** Get one parameter type for function eOp.
91 @param nParameter
92 Which parameter, 0-based */
93 static Type GetParameterType( const formula::FormulaToken* pToken,
94 USHORT nParameter);
96 /** Whether OpCode has a parameter of type
97 ForceArray or ReferenceOrForceArray. */
98 static inline bool HasForceArray( OpCode eOp)
100 return 0 <= (short)eOp &&
101 eOp <= SC_OPCODE_LAST_OPCODE_ID &&
102 pData[eOp].bHasForceArray;
105 private:
107 struct CommonData
109 const static size_t nMaxParams = 7;
111 Type nParam[nMaxParams];
112 bool bRepeatLast;
115 // SUNWS7 needs a forward declared friend, otherwise members of the outer
116 // class are not accessible (in this case CommonData).
117 struct RawData;
118 friend struct ScParameterClassification::RawData;
119 struct RawData
121 OpCode eOp;
122 CommonData aData;
125 struct RunData;
126 friend struct ScParameterClassification::RunData;
127 struct RunData
129 CommonData aData;
130 BYTE nMinParams; // fix or minimum, or repeat start
131 bool bHasForceArray;
134 static const RawData pRawData[];
135 static RunData* pData;
137 // ocExternal AddIns
138 static Type GetExternalParameterType(
139 const formula::FormulaToken* pToken, USHORT nParameter);
141 #if OSL_DEBUG_LEVEL > 1
142 // Generate documentation to stdout if environment variable
143 // OOO_CALC_GENPARCLASSDOC is set.
144 static void GenerateDocumentation();
146 /* OpCodes not specified in the implementation are taken from the global
147 * function list and all parameters, if any, are assumed to be of type
148 * Value. This could also be done in the product version if needed, but we
149 * don't want to spoil startup time. However, doing so could propagate the
150 * minimum parameter count to the formula compiler, which, together with
151 * additional information about optional parameters, could react on missing
152 * parameters then. */
153 static void MergeArgumentsFromFunctionResource();
155 /** Minimum number of parameters, or fix number
156 of parameters if HasRepeatParameters()
157 returns FALSE. For opcodes not specified in
158 the implementation a parameter count of 1
159 is assumed, for opcodes out of range 0 is
160 assumed. If HasRepeatParameters() returns
161 TRUE, information is NOT related to whether
162 any parameters are optional, only the type
163 of parameters is significant. */
164 static inline BYTE GetMinimumParameters( OpCode eOp)
166 if ( eOp <= SC_OPCODE_LAST_OPCODE_ID )
167 return pData[eOp].aData.nParam[0]
168 == Unknown ? 1 :
169 pData[eOp].nMinParams;
170 return 0;
173 /** Whether last parameter type is repeated. */
174 static inline bool HasRepeatParameters( OpCode eOp)
176 return eOp <= SC_OPCODE_LAST_OPCODE_ID
177 && pData[eOp].aData.bRepeatLast;
179 #endif // OSL_DEBUG_LEVEL
182 #endif // SC_PARCLASS_HXX