kspread

kspread_value.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2003,2004 Ariya Hidayat <ariya@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef KSPREAD_VALUE_H
00021 #define KSPREAD_VALUE_H
00022 
00023 #include <qdatetime.h>
00024 #include <qstring.h>
00025 #include <qtextstream.h>
00026 
00027 #include <koffice_export.h>
00028 
00029 namespace KSpread
00030 {
00031 class ValueData;
00032 
00041 class KSPREAD_EXPORT Value
00042 {
00043 
00044   public:
00045 
00046     typedef enum {
00047       Empty,
00048       Boolean,
00049       Integer,
00050       Float,
00051       String,
00052       Array,
00053       CellRange, // not used yet
00054       Error
00055     } Type;
00056 
00057     typedef enum {
00058       fmt_None,
00059       fmt_Boolean,
00060       fmt_Number,
00061       fmt_Percent,
00062       fmt_Money,
00063       fmt_DateTime,
00064       fmt_Date,
00065       fmt_Time,
00066       fmt_String
00067     } Format;
00071     Value();
00072 
00076     Value( Type _type );
00077 
00081     virtual ~Value();
00082 
00086     Value( const Value& _value );
00087 
00094     Value& operator= ( const Value& _value );
00095 
00099     Value& assign( const Value& _value );
00100 
00104     Value( bool b );
00105 
00109     Value( long i );
00110 
00114     Value( int i );
00115 
00119     Value( double f );
00120 
00124     Value( const QString& s );
00125 
00126     Value (const char *s);
00133     Value( const QDateTime& dt );
00134 
00139     Value( const QTime& time );
00140 
00145     Value( const QDate& date );
00146 
00150     Value( unsigned columns, unsigned rows );
00151 
00155     Type type() const;
00156 
00158     Format format() const;
00159 
00163     bool isEmpty() const { return type() == Empty; }
00164 
00168     bool isBoolean() const { return type() == Boolean; }
00169 
00173     bool isInteger() const { return type() == Integer; }
00174 
00178     bool isFloat() const { return type() == Float; }
00179 
00184     bool isNumber() const { return (type() == Integer) || (type() == Float); }
00185 
00189     bool isString() const { return type() == String; }
00190 
00194     bool isArray() const { return type() == Array; }
00195 
00199     bool isError() const { return type() == Error; }
00200 
00204     void setValue( const Value& v );
00205 
00209     void setValue( bool b );
00210 
00214     void setValue( long i );
00215 
00219     void setValue( int i );
00220 
00224     void setValue( double f );
00225 
00229     void setValue( const QString& s );
00230 
00234     void setError( const QString& msg );
00235 
00239     void setValue( const QDateTime& dt );
00240 
00244     void setValue( const QTime& dt );
00245 
00249     void setValue( const QDate& dt );
00250 
00252     void setFormat (Format fmt);
00253 
00259     bool asBoolean() const;
00260 
00266     long asInteger() const;
00267 
00273     double asFloat() const;
00274 
00280     QString asString() const;
00281 
00285     QDateTime asDateTime() const;
00286 
00290     QDate asDate() const;
00291 
00295     QTime asTime() const;
00296 
00300     Value element( unsigned column, unsigned row ) const;
00301 
00305     void setElement( unsigned column, unsigned row, const Value& value );
00306 
00311     unsigned columns() const;
00312 
00317     unsigned rows() const;
00318 
00324     QString errorMessage() const;
00325 
00331     void detach();
00332 
00336     static const Value& empty();
00337 
00343     static const Value& errorDIV0();
00344 
00350     static const Value& errorNA();
00351 
00359     static const Value& errorNAME();
00360 
00366     static const Value& errorNUM();
00367 
00373     static const Value& errorNULL();
00374 
00380     static const Value& errorREF();
00381 
00388     static const Value& errorVALUE();
00389 
00394     bool allowComparison( const Value& v ) const;
00395     
00400     int compare( const Value& v ) const;
00401 
00405     bool equal( const Value& v ) const;
00406 
00410     bool less( const Value& v ) const;
00411 
00415     bool greater( const Value& v ) const;
00416 
00417     // comparison operator - returns true only if strictly identical, unlike equal()/compare()
00418     bool operator==( const Value& v ) const;
00419     inline bool operator!=( const Value& other ) const { return !operator==( other ); }
00420 
00421     static int compare( double v1, double v2 );
00422     
00423     bool isZero() const;
00424     
00425     static bool isZero( double v );
00426       
00427   protected:
00428 
00429     ValueData* d; // can't never be 0
00430 };
00431 
00432 } // namespace KSpread
00433 
00434 QTextStream& operator<<( QTextStream& ts, KSpread::Value::Type type );
00435 QTextStream& operator<<( QTextStream& ts, KSpread::Value value );
00436 
00437 #endif // KSPREAD_VALUE_H
KDE Home | KDE Accessibility Home | Description of Access Keys