16template <VARTYPE ElementVartype>
17int CompareAgainstSafearray(
const std::vector<ScopedVariant>& vector,
18 const ScopedSafearray& safearray,
20 std::optional<ScopedSafearray::LockScope<ElementVartype>> lock_scope =
21 safearray.CreateLockScope<ElementVartype>();
31 V_VT(&non_owning_temp) = ElementVartype;
33 auto vector_iter = vector.begin();
34 auto scope_iter = lock_scope->begin();
35 for (; vector_iter != vector.end() && scope_iter != lock_scope->end();
36 ++vector_iter, ++scope_iter) {
39 int compare_result = vector_iter->Compare(non_owning_temp, ignore_case);
42 return compare_result;
46 if (vector_iter != vector.end())
50 if (scope_iter != lock_scope->end())
60 : vartype_(
std::exchange(other.vartype_, VT_EMPTY)),
61 vector_(
std::move(other.vector_)) {}
65 vartype_ = std::exchange(other.vartype_, VT_EMPTY);
66 vector_ = std::move(other.vector_);
92 scoped_variant = std::move(vector_[0]);
96 return scoped_variant.
Release();
106 scoped_variant.
Set(CreateAndPopulateSafearray<VT_BOOL>());
109 scoped_variant.
Set(CreateAndPopulateSafearray<VT_I1>());
112 scoped_variant.
Set(CreateAndPopulateSafearray<VT_UI1>());
115 scoped_variant.
Set(CreateAndPopulateSafearray<VT_I2>());
118 scoped_variant.
Set(CreateAndPopulateSafearray<VT_UI2>());
121 scoped_variant.
Set(CreateAndPopulateSafearray<VT_I4>());
124 scoped_variant.
Set(CreateAndPopulateSafearray<VT_UI4>());
127 scoped_variant.
Set(CreateAndPopulateSafearray<VT_I8>());
130 scoped_variant.
Set(CreateAndPopulateSafearray<VT_UI8>());
133 scoped_variant.
Set(CreateAndPopulateSafearray<VT_R4>());
136 scoped_variant.
Set(CreateAndPopulateSafearray<VT_R8>());
139 scoped_variant.
Set(CreateAndPopulateSafearray<VT_DATE>());
142 scoped_variant.
Set(CreateAndPopulateSafearray<VT_BSTR>());
145 scoped_variant.
Set(CreateAndPopulateSafearray<VT_DISPATCH>());
148 scoped_variant.
Set(CreateAndPopulateSafearray<VT_UNKNOWN>());
168 return scoped_variant.
Release();
173 if (
Type() != (V_VT(&other) & VT_TYPEMASK))
174 return (
Type() < (V_VT(&other) & VT_TYPEMASK)) ? (-1) : 1;
177 if (
Type() == VT_EMPTY)
180 int compare_result = 0;
181 if (V_ISARRAY(&other)) {
182 compare_result =
Compare(V_ARRAY(&other), ignore_case);
184 compare_result = vector_[0].Compare(other, ignore_case);
187 if (!compare_result &&
Size() > 1)
190 return compare_result;
196 return (
Type() < other.
Type()) ? (-1) : 1;
199 if (
Type() == VT_EMPTY)
202 auto iter1 = vector_.begin();
203 auto iter2 = other.vector_.begin();
204 for (; (iter1 != vector_.end()) && (iter2 != other.vector_.end());
206 int compare_result = iter1->Compare(*iter2, ignore_case);
208 return compare_result;
211 if (iter1 != vector_.end())
214 if (iter2 != other.vector_.end())
220 VARTYPE safearray_vartype;
223 if (
FAILED(SafeArrayGetVartype(safearray, &safearray_vartype)))
227 if (
Type() != safearray_vartype)
228 return (
Type() < safearray_vartype) ? (-1) : 1;
231 int compare_result = 0;
234 compare_result = CompareAgainstSafearray<VT_BOOL>(
235 vector_, scoped_safearray, ignore_case);
238 compare_result = CompareAgainstSafearray<VT_I1>(vector_, scoped_safearray,
242 compare_result = CompareAgainstSafearray<VT_UI1>(
243 vector_, scoped_safearray, ignore_case);
246 compare_result = CompareAgainstSafearray<VT_I2>(vector_, scoped_safearray,
250 compare_result = CompareAgainstSafearray<VT_UI2>(
251 vector_, scoped_safearray, ignore_case);
254 compare_result = CompareAgainstSafearray<VT_I4>(vector_, scoped_safearray,
258 compare_result = CompareAgainstSafearray<VT_UI4>(
259 vector_, scoped_safearray, ignore_case);
262 compare_result = CompareAgainstSafearray<VT_I8>(vector_, scoped_safearray,
266 compare_result = CompareAgainstSafearray<VT_UI8>(
267 vector_, scoped_safearray, ignore_case);
270 compare_result = CompareAgainstSafearray<VT_R4>(vector_, scoped_safearray,
274 compare_result = CompareAgainstSafearray<VT_R8>(vector_, scoped_safearray,
278 compare_result = CompareAgainstSafearray<VT_DATE>(
279 vector_, scoped_safearray, ignore_case);
282 compare_result = CompareAgainstSafearray<VT_BSTR>(
283 vector_, scoped_safearray, ignore_case);
286 compare_result = CompareAgainstSafearray<VT_DISPATCH>(
287 vector_, scoped_safearray, ignore_case);
290 compare_result = CompareAgainstSafearray<VT_UNKNOWN>(
291 vector_, scoped_safearray, ignore_case);
311 return compare_result;
314template <VARTYPE ElementVartype>
315SAFEARRAY* VariantVector::CreateAndPopulateSafearray() {
319 SafeArrayCreateVector(ElementVartype, 0,
Size()));
320 if (!scoped_safearray.Get()) {
321 constexpr size_t kElementSize =
326 std::optional<ScopedSafearray::LockScope<ElementVartype>> lock_scope =
327 scoped_safearray.CreateLockScope<ElementVartype>();
330 for (
size_t i = 0;
i <
Size(); ++
i) {
331 VARIANT element = vector_[
i].Release();
336 return scoped_safearray.Release();
void Set(const wchar_t *str)
VARIANT ReleaseAsSafearrayVariant()
bool operator==(const VariantVector &other) const
VariantVector & operator=(VariantVector &&other)
int Compare(const VARIANT &other, bool ignore_case=false) const
VARIANT ReleaseAsScalarVariant()
bool operator!=(const VariantVector &other) const
typename VartypeToNativeType< ElementVartype >::Type Type
static void RawSet(VARIANT *var, Type value)
static Type RawGet(const VARIANT &var)
#define BASE_DCHECK(condition)
#define BASE_UNREACHABLE()