mirror of
https://github.com/vczh-libraries/Release.git
synced 2026-06-04 05:43:01 +08:00
...
This commit is contained in:
+1
-4
@@ -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>
|
||||||
|
|||||||
+76
-14
@@ -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,25 +6243,41 @@ 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)
|
||||||
{
|
{
|
||||||
auto collection = new TCollection();
|
using TCollection = std::remove_const_t<T>;
|
||||||
auto lazyList = GetLazyList<typename TCollection::ElementType>(colref);
|
if (auto colobj = dynamic_cast<TCollection*>(const_cast<Object*>(colref->GetCollectionObject())))
|
||||||
collections::CopyFrom(*collection, lazyList);
|
{
|
||||||
return { collection, true };
|
return { colobj,false };
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto collection = new TCollection();
|
||||||
|
auto lazyList = GetLazyList<typename TCollection::ElementType>(colref);
|
||||||
|
collections::CopyFrom(*collection, lazyList);
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
auto collection = new TCollection();
|
using TCollection = std::remove_const_t<T>;
|
||||||
auto lazyList = GetLazyList<
|
if (auto colobj = dynamic_cast<TCollection*>(const_cast<Object*>(colref->GetCollectionObject())))
|
||||||
typename TCollection::KeyContainer::ElementType,
|
{
|
||||||
typename TCollection::ValueContainer::ElementType
|
return { colobj,false };
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto collection = new TCollection();
|
||||||
|
auto lazyList = GetLazyList<
|
||||||
|
typename TCollection::KeyContainer::ElementType,
|
||||||
|
typename TCollection::ValueContainer::ElementType
|
||||||
>(colref);
|
>(colref);
|
||||||
collections::CopyFrom(*collection, lazyList);
|
collections::CopyFrom(*collection, lazyList);
|
||||||
return { collection, true };
|
return { collection, true };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|||||||
Reference in New Issue
Block a user