diff --git a/uppsrc/Core/Defs.h b/uppsrc/Core/Defs.h index 70278b863..b120669c7 100644 --- a/uppsrc/Core/Defs.h +++ b/uppsrc/Core/Defs.h @@ -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 void SetNull(T& x) { x = Null; } + +template 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 diff --git a/uppsrc/Core/String.h b/uppsrc/Core/String.h index 3ebbf621b..4abb99487 100644 --- a/uppsrc/Core/String.h +++ b/uppsrc/Core/String.h @@ -391,8 +391,6 @@ public: inline bool IsEmpty(const String& s) { return s.IsEmpty(); } -template bool IsNull(const T& x) { return x.IsNullInstance(); } - String FormatPtr(const void *p); template diff --git a/uppsrc/Core/Uuid.h b/uppsrc/Core/Uuid.h index b61d7d4ec..1efb08543 100644 --- a/uppsrc/Core/Uuid.h +++ b/uppsrc/Core/Uuid.h @@ -2,7 +2,7 @@ struct Uuid : AssignValueTypeNo > { 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(*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); } diff --git a/uppsrc/Core/Value.h b/uppsrc/Core/Value.h index 969daeb39..c6c919059 100644 --- a/uppsrc/Core/Value.h +++ b/uppsrc/Core/Value.h @@ -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 { virtual Value GetValue(const void *p) { return RichValue(*(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 { diff --git a/uppsrc/Draw/Draw.h b/uppsrc/Draw/Draw.h index 0f30d62e6..cd9e69ddb 100644 --- a/uppsrc/Draw/Draw.h +++ b/uppsrc/Draw/Draw.h @@ -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(*this); } Font(const Value& q) { *this = RichValue::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(*this); } Painting(const Value& q) { *this = RichValue::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(*this); } Drawing(const Value& src); - Drawing() { size = Null; } - Drawing(const Nuller&) { size = Null; } + Drawing() { SetNull(); } + Drawing(const Nuller&) { SetNull(); } }; class DrawingDraw : public Draw { diff --git a/uppsrc/Draw/Font.cpp b/uppsrc/Draw/Font.cpp index ae215184a..5ad34bb4b 100644 --- a/uppsrc/Draw/Font.cpp +++ b/uppsrc/Draw/Font.cpp @@ -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); } }