*Core: SvoValue: fixed a couple of issues with Null

git-svn-id: svn://ultimatepp.org/upp/trunk@4681 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2012-03-11 12:24:20 +00:00
parent 2252928b93
commit 267ef3e3c6
8 changed files with 1980 additions and 1959 deletions

View file

@ -90,23 +90,41 @@ Color::Color(RGBA rgba)
void Color::Jsonize(JsonIO& jio)
{
int r = GetR();
int g = GetG();
int b = GetB();
int r, g, b;
if(IsNullInstance()) {
r = g = b = Null;
}
else {
r = GetR();
g = GetG();
b = GetB();
}
jio("red", r)("green", g)("blue", b);
if(IsNull(r))
*this = Null;
else
*this = Color(r, g, b);
}
void Color::Xmlize(XmlIO& xio)
{
int r = GetR();
int g = GetG();
int b = GetB();
int r, g, b;
if(IsNullInstance()) {
r = g = b = Null;
}
else {
r = GetR();
g = GetG();
b = GetB();
}
xio
.Attr("red", r)
.Attr("green", g)
.Attr("blue", b)
;
if(IsNull(r))
*this = Null;
else
*this = Color(r, g, b);
}

View file

@ -251,12 +251,15 @@ template<> void Jsonize(JsonIO& io, Date& var)
if(IsString(v)) {
String text = v;
if(text.GetCount() > 6) {
DDUMP(text);
Date d;
d.year = ScanInt(text.Left(4));
d.month = ScanInt(text.Mid(4, 2));
d.day = ScanInt(text.Mid(6));
if(var.IsValid()) {
DDUMP(d);
if(d.IsValid()) {
var = d;
DDUMP(var);
return;
}
}
@ -288,7 +291,7 @@ template<> void Jsonize(JsonIO& io, Time& var)
tm.hour = ScanInt(text.Mid(9, 2));
tm.minute = ScanInt(text.Mid(12, 2));
tm.second = ScanInt(text.Mid(15));
if(var.IsValid()) {
if(tm.IsValid()) {
var = tm;
return;
}

View file

@ -433,9 +433,9 @@ const Value& ValueArray::Get(int i) const {
return data->data[i];
}
template<>
String AsString(const ValueArray& v) {
return sAsString(v.Get());
String ValueArray::ToString() const
{
return sAsString(Get());
}
bool ValueMap::Data::IsNull() const {

View file

@ -32,7 +32,7 @@ void Value::RefRetain()
Value& Value::operator=(const Value& v) {
if(this == &v) return *this;
Free();
FreeRef();
data = v.data;
if(IsRef())
ptr()->Retain();

View file

@ -137,7 +137,8 @@ protected:
void InitRef(Void *p) { data.SetSpecial(REF); ptr() = p; }
void RefRelease();
void RefRetain();
void Free() { if(IsRef()) RefRelease(); }
void FreeRef() { if(IsRef()) RefRelease(); }
void Free() { FreeRef(); data.Clear(); }
void SetLarge(const Value& v);
template <class T>

View file

@ -28,7 +28,7 @@ Ref::Ref(Value& v) { ptr = &v; m = &Single< ValueRef >(); }
bool ValueArray::Data::IsNull() const
{
return this == &Single<ValueArray::NullData>();
return data.IsEmpty();
}
void ValueArray::Data::Serialize(Stream& s)

View file

@ -225,7 +225,7 @@ public:
ValueArray(const Value& src);
ValueArray(const Nuller&) { Init0(); }
bool IsNull() const { return data->IsNull(); }
bool IsNullInstance() const { return IsEmpty(); }
void Clear();
void SetCount(int n);
@ -249,14 +249,12 @@ public:
unsigned GetHashValue() const { return data->GetHashValue(); }
void Serialize(Stream& s);
void Jsonize(JsonIO& jio);
String ToString() const;
bool operator==(const ValueArray& v) const;
bool operator!=(const ValueArray& v) const { return !operator==(v); }
};
template<> inline unsigned GetHashValue(const ValueArray& v) { return v.GetHashValue(); }
template<> inline bool IsNull(const ValueArray& v) { return v.IsNull(); }
template<>
String AsString(const ValueArray& v);
@ -300,7 +298,7 @@ public:
ValueMap(const Value& src);
ValueMap(const Nuller&) { Init0(); }
bool IsNullInstance() const { return data->IsNull(); }
bool IsNullInstance() const { return IsEmpty(); }
void Clear();
int GetCount() const { return data->value.GetCount(); }

View file

@ -11,6 +11,7 @@ void Xmlize(XmlIO& xml, String& var)
var = xml->Node(i).GetText();
return;
}
var.Clear();
}
else {
for(int i = 0; i < xml->GetCount(); i++)