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;
286 if( !ks_error_div0.isError() )
288 return ks_error_div0;
294 if( !ks_error_na.isError() )
302 if( !ks_error_name.isError() )
304 return ks_error_name;
310 if( !ks_error_num.isError() )
318 if( !ks_error_null.isError() )
320 return ks_error_null;
326 if( !ks_error_ref.isError() )
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!
static const Value & errorNULL()
Returns constant reference to NULL!
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?
Value & assign(const Value &_value)
Assigns from another value.
static const Value & errorNUM()
Returns constant reference to NUM!
Type type() const
Returns the type of the value.
static const Value & errorREF()
Returns constant reference to REF!
double asFloat() const
Returns the floating-point value of this value.
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!
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.