diff --git a/uppsrc/Core/Value.cpp b/uppsrc/Core/Value.cpp index 174c932e5..dd4f553d5 100644 --- a/uppsrc/Core/Value.cpp +++ b/uppsrc/Core/Value.cpp @@ -22,7 +22,7 @@ unsigned Value::GetOtherHashValue() const { void Value::RefRelease() { - ASSERT(ptr()->GetType() >= 255 || !svo[ptr()->GetType()]); // Check that svo type is not registered as Ref + ASSERT(IsRef()); // Check that svo type is not registered as Ref ptr()->Release(); } @@ -169,7 +169,9 @@ Time Value::GetOtherTime() const String Value::GetOtherString() const { if(IsNull()) return Null; - return RichValue::Extract(*this).ToString(); + if(Is()) + return To(); + return To().ToString(); } int Value::GetOtherInt() const diff --git a/uppsrc/Core/Value.hpp b/uppsrc/Core/Value.hpp index 80d42fe69..1d32ffb9f 100644 --- a/uppsrc/Core/Value.hpp +++ b/uppsrc/Core/Value.hpp @@ -6,7 +6,7 @@ Value::Value(const Value& v) SetLarge(v); else data.SetSmall(v.data); - Magic(); + Magic(); } template<> @@ -118,7 +118,7 @@ inline unsigned ValueGetHashValue(const WString& x) { template class RawValueRep : public Value::Void { public: - virtual dword GetType() const { return GetValueTypeNo() + 0x10000000; } + virtual dword GetType() const { return GetValueTypeNo(); } virtual bool IsNull() const { return false; } T v; @@ -235,16 +235,17 @@ inline const T& Value::To() const return *(T*)this; // Illegal, but works -> better than crash in release mode } #endif - if(t == STRING_V) { - ASSERT(IsString()); - return *reinterpret_cast(&data); // Only active when T is String - } if(IsRef()) { const RawValueRep *x = dynamic_cast*>(ptr()); if(x) return x->Get(); } else + if(t == STRING_V) { + ASSERT(IsString()); + return *reinterpret_cast(&data); // Only active when T is String + } + else if(t < 255 && Is((byte)t)) return GetSmallRaw(); throw ValueTypeError(String().Cat() << "Invalid value conversion: " @@ -256,16 +257,13 @@ template inline bool Value::Is() const { dword t = GetValueTypeNo(); - if(t > 0x80000000) - return IsRef() && dynamic_cast *>(ptr()); + if(IsRef() && ptr()->GetType() == t) + return true; if(t == STRING_V) return IsString(); if(t == VOID_V) return IsVoid(); - if(t == INT_V || t == INT64_V || t == DOUBLE_V || t == BOOL_V || - t == DATE_V || t == TIME_V) - return Is((byte)t); - return t < 255 && Is((byte)t) || IsRef() && ptr()->GetType() == t; + return t < 255 && Is((byte)t); } template @@ -365,6 +363,12 @@ inline Value RichToValue(const T& data) return Value(new RichValueRep(data)); } +template <> +inline Value RichToValue(const String& data) +{ + return Value(data); +} + #ifdef DEPRECATED template // use Value::Is bool IsTypeRaw(const Value& value, T * = 0) { return value.Is(); } diff --git a/uppsrc/Core/core.upt b/uppsrc/Core/core.upt index 5adf512a0..a32df36a6 100644 --- a/uppsrc/Core/core.upt +++ b/uppsrc/Core/core.upt @@ -30,3 +30,6 @@ uses Core; file<:?header:> <:PACKAGE:>.h,<:.:> <:PACKAGE:>.cpp; + +mainconfig + "" = "";