This commit is contained in:
vczh
2021-10-31 05:04:06 -07:00
parent de69ab2254
commit fb43767139
2 changed files with 77 additions and 18 deletions
+1 -4
View File
@@ -2200,10 +2200,7 @@ Interfaces
virtual IEnumerator<T>* CreateEnumerator() const = 0; virtual IEnumerator<T>* CreateEnumerator() const = 0;
/// <summary>Get the underlying collection object.</summary> /// <summary>Get the underlying collection object.</summary>
/// <returns> /// <returns>The underlying collection object, could be nullptr.</returns>
/// The underlying collection object.
/// It could returns nullptr when <see cref="GetCollectionEntity"/> returns <see cref="CollectionEntity::Unknown"/>.
/// </returns>
virtual const Object* GetCollectionObject() const = 0; virtual const Object* GetCollectionObject() const = 0;
/// <summary>Get the associated collection reference.</summary> /// <summary>Get the associated collection reference.</summary>
+66 -4
View File
@@ -2957,6 +2957,10 @@ Collections
/// <returns>The enumerator.</returns> /// <returns>The enumerator.</returns>
virtual Ptr<IValueEnumerator> CreateEnumerator() = 0; virtual Ptr<IValueEnumerator> CreateEnumerator() = 0;
/// <summary>Get the underlying collection object, which is boxed to be this interface.</summary>
/// <returns>The underlying collection object, could be nullptr.</returns>
virtual const Object* GetCollectionObject() { return nullptr; }
/// <summary>Create an enumerable from another lazy list.</summary> /// <summary>Create an enumerable from another lazy list.</summary>
/// <returns>The created enumerable.</returns> /// <returns>The created enumerable.</returns>
/// <param name="values">The lazy list to wrap.</param> /// <param name="values">The lazy list to wrap.</param>
@@ -3377,6 +3381,10 @@ Collections
/// <returns>The reference to the value. It will crash if the key does not exist.</returns> /// <returns>The reference to the value. It will crash if the key does not exist.</returns>
/// <param name="key">The key to find.</param> /// <param name="key">The key to find.</param>
virtual Value Get(const Value& key) = 0; virtual Value Get(const Value& key) = 0;
/// <summary>Get the underlying collection object, which is boxed to be this interface.</summary>
/// <returns>The underlying collection object, could be nullptr.</returns>
virtual const Object* GetCollectionObject() { return nullptr; }
}; };
/// <summary> /// <summary>
@@ -5833,6 +5841,25 @@ Collection Wrappers
wrapperPointer->CreateEnumerator() wrapperPointer->CreateEnumerator()
); );
} }
const Object* GetCollectionObject()override
{
if constexpr (std::is_same_v<typename trait_helper::RemovePtr<T>::Type*, T>)
{
if (wrapperPointer->GetCollectionReference() == this)
{
return wrapperPointer;
}
else
{
return nullptr;
}
}
else
{
return nullptr;
}
}
}; };
template<typename T> template<typename T>
@@ -6029,6 +6056,25 @@ Collection Wrappers
ValueType result = wrapperPointer->Get(item); ValueType result = wrapperPointer->Get(item);
return BoxValue<ValueType>(result); return BoxValue<ValueType>(result);
} }
const Object* GetCollectionObject()override
{
if constexpr (std::is_same_v<typename trait_helper::RemovePtr<T>::Type*, T>)
{
if (wrapperPointer->GetCollectionReference() == this)
{
return wrapperPointer;
}
else
{
return nullptr;
}
}
else
{
return nullptr;
}
}
}; };
#define KEY_VALUE_TYPE typename ValueReadonlyDictionaryWrapper<T>::KeyValueType #define KEY_VALUE_TYPE typename ValueReadonlyDictionaryWrapper<T>::KeyValueType
@@ -6197,17 +6243,32 @@ Containers
return BoxValue(result, td); return BoxValue(result, td);
} }
template<typename TCollection, typename TValueItf> template<typename T, typename TValueItf>
Unboxed<TCollection> UnboxCollection(const Ptr<TValueItf>& colref) Unboxed<T> UnboxCollection(const Ptr<TValueItf>& colref)
{
using TCollection = std::remove_const_t<T>;
if (auto colobj = dynamic_cast<TCollection*>(const_cast<Object*>(colref->GetCollectionObject())))
{
return { colobj,false };
}
else
{ {
auto collection = new TCollection(); auto collection = new TCollection();
auto lazyList = GetLazyList<typename TCollection::ElementType>(colref); auto lazyList = GetLazyList<typename TCollection::ElementType>(colref);
collections::CopyFrom(*collection, lazyList); collections::CopyFrom(*collection, lazyList);
return { collection, true }; return { collection, true };
} }
}
template<typename TCollection, typename TValueItf> template<typename T, typename TValueItf>
Unboxed<TCollection> UnboxDictionary(const Ptr<TValueItf>& colref) Unboxed<T> UnboxDictionary(const Ptr<TValueItf>& colref)
{
using TCollection = std::remove_const_t<T>;
if (auto colobj = dynamic_cast<TCollection*>(const_cast<Object*>(colref->GetCollectionObject())))
{
return { colobj,false };
}
else
{ {
auto collection = new TCollection(); auto collection = new TCollection();
auto lazyList = GetLazyList< auto lazyList = GetLazyList<
@@ -6217,6 +6278,7 @@ Containers
collections::CopyFrom(*collection, lazyList); collections::CopyFrom(*collection, lazyList);
return { collection, true }; return { collection, true };
} }
}
template<typename T> template<typename T>
struct ParameterAccessor<const collections::LazyList<T>, TypeFlags::EnumerableType> struct ParameterAccessor<const collections::LazyList<T>, TypeFlags::EnumerableType>