kspread

functions.h
1/* This file is part of the KDE project
2 Copyright (C) 2003,2004 Ariya Hidayat <ariya@kde.org>
3 Copyright (C) 2005 Tomas Mecir <mecirt@gmail.com>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21
22#ifndef KSPREAD_FUNCTIONS
23#define KSPREAD_FUNCTIONS
24
25#include <tqstringlist.h>
26#include <tqvaluevector.h>
27
28class TQDomElement;
29
30namespace KSpread
31{
32class Sheet;
33class Value;
34class ValueCalc;
35
36typedef TQValueVector<Value> valVector;
37
38struct rangeInfo {
39 int col1, col2, row1, row2;
40};
41struct FuncExtra {
42 // here we'll add all the extras a function may need
43 TQValueVector<rangeInfo> ranges;
44 Sheet *sheet;
45 int myrow, mycol;
46};
47
48typedef Value (*FunctionPtr)(valVector, ValueCalc *, FuncExtra *);
49
50class Function
51{
52public:
53 Function (const TQString& name, FunctionPtr ptr);
54 ~Function();
59 void setParamCount (int min, int max = 0);
61 bool paramCountOkay (int count);
65 void setAcceptArray (bool accept = true);
66 bool needsExtra ();
67 void setNeedsExtra (bool extra);
68 TQString name() const;
69 TQString localizedName() const;
70 TQString helpText() const;
71 void setHelpText( const TQString& text );
72 Value exec (valVector args, ValueCalc *calc, FuncExtra *extra = 0);
73
74private:
75 class Private;
76 Private* d;
77};
78
79enum ParameterType { KSpread_Int, KSpread_Float, KSpread_String, KSpread_Boolean, KSpread_Any };
80
81class FunctionParameter
82{
83public:
84 FunctionParameter();
85 FunctionParameter( const FunctionParameter& param );
86 FunctionParameter( const TQDomElement& element );
87
88 TQString helpText() const { return m_help; }
89 ParameterType type() const { return m_type; }
90 bool hasRange() const { return m_range; }
91
92private:
93 TQString m_help;
94 ParameterType m_type;
95 bool m_range;
96};
97
98class FunctionDescription
99{
100public:
101 FunctionDescription();
102 FunctionDescription (const TQDomElement& element);
103 FunctionDescription (const FunctionDescription& desc);
104
105 const TQStringList& examples() { return m_examples; }
106 const TQStringList& syntax() { return m_syntax; }
107 const TQStringList& related() { return m_related; }
108 const TQStringList& helpText() const { return m_help; }
109 TQString name() const { return m_name; }
110 ParameterType type() const { return m_type; }
111
112 int params() const { return m_params.count(); }
113 FunctionParameter& param( int i ) { return m_params[ i ]; }
114
115 void setGroup( const TQString& g ) { m_group = g; }
116 TQString group() const { return m_group; }
117
118 TQString toTQML() const;
119
120private:
121 TQString m_group;
122 TQStringList m_examples;
123 TQStringList m_syntax;
124 TQStringList m_related;
125 TQStringList m_help;
126 TQString m_name;
127 ParameterType m_type;
128 TQValueList<FunctionParameter> m_params;
129};
130
131class FunctionRepository
132{
133public:
134 FunctionRepository();
135 ~FunctionRepository();
136
137 static FunctionRepository *self();
138
139 void add (Function *function);
140
141 Function *function (const TQString& name);
142
143 FunctionDescription *functionInfo (const TQString& name);
144
146 TQStringList functionNames (const TQString& group = TQString());
147
148 const TQStringList &groups () const { return m_groups; }
149
150private:
151
152 class Private;
153 Private* d;
154
155 static FunctionRepository* s_self;
156
158 void loadFile (const TQString& filename);
159
160 TQStringList m_groups;
161
162 // no copy or assign
163 FunctionRepository( const FunctionRepository& );
164 FunctionRepository& operator=( const FunctionRepository& );
165};
166
167
168} // namespace KSpread
169
170
171#endif // KSPREAD_FUNCTIONS
The KSpread namespace.
Definition commands.h:39