value.h
1/* Swinder - Portable library for spreadsheet
2 Copyright (C) 2003 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, or (at your option) any later version.
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 SWINDER_VALUE_H
21#define SWINDER_VALUE_H
22
23#include <iostream>
24#include "ustring.h"
25
26namespace Swinder
27{
28
29class ValueData;
30
31
32
42class Value
43{
44
45 public:
46
47 typedef enum {
48 Empty,
49 Boolean,
50 Integer,
51 Float,
52 String,
53 CellRange, // not used yet
54 Array, // not used yet
55 Error
56 } Type;
57
61 Value();
62
66 Value( Type _type );
67
71 virtual ~Value();
72
76 Value( const Value& _value );
77
84 Value& operator= ( const Value& _value );
85
89 Value& assign( const Value& _value );
90
94 Value( bool b );
95
99 Value( int i );
100
104 Value( double f );
105
109 Value( const UString& s );
110
114 Type type() const;
115
119 bool isEmpty() const { return type() == Empty; }
120
124 bool isBoolean() const { return type() == Boolean; }
125
129 bool isInteger() const { return type() == Integer; }
130
134 bool isFloat() const { return type() == Float; }
135
140 bool isNumber() const { return (type() == Integer) || (type() == Float); }
141
145 bool isString() const { return type() == String; }
146
150 bool isError() const { return type() == Error; }
151
152 void setValue( const Value& v );
153
157 void setValue( bool b );
158
162 void setValue( int i );
163
167 void setValue( double f );
168
172 void setValue( const UString& s );
173
177 void setError( const UString& msg );
178
184 bool asBoolean() const;
185
191 int asInteger() const;
192
198 double asFloat() const;
199
205 UString asString() const;
206
212 UString errorMessage() const;
213
219 void detach();
220
224 static const Value& empty();
225
231 static const Value& errorDIV0();
232
238 static const Value& errorNA();
239
247 static const Value& errorNAME();
248
254 static const Value& errorNUM();
255
261 static const Value& errorNULL();
262
268 static const Value& errorREF();
269
276 static const Value& errorVALUE();
277
278 protected:
279
280 ValueData* d; // can't never be 0
281};
282
286std::ostream& operator<<( std::ostream& s, Value value );
287
288} // namespace Swinder
289
290#endif // SWINDER_VALUE_H
Provides a wrapper for cell value.
Definition value.h:43
bool isNumber() const
Returns true if the type of this value is either integer or floating-point.
Definition value.h:140
UString errorMessage() const
Returns error message associated with this value.
Definition value.cpp:267
static const Value & empty()
Returns constant reference to empty value.
Definition value.cpp:278
static const Value & errorDIV0()
Returns constant reference to #DIV/0! error.
Definition value.cpp:284
static const Value & errorNULL()
Returns constant reference to NULL! error.
Definition value.cpp:316
virtual ~Value()
Destroys the value.
Definition value.cpp:102
void setError(const UString &msg)
Sets this value to hold error message.
Definition value.cpp:259
static const Value & errorNAME()
Returns constant reference to #NAME? error.
Definition value.cpp:300
Value & assign(const Value &_value)
Assigns from another value.
Definition value.cpp:157
bool isInteger() const
Returns true if the type of this value is integer.
Definition value.h:129
static const Value & errorNUM()
Returns constant reference to #NUM! error.
Definition value.cpp:308
Type type() const
Returns the type of the value.
Definition value.cpp:166
static const Value & errorREF()
Returns constant reference to #REF! error.
Definition value.cpp:324
bool isBoolean() const
Returns true if the type of this value is Boolean.
Definition value.h:124
double asFloat() const
Returns the floating-point value of this value.
Definition value.cpp:226
bool isError() const
Returns true if this value holds error information.
Definition value.h:150
bool isFloat() const
Returns true if the type of this value is floating-point.
Definition value.h:134
Value & operator=(const Value &_value)
Assigns from another value.
Definition value.cpp:122
UString asString() const
Returns the string value of this value.
Definition value.cpp:248
Value()
Creates an empty value, i.e holds nothing.
Definition value.cpp:96
bool isString() const
Returns true if the type of this value is string.
Definition value.h:145
static const Value & errorVALUE()
Returns constant reference to #VALUE! error.
Definition value.cpp:332
void detach()
Detaches itself from shared value data, i.e make a private, deep copy of the data.
Definition value.cpp:340
bool asBoolean() const
Returns the boolean value of this value.
Definition value.cpp:180
static const Value & errorNA()
Returns constant reference to #N/A error.
Definition value.cpp:292
int asInteger() const
Returns the integer value of this value.
Definition value.cpp:199
bool isEmpty() const
Returns true if empty.
Definition value.h:119