54 if(
this == s_null ) s_null = 0;
57 void ref(){ count++; }
60 static ValueData* null()
61 {
if( !s_null) s_null =
new ValueData;
else s_null->ref();
return s_null; }
65 { --count;
if( !count )
delete this; }
68 bool isNull(){
return this == s_null; }
74 static ValueData* s_null;
80using namespace Swinder;
83ValueData* ValueData::s_null = 0;
98 d = ValueData::null();
117 d = ValueData::null();
130 d = ValueData::null();
137 d = ValueData::null();
144 d = ValueData::null();
151 d = ValueData::null();
168 return d ? d->type : Empty;
172void Value::setValue(
bool b )
184 if(
type() == Value::Boolean )
191void Value::setValue(
int i )
203 if(
type() == Value::Integer )
206 if(
type() == Value::Float )
207 result =
static_cast<int>(d->f);
212void Value::setValue(
const Value& v )
218void Value::setValue(
double f )
230 if(
type() == Value::Float )
233 if(
type() == Value::Integer )
234 result =
static_cast<double>(d->i);
252 if(
type() == Value::String )
271 if(
type() == Value::Error )
280 return ks_value_empty;
288 return ks_error_div0;
304 return ks_error_name;
320 return ks_error_null;
334 if( !ks_error_value.
isError() )
336 return ks_error_value;
342 if( d->isNull() || ( d->count > 1 ) )
351 case Boolean: n->b = d->b;
break;
352 case Integer: n->i = d->i;
break;
353 case Float: n->f = d->f;
break;
354 case String: n->s = d->s;
break;
355 case Error: n->s = d->s;
break;
364std::ostream& Swinder::operator<<( std::ostream& s,
Swinder::Value value )
366 switch( value.
type() )
372 s <<
"Boolean: " << (value.
asBoolean()?
"True":
"False");
378 s <<
"Float: " << value.
asFloat();
char * ascii() const
Convert the Unicode string to plain ASCII chars chopping of any higher bytes.
static UString null
Static instance of a null string.
Provides a wrapper for cell value.
UString errorMessage() const
Returns error message associated with this value.
static const Value & empty()
Returns constant reference to empty value.
static const Value & errorDIV0()
Returns constant reference to #DIV/0! error.
static const Value & errorNULL()
Returns constant reference to NULL! error.
virtual ~Value()
Destroys the value.
void setError(const UString &msg)
Sets this value to hold error message.
static const Value & errorNAME()
Returns constant reference to #NAME? error.
Value & assign(const Value &_value)
Assigns from another value.
static const Value & errorNUM()
Returns constant reference to #NUM! error.
Type type() const
Returns the type of the value.
static const Value & errorREF()
Returns constant reference to #REF! error.
double asFloat() const
Returns the floating-point value of this value.
bool isError() const
Returns true if this value holds error information.
Value & operator=(const Value &_value)
Assigns from another value.
UString asString() const
Returns the string value of this value.
Value()
Creates an empty value, i.e holds nothing.
static const Value & errorVALUE()
Returns constant reference to #VALUE! error.
void detach()
Detaches itself from shared value data, i.e make a private, deep copy of the data.
bool asBoolean() const
Returns the boolean value of this value.
static const Value & errorNA()
Returns constant reference to #N/A error.
int asInteger() const
Returns the integer value of this value.