kspread

kspread_value.h
1/* This file is part of the KDE project
2 Copyright (C) 2003,2004 Ariya Hidayat <ariya@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#ifndef KSPREAD_VALUE_H
21#define KSPREAD_VALUE_H
22
23#include <tqdatetime.h>
24#include <tqstring.h>
25#include <tqtextstream.h>
26
27#include <koffice_export.h>
28
29namespace KSpread
30{
31class ValueData;
32
41class KSPREAD_EXPORT Value
42{
43
44 public:
45
46 typedef enum {
47 Empty,
48 Boolean,
49 Integer,
50 Float,
51 String,
52 Array,
53 CellRange, // not used yet
54 Error
55 } Type;
56
57 typedef enum {
58 fmt_None,
59 fmt_Boolean,
60 fmt_Number,
61 fmt_Percent,
62 fmt_Money,
63 fmt_DateTime,
64 fmt_Date,
65 fmt_Time,
66 fmt_String
67 } Format;
71 Value();
72
76 Value( Type _type );
77
81 virtual ~Value();
82
86 Value( const Value& _value );
87
94 Value& operator= ( const Value& _value );
95
99 Value& assign( const Value& _value );
100
104 Value( bool b );
105
109 Value( long i );
110
114 Value( int i );
115
119 Value( double f );
120
124 Value( const TQString& s );
125
126 Value (const char *s);
133 Value( const TQDateTime& dt );
134
139 Value( const TQTime& time );
140
145 Value( const TQDate& date );
146
150 Value( unsigned columns, unsigned rows );
151
155 Type type() const;
156
158 Format format() const;
159
163 bool isEmpty() const { return type() == Empty; }
164
168 bool isBoolean() const { return type() == Boolean; }
169
173 bool isInteger() const { return type() == Integer; }
174
178 bool isFloat() const { return type() == Float; }
179
184 bool isNumber() const { return (type() == Integer) || (type() == Float); }
185
189 bool isString() const { return type() == String; }
190
194 bool isArray() const { return type() == Array; }
195
199 bool isError() const { return type() == Error; }
200
204 void setValue( const Value& v );
205
209 void setValue( bool b );
210
214 void setValue( long i );
215
219 void setValue( int i );
220
224 void setValue( double f );
225
229 void setValue( const TQString& s );
230
234 void setError( const TQString& msg );
235
239 void setValue( const TQDateTime& dt );
240
244 void setValue( const TQTime& dt );
245
249 void setValue( const TQDate& dt );
250
252 void setFormat (Format fmt);
253
259 bool asBoolean() const;
260
266 long asInteger() const;
267
273 double asFloat() const;
274
280 TQString asString() const;
281
285 TQDateTime asDateTime() const;
286
290 TQDate asDate() const;
291
295 TQTime asTime() const;
296
300 Value element( unsigned column, unsigned row ) const;
301
305 void setElement( unsigned column, unsigned row, const Value& value );
306
311 unsigned columns() const;
312
317 unsigned rows() const;
318
324 TQString errorMessage() const;
325
331 void detach();
332
336 static const Value& empty();
337
343 static const Value& errorDIV0();
344
350 static const Value& errorNA();
351
359 static const Value& errorNAME();
360
366 static const Value& errorNUM();
367
373 static const Value& errorNULL();
374
380 static const Value& errorREF();
381
388 static const Value& errorVALUE();
389
394 bool allowComparison( const Value& v ) const;
395
400 int compare( const Value& v ) const;
401
405 bool equal( const Value& v ) const;
406
410 bool less( const Value& v ) const;
411
415 bool greater( const Value& v ) const;
416
417 // comparison operator - returns true only if strictly identical, unlike equal()/compare()
418 bool operator==( const Value& v ) const;
419 inline bool operator!=( const Value& other ) const { return !operator==( other ); }
420
421 static int compare( double v1, double v2 );
422
423 bool isZero() const;
424
425 static bool isZero( double v );
426
427 protected:
428
429 ValueData* d; // can't never be 0
430};
431
432} // namespace KSpread
433
434TQTextStream& operator<<( TQTextStream& ts, KSpread::Value::Type type );
435TQTextStream& operator<<( TQTextStream& ts, KSpread::Value value );
436
437#endif // KSPREAD_VALUE_H
Provides a wrapper for cell value.
bool isBoolean() const
Returns true if the type of this value is Boolean.
bool isEmpty() const
Returns true if empty.
bool isNumber() const
Returns true if the type of this value is either integer or floating-point.
bool isArray() const
Returns true if the type of this value is array.
bool isFloat() const
Returns true if the type of this value is floating-point.
bool isError() const
Returns true if this value holds error information.
bool isString() const
Returns true if the type of this value is string.
bool isInteger() const
Returns true if the type of this value is integer.
The KSpread namespace.
Definition commands.h:39