formula.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef KSPREAD_FORMULA
00021 #define KSPREAD_FORMULA
00022
00023 #include <qstring.h>
00024 #include <qvaluevector.h>
00025
00026 #include "kspread_cell.h"
00027 #include "kspread_value.h"
00028
00029 class KLocale;
00030 class KSpreadCell;
00031
00032 namespace KSpread
00033 {
00034
00035 class Token
00036 {
00037 public:
00038 typedef enum
00039 {
00040 Unknown,
00041 Boolean,
00042 Integer,
00043 Float,
00044 String,
00045 Operator,
00046 Cell,
00047 Range,
00048 Identifier
00049 } Type;
00050
00051 typedef enum
00052 {
00053 InvalidOp = 0,
00054 Plus,
00055 Minus,
00056 Asterisk,
00057 Slash,
00058 Caret,
00059 LeftPar,
00060 RightPar,
00061 Comma,
00062 Semicolon,
00063 Ampersand,
00064 Equal,
00065 NotEqual,
00066 Less,
00067 Greater,
00068 LessEqual,
00069 GreaterEqual,
00070 Percent
00071 } Op;
00072
00076 Token( Type type = Unknown, const QString& text = QString::null, int pos = -1 );
00077
00078 static const Token null;
00079
00080 Token( const Token& );
00081 Token& operator=( const Token& );
00082
00086 Type type() const { return m_type; }
00087
00095 QString text() const { return m_text; }
00096
00097 int pos() const { return m_pos; };
00098
00102 bool isBoolean() const { return m_type == Boolean; }
00103
00107 bool isInteger() const { return m_type == Integer; }
00108
00112 bool isFloat() const { return m_type == Float; }
00113
00117 bool isNumber() const { return (m_type == Integer) || (m_type == Float); }
00118
00122 bool isString() const { return m_type == String; }
00123
00127 bool isOperator() const { return m_type == Operator; }
00128
00132 bool isCell() const { return m_type == Cell; }
00133
00137 bool isRange() const { return m_type == Range; }
00138
00142 bool isIdentifier() const { return m_type == Identifier; }
00143
00148 bool asBoolean() const;
00149
00154 int asInteger() const;
00155
00160 double asFloat() const;
00161
00171 QString asString() const;
00172
00177 Op asOperator() const;
00178
00191 QString sheetName() const;
00192
00197 QString description() const;
00198
00199 protected:
00200
00201 Type m_type;
00202 QString m_text;
00203 int m_pos;
00204
00205 };
00206
00207
00208
00209
00210
00211 class Tokens: public QValueVector<Token>
00212 {
00213 public:
00214 Tokens(): QValueVector<Token>(), m_valid(true) {};
00215 bool valid() const { return m_valid; }
00216 void setValid( bool v ){ m_valid = v; }
00217 protected:
00218 bool m_valid;
00219 };
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231 class Formula
00232 {
00233 public:
00234
00235
00236
00237
00238 Formula( KSpreadCell *cell );
00239
00240
00241
00242
00243
00244 Formula();
00245
00246
00247
00248
00249 ~Formula();
00250
00251
00252
00253
00254 KSpreadCell* cell();
00255
00256
00257
00258
00259 void setExpression( const QString& expr );
00260
00261
00262
00263
00264 QString expression() const;
00265
00266
00267
00268
00269 void clear();
00270
00271
00272
00273
00274
00275
00276 bool isValid() const;
00277
00278
00279
00280
00281
00282
00283
00284 Tokens tokens() const;
00285
00286
00287
00288
00289 KSpreadValue eval() const;
00290
00291
00292
00293
00294
00295
00296 static Tokens scan( const QString& expr, KLocale* locale = 0 );
00297
00298 QString dump() const;
00299
00300 protected:
00301
00302 void compile( const Tokens& tokens ) const;
00303
00304 private:
00305 class Private;
00306 Private *d;
00307
00308 Formula( const Formula& );
00309 Formula& operator=( const Formula& );
00310 };
00311
00315 QTextStream& operator<<( QTextStream& ts, Formula formula );
00316
00317
00318 }
00319
00320
00321
00322 #endif // KSPREAD_FORMULA
00323
This file is part of the documentation for kspread Library Version 1.4.2.