filters
value.h
00001 /* Swinder - Portable library for spreadsheet 00002 Copyright (C) 2003 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, or (at your option) any later version. 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 SWINDER_VALUE_H 00021 #define SWINDER_VALUE_H 00022 00023 #include <iostream> 00024 #include "ustring.h" 00025 00026 namespace Swinder 00027 { 00028 00029 class ValueData; 00030 00031 00032 00042 class Value 00043 { 00044 00045 public: 00046 00047 typedef enum { 00048 Empty, 00049 Boolean, 00050 Integer, 00051 Float, 00052 String, 00053 CellRange, // not used yet 00054 Array, // not used yet 00055 Error 00056 } Type; 00057 00061 Value(); 00062 00066 Value( Type _type ); 00067 00071 virtual ~Value(); 00072 00076 Value( const Value& _value ); 00077 00084 Value& operator= ( const Value& _value ); 00085 00089 Value& assign( const Value& _value ); 00090 00094 Value( bool b ); 00095 00099 Value( int i ); 00100 00104 Value( double f ); 00105 00109 Value( const UString& s ); 00110 00114 Type type() const; 00115 00119 bool isEmpty() const { return type() == Empty; } 00120 00124 bool isBoolean() const { return type() == Boolean; } 00125 00129 bool isInteger() const { return type() == Integer; } 00130 00134 bool isFloat() const { return type() == Float; } 00135 00140 bool isNumber() const { return (type() == Integer) || (type() == Float); } 00141 00145 bool isString() const { return type() == String; } 00146 00150 bool isError() const { return type() == Error; } 00151 00152 void setValue( const Value& v ); 00153 00157 void setValue( bool b ); 00158 00162 void setValue( int i ); 00163 00167 void setValue( double f ); 00168 00172 void setValue( const UString& s ); 00173 00177 void setError( const UString& msg ); 00178 00184 bool asBoolean() const; 00185 00191 int asInteger() const; 00192 00198 double asFloat() const; 00199 00205 UString asString() const; 00206 00212 UString errorMessage() const; 00213 00219 void detach(); 00220 00224 static const Value& empty(); 00225 00231 static const Value& errorDIV0(); 00232 00238 static const Value& errorNA(); 00239 00247 static const Value& errorNAME(); 00248 00254 static const Value& errorNUM(); 00255 00261 static const Value& errorNULL(); 00262 00268 static const Value& errorREF(); 00269 00276 static const Value& errorVALUE(); 00277 00278 protected: 00279 00280 ValueData* d; // can't never be 0 00281 }; 00282 00286 std::ostream& operator<<( std::ostream& s, Value value ); 00287 00288 } // namespace Swinder 00289 00290 #endif // SWINDER_VALUE_H