Core: Value now allows RawToValue for svo types

git-svn-id: svn://ultimatepp.org/upp/trunk@10911 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2017-03-07 10:35:32 +00:00
parent c8ecec60df
commit 643d4f2434
3 changed files with 23 additions and 14 deletions

View file

@ -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<WString>::Extract(*this).ToString();
if(Is<String>())
return To<String>();
return To<WString>().ToString();
}
int Value::GetOtherInt() const

View file

@ -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 T>
class RawValueRep : public Value::Void {
public:
virtual dword GetType() const { return GetValueTypeNo<T>() + 0x10000000; }
virtual dword GetType() const { return GetValueTypeNo<T>(); }
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<const T*>(&data); // Only active when T is String
}
if(IsRef()) {
const RawValueRep<T> *x = dynamic_cast<const RawValueRep<T>*>(ptr());
if(x)
return x->Get();
}
else
if(t == STRING_V) {
ASSERT(IsString());
return *reinterpret_cast<const T*>(&data); // Only active when T is String
}
else
if(t < 255 && Is((byte)t))
return GetSmallRaw<T>();
throw ValueTypeError(String().Cat() << "Invalid value conversion: "
@ -256,16 +257,13 @@ template <class T>
inline bool Value::Is() const
{
dword t = GetValueTypeNo<T>();
if(t > 0x80000000)
return IsRef() && dynamic_cast<const RawValueRep<T> *>(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 <class T>
@ -365,6 +363,12 @@ inline Value RichToValue(const T& data)
return Value(new RichValueRep<T>(data));
}
template <>
inline Value RichToValue(const String& data)
{
return Value(data);
}
#ifdef DEPRECATED
template <class T> // use Value::Is
bool IsTypeRaw(const Value& value, T * = 0) { return value.Is<T>(); }

View file

@ -30,3 +30,6 @@ uses Core;
file<:?header:>
<:PACKAGE:>.h,<:.:>
<:PACKAGE:>.cpp;
mainconfig
"" = "";