uppsrc: Null cleanup

git-svn-id: svn://ultimatepp.org/upp/trunk@3866 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2011-09-16 08:24:44 +00:00
parent 9b18b6c807
commit a40565c216
6 changed files with 48 additions and 50 deletions

View file

@ -331,6 +331,37 @@ public:
NoCopy() {}
};
const int INT_NULL = INT_MIN;
const int64 INT64_NULL = INT64_MIN;
const double DOUBLE_NULL = -1.0E+308;
const double DOUBLE_NULL_LIM = -1.0E+307;
class Nuller {
public:
operator int() const { return INT_NULL; }
operator int64() const { return INT64_NULL; }
operator double() const { return DOUBLE_NULL; }
operator bool() const { return false; }
Nuller() {}
};
#ifdef flagSO
static const Nuller Null;
#else
extern const Nuller Null;
#endif
template <class T> void SetNull(T& x) { x = Null; }
template <class T> bool IsNull(const T& x) { return x.IsNullInstance(); }
template<> inline bool IsNull(const int& i) { return i == INT_NULL; }
template<> inline bool IsNull(const int64& i) { return i == INT64_NULL; }
template<> inline bool IsNull(const double& r) { return r < DOUBLE_NULL_LIM; }
template<> inline bool IsNull(const bool& r ) { return false; }
#if defined(flagMT)
#if defined(PLATFORM_WIN32) && defined(COMPILER_GCC)
#define flagUSEMALLOC //MINGW does not support

View file

@ -391,8 +391,6 @@ public:
inline bool IsEmpty(const String& s) { return s.IsEmpty(); }
template <class T> bool IsNull(const T& x) { return x.IsNullInstance(); }
String FormatPtr(const void *p);
template <class T>

View file

@ -2,7 +2,7 @@ struct Uuid : AssignValueTypeNo<Uuid, 50, Moveable<Uuid> > {
dword a, b, c, d;
void Serialize(Stream& s);
bool IsNull() const { return a == 0 && b == 0 && c == 0 && d == 0; }
bool IsNullInstance() const { return a == 0 && b == 0 && c == 0 && d == 0; }
void SetNull() { a = b = c = d = 0; }
operator Value() const { return RichValue<Uuid>(*this); }
@ -31,9 +31,6 @@ inline bool operator!=(const Uuid& u, const Uuid& w) {
return !(u == w);
}
template<>
inline bool IsNull(const Uuid& id) { return id.IsNull(); }
template<>
inline String AsString(const Uuid& id) { return Format(id); }

View file

@ -37,32 +37,6 @@ public:
Id(const IdConst& cnst);
};
const int INT_NULL = INT_MIN;
const int64 INT64_NULL = INT64_MIN;
const double DOUBLE_NULL = -1.0E+308;
const double DOUBLE_NULL_LIM = -1.0E+307;
class Nuller {
public:
operator int() const { return INT_NULL; }
operator int64() const { return INT64_NULL; }
operator double() const { return DOUBLE_NULL; }
operator bool() const { return false; }
Nuller() {}
};
#ifdef flagSO
static const Nuller Null;
#else
extern const Nuller Null;
#endif
template<> inline bool IsNull(const int& i) { return i == INT_NULL; }
template<> inline bool IsNull(const int64& i) { return i == INT64_NULL; }
template<> inline bool IsNull(const double& r) { return r < DOUBLE_NULL_LIM; }
template<> inline bool IsNull(const bool& r ) { return false; }
template<> inline bool IsNull(const Date& d) { return d.year == -32768; }
template<> inline bool IsNull(const Time& t) { return t.year == -32768; }
@ -484,7 +458,7 @@ protected:
static const T& GetNull() {
static T *q;
ONCELOCK {
static T x(Null);
static T x; SetNull(x);
q = &x;
}
return *q;
@ -544,7 +518,7 @@ struct RichRef : public RawRef<T> {
virtual Value GetValue(const void *p) { return RichValue<T>(*(T *) p); }
virtual bool IsNull(const void *p) { return UPP::IsNull(*(T *) p); }
virtual void SetValue(void *p, const Value& v) { *(T *) p = T(v); }
virtual void SetNull(void *p) { *(T *) p = T(Null); }
virtual void SetNull(void *p) { UPP::SetNull(*(T *)p); }
};
class Ref : Moveable<Ref> {

View file

@ -175,11 +175,11 @@ public:
bool operator!=(Font f) const { return !operator==(f); }
dword GetHashValue() const { return CombineHash(v.width, v.flags, v.height, v.face); }
bool IsNull() const { return v.face == 0xffff; }
bool IsNullInstance() const { return v.face == 0xffff; }
void SetNull() { v.face = 0xffff; v.height = v.width = 0; v.flags = 0; }
Font() { v.height = v.width = 0; v.face = v.flags = 0; }
Font(int face, int height) { v.face = face; v.height = height; v.flags = 0; v.width = 0; }
Font(const Nuller&) { v.face = 0xffff; v.height = v.width = 0; v.flags = 0; }
Font(const Nuller&) { SetNull(); }
operator Value() const { return RichValue<Font>(*this); }
Font(const Value& q) { *this = RichValue<Font>::Extract(q); }
@ -188,6 +188,7 @@ public:
FontInfo Info() const;
};
//BW compatibility
class FontInfo {
Font font;
@ -225,12 +226,6 @@ struct ComposedGlyph {
bool Compose(Font fnt, int chr, ComposedGlyph& cs);
template<>
inline bool IsNull(const Font& f) { return f.IsNull(); }
template<>
inline unsigned GetHashValue(const Font& f) { return f.GetHashValue(); }
template<>
String AsString(const Font& f);
@ -375,6 +370,7 @@ public:
void Clear() { size = Null; data.Clear(); cmd.Clear(); }
void Serialize(Stream& s) { s % cmd % data % size; }
bool IsNullInstance() const { return cmd.IsEmpty(); }
void SetNull() { size = Null; }
bool operator==(const Painting& b) const { return cmd == b.cmd && data == b.data && size == b.size; }
unsigned GetHashValue() const { return CombineHash(cmd, data); }
String ToString() const { return "painting " + AsString(size); }
@ -382,8 +378,8 @@ public:
operator Value() const { return RichValue<Painting>(*this); }
Painting(const Value& q) { *this = RichValue<Painting>::Extract(q); }
Painting() { size = Null; }
Painting(const Nuller&) { size = Null; }
Painting() { SetNull(); }
Painting(const Nuller&) { SetNull(); }
};
enum {
@ -635,6 +631,8 @@ public:
void Serialize(Stream& s);
bool IsNullInstance() const { return data.IsEmpty(); }
void SetNull() { size = Null; }
bool operator==(const Drawing& b) const { return val == b.val && data == b.data && size == b.size; }
String ToString() const { return "drawing " + AsString(size); }
unsigned GetHashValue() const { return CombineHash(data, val); }
@ -642,8 +640,8 @@ public:
operator Value() const { return RichValue<Drawing>(*this); }
Drawing(const Value& src);
Drawing() { size = Null; }
Drawing(const Nuller&) { size = Null; }
Drawing() { SetNull(); }
Drawing(const Nuller&) { SetNull(); }
};
class DrawingDraw : public Draw {

View file

@ -156,14 +156,14 @@ int Font::GetHeight() const
}
String Font::GetFaceName() const {
if(IsNull()) return String();
if(IsNullInstance()) return String();
if(GetFace() == 0)
return "STDFONT";
return GetFaceName(GetFace());
}
dword Font::GetFaceInfo() const {
if(IsNull()) return 0;
if(IsNullInstance()) return 0;
return GetFaceInfo(GetFace());
}
@ -209,7 +209,7 @@ void Font::Serialize(Stream& s) {
s % name;
if(s.IsLoading()) {
FaceName(name);
if(IsNull())
if(IsNullInstance())
Face(COURIER);
}
}