Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
base::win::VariantVector Class Referencefinal

#include <variant_vector.h>

Public Member Functions

 VariantVector ()
 
 VariantVector (VariantVector &&other)
 
VariantVectoroperator= (VariantVector &&other)
 
 VariantVector (const VariantVector &)=delete
 
VariantVectoroperator= (const VariantVector &)=delete
 
 ~VariantVector ()
 
bool operator== (const VariantVector &other) const
 
bool operator!= (const VariantVector &other) const
 
VARTYPE Type () const
 
size_t Size () const
 
bool Empty () const
 
void Reset ()
 
template<VARTYPE ExpectedVartype, std::enable_if_t< ExpectedVartype !=VT_BOOL, int > = 0>
void Insert (typename internal::VariantUtil< ExpectedVartype >::Type value)
 
template<VARTYPE ExpectedVartype, std::enable_if_t< ExpectedVartype==VT_BOOL, int > = 0>
void Insert (bool value)
 
template<>
void Insert (typename internal::VariantUtil< VT_DATE >::Type value)
 
VARIANT ReleaseAsScalarVariant ()
 
VARIANT ReleaseAsSafearrayVariant ()
 
int Compare (const VARIANT &other, bool ignore_case=false) const
 
int Compare (SAFEARRAY *safearray, bool ignore_case=false) const
 
int Compare (const VariantVector &other, bool ignore_case=false) const
 

Detailed Description

Definition at line 32 of file variant_vector.h.

Constructor & Destructor Documentation

◆ VariantVector() [1/3]

base::win::VariantVector::VariantVector ( )
default

◆ VariantVector() [2/3]

base::win::VariantVector::VariantVector ( VariantVector &&  other)

Definition at line 59 of file variant_vector.cc.

60 : vartype_(std::exchange(other.vartype_, VT_EMPTY)),
61 vector_(std::move(other.vector_)) {}

◆ VariantVector() [3/3]

base::win::VariantVector::VariantVector ( const VariantVector )
delete

◆ ~VariantVector()

base::win::VariantVector::~VariantVector ( )

Definition at line 70 of file variant_vector.cc.

70 {
71 Reset();
72}

Member Function Documentation

◆ Compare() [1/3]

int base::win::VariantVector::Compare ( const VARIANT &  other,
bool  ignore_case = false 
) const

Definition at line 171 of file variant_vector.cc.

171 {
172 // If the element variant types are different, compare against the types.
173 if (Type() != (V_VT(&other) & VT_TYPEMASK))
174 return (Type() < (V_VT(&other) & VT_TYPEMASK)) ? (-1) : 1;
175
176 // Both have an empty variant type so they are the same.
177 if (Type() == VT_EMPTY)
178 return 0;
179
180 int compare_result = 0;
181 if (V_ISARRAY(&other)) {
182 compare_result = Compare(V_ARRAY(&other), ignore_case);
183 } else {
184 compare_result = vector_[0].Compare(other, ignore_case);
185 // If the first element is equal to |other|, and |vector_|
186 // has more than one element, then |vector_| is greater.
187 if (!compare_result && Size() > 1)
188 compare_result = 1;
189 }
190 return compare_result;
191}
int Compare(const VARIANT &other, bool ignore_case=false) const

◆ Compare() [2/3]

int base::win::VariantVector::Compare ( const VariantVector other,
bool  ignore_case = false 
) const

Definition at line 193 of file variant_vector.cc.

193 {
194 // If the element variant types are different, compare against the types.
195 if (Type() != other.Type())
196 return (Type() < other.Type()) ? (-1) : 1;
197
198 // Both have an empty variant type so they are the same.
199 if (Type() == VT_EMPTY)
200 return 0;
201
202 auto iter1 = vector_.begin();
203 auto iter2 = other.vector_.begin();
204 for (; (iter1 != vector_.end()) && (iter2 != other.vector_.end());
205 ++iter1, ++iter2) {
206 int compare_result = iter1->Compare(*iter2, ignore_case);
207 if (compare_result)
208 return compare_result;
209 }
210 // There are more elements in |this|, so |this| is greater than |other|.
211 if (iter1 != vector_.end())
212 return 1;
213 // There are more elements in |other|, so |this| is less than |other|.
214 if (iter2 != other.vector_.end())
215 return -1;
216 return 0;
217}

◆ Compare() [3/3]

int base::win::VariantVector::Compare ( SAFEARRAY *  safearray,
bool  ignore_case = false 
) const

Definition at line 219 of file variant_vector.cc.

219 {
220 VARTYPE safearray_vartype;
221 // If we fail to get the element variant type for the SAFEARRAY, then
222 // arbitrarily treat |this| as greater.
223 if (FAILED(SafeArrayGetVartype(safearray, &safearray_vartype)))
224 return 1;
225
226 // If the element variant types are different, compare against the types.
227 if (Type() != safearray_vartype)
228 return (Type() < safearray_vartype) ? (-1) : 1;
229
230 ScopedSafearray scoped_safearray(safearray);
231 int compare_result = 0;
232 switch (Type()) {
233 case VT_BOOL:
234 compare_result = CompareAgainstSafearray<VT_BOOL>(
235 vector_, scoped_safearray, ignore_case);
236 break;
237 case VT_I1:
238 compare_result = CompareAgainstSafearray<VT_I1>(vector_, scoped_safearray,
239 ignore_case);
240 break;
241 case VT_UI1:
242 compare_result = CompareAgainstSafearray<VT_UI1>(
243 vector_, scoped_safearray, ignore_case);
244 break;
245 case VT_I2:
246 compare_result = CompareAgainstSafearray<VT_I2>(vector_, scoped_safearray,
247 ignore_case);
248 break;
249 case VT_UI2:
250 compare_result = CompareAgainstSafearray<VT_UI2>(
251 vector_, scoped_safearray, ignore_case);
252 break;
253 case VT_I4:
254 compare_result = CompareAgainstSafearray<VT_I4>(vector_, scoped_safearray,
255 ignore_case);
256 break;
257 case VT_UI4:
258 compare_result = CompareAgainstSafearray<VT_UI4>(
259 vector_, scoped_safearray, ignore_case);
260 break;
261 case VT_I8:
262 compare_result = CompareAgainstSafearray<VT_I8>(vector_, scoped_safearray,
263 ignore_case);
264 break;
265 case VT_UI8:
266 compare_result = CompareAgainstSafearray<VT_UI8>(
267 vector_, scoped_safearray, ignore_case);
268 break;
269 case VT_R4:
270 compare_result = CompareAgainstSafearray<VT_R4>(vector_, scoped_safearray,
271 ignore_case);
272 break;
273 case VT_R8:
274 compare_result = CompareAgainstSafearray<VT_R8>(vector_, scoped_safearray,
275 ignore_case);
276 break;
277 case VT_DATE:
278 compare_result = CompareAgainstSafearray<VT_DATE>(
279 vector_, scoped_safearray, ignore_case);
280 break;
281 case VT_BSTR:
282 compare_result = CompareAgainstSafearray<VT_BSTR>(
283 vector_, scoped_safearray, ignore_case);
284 break;
285 case VT_DISPATCH:
286 compare_result = CompareAgainstSafearray<VT_DISPATCH>(
287 vector_, scoped_safearray, ignore_case);
288 break;
289 case VT_UNKNOWN:
290 compare_result = CompareAgainstSafearray<VT_UNKNOWN>(
291 vector_, scoped_safearray, ignore_case);
292 break;
293 // The default case shouldn't be reachable, but if we added support for more
294 // VARTYPEs to base::win::internal::VariantUtil<> and they were inserted
295 // into a VariantVector then it would be possible to reach the default case
296 // for those new types until implemented.
297 //
298 // Because the switch is against VARTYPE (unsigned short) and not VARENUM,
299 // removing the default case will not result in build warnings/errors if
300 // there are missing cases. It is important that this uses VARTYPE rather
301 // than VARENUM, because in the future we may want to support complex
302 // VARTYPES. For example a value within VT_TYPEMASK that's joined something
303 // outside the typemask like VT_ARRAY or VT_BYREF.
304 default:
305 compare_result = 1;
307 break;
308 }
309
310 scoped_safearray.Release();
311 return compare_result;
312}
#define BASE_UNREACHABLE()
Definition logging.h:69
#define FAILED(hr)

◆ Empty()

bool base::win::VariantVector::Empty ( ) const
inline

Definition at line 51 of file variant_vector.h.

51{ return vector_.empty(); }

◆ Insert() [1/3]

template<VARTYPE ExpectedVartype, std::enable_if_t< ExpectedVartype==VT_BOOL, int > = 0>
void base::win::VariantVector::Insert ( bool  value)
inline

Definition at line 73 of file variant_vector.h.

73 {
74 if (vartype_ == VT_EMPTY)
75 vartype_ = ExpectedVartype;
76 AssertVartype<ExpectedVartype>();
77 ScopedVariant scoped_variant;
78 scoped_variant.Set(value);
79 vector_.push_back(std::move(scoped_variant));
80 }

◆ Insert() [2/3]

template<VARTYPE ExpectedVartype, std::enable_if_t< ExpectedVartype !=VT_BOOL, int > = 0>
void base::win::VariantVector::Insert ( typename internal::VariantUtil< ExpectedVartype >::Type  value)
inline

Definition at line 60 of file variant_vector.h.

60 {
61 if (vartype_ == VT_EMPTY)
62 vartype_ = ExpectedVartype;
63 AssertVartype<ExpectedVartype>();
64 ScopedVariant scoped_variant;
65 scoped_variant.Set(value);
66 vector_.push_back(std::move(scoped_variant));
67 }

◆ Insert() [3/3]

template<>
void base::win::VariantVector::Insert ( typename internal::VariantUtil< VT_DATE >::Type  value)
inline

Definition at line 85 of file variant_vector.h.

85 {
86 if (vartype_ == VT_EMPTY)
87 vartype_ = VT_DATE;
88 AssertVartype<VT_DATE>();
89 ScopedVariant scoped_variant;
90 scoped_variant.SetDate(value);
91 vector_.push_back(std::move(scoped_variant));
92 }

◆ operator!=()

bool base::win::VariantVector::operator!= ( const VariantVector other) const

Definition at line 78 of file variant_vector.cc.

78 {
79 return !VariantVector::operator==(other);
80}
bool operator==(const VariantVector &other) const

◆ operator=() [1/2]

VariantVector & base::win::VariantVector::operator= ( const VariantVector )
delete

◆ operator=() [2/2]

VariantVector & base::win::VariantVector::operator= ( VariantVector &&  other)

Definition at line 63 of file variant_vector.cc.

63 {
64 BASE_DCHECK(this != &other);
65 vartype_ = std::exchange(other.vartype_, VT_EMPTY);
66 vector_ = std::move(other.vector_);
67 return *this;
68}
#define BASE_DCHECK(condition)
Definition logging.h:63

◆ operator==()

bool base::win::VariantVector::operator== ( const VariantVector other) const

Definition at line 74 of file variant_vector.cc.

74 {
75 return !Compare(other);
76}

◆ ReleaseAsSafearrayVariant()

VARIANT base::win::VariantVector::ReleaseAsSafearrayVariant ( )

Definition at line 99 of file variant_vector.cc.

99 {
100 ScopedVariant scoped_variant;
101
102 switch (Type()) {
103 case VT_EMPTY:
104 break;
105 case VT_BOOL:
106 scoped_variant.Set(CreateAndPopulateSafearray<VT_BOOL>());
107 break;
108 case VT_I1:
109 scoped_variant.Set(CreateAndPopulateSafearray<VT_I1>());
110 break;
111 case VT_UI1:
112 scoped_variant.Set(CreateAndPopulateSafearray<VT_UI1>());
113 break;
114 case VT_I2:
115 scoped_variant.Set(CreateAndPopulateSafearray<VT_I2>());
116 break;
117 case VT_UI2:
118 scoped_variant.Set(CreateAndPopulateSafearray<VT_UI2>());
119 break;
120 case VT_I4:
121 scoped_variant.Set(CreateAndPopulateSafearray<VT_I4>());
122 break;
123 case VT_UI4:
124 scoped_variant.Set(CreateAndPopulateSafearray<VT_UI4>());
125 break;
126 case VT_I8:
127 scoped_variant.Set(CreateAndPopulateSafearray<VT_I8>());
128 break;
129 case VT_UI8:
130 scoped_variant.Set(CreateAndPopulateSafearray<VT_UI8>());
131 break;
132 case VT_R4:
133 scoped_variant.Set(CreateAndPopulateSafearray<VT_R4>());
134 break;
135 case VT_R8:
136 scoped_variant.Set(CreateAndPopulateSafearray<VT_R8>());
137 break;
138 case VT_DATE:
139 scoped_variant.Set(CreateAndPopulateSafearray<VT_DATE>());
140 break;
141 case VT_BSTR:
142 scoped_variant.Set(CreateAndPopulateSafearray<VT_BSTR>());
143 break;
144 case VT_DISPATCH:
145 scoped_variant.Set(CreateAndPopulateSafearray<VT_DISPATCH>());
146 break;
147 case VT_UNKNOWN:
148 scoped_variant.Set(CreateAndPopulateSafearray<VT_UNKNOWN>());
149 break;
150 // The default case shouldn't be reachable, but if we added support for more
151 // VARTYPEs to base::win::internal::VariantUtil<> and they were inserted
152 // into a VariantVector then it would be possible to reach the default case
153 // for those new types until implemented.
154 //
155 // Because the switch is against VARTYPE (unsigned short) and not VARENUM,
156 // removing the default case will not result in build warnings/errors if
157 // there are missing cases. It is important that this uses VARTYPE rather
158 // than VARENUM, because in the future we may want to support complex
159 // VARTYPES. For example a value within VT_TYPEMASK that's joined something
160 // outside the typemask like VT_ARRAY or VT_BYREF.
161 default:
163 break;
164 }
165
166 // CreateAndPopulateSafearray handles resetting |this| to VT_EMPTY because it
167 // transfers ownership of each element to the SAFEARRAY.
168 return scoped_variant.Release();
169}

◆ ReleaseAsScalarVariant()

VARIANT base::win::VariantVector::ReleaseAsScalarVariant ( )

Definition at line 87 of file variant_vector.cc.

87 {
88 ScopedVariant scoped_variant;
89
90 if (!Empty()) {
91 BASE_DCHECK(Size() == 1U);
92 scoped_variant = std::move(vector_[0]);
93 Reset();
94 }
95
96 return scoped_variant.Release();
97}

◆ Reset()

void base::win::VariantVector::Reset ( )

Definition at line 82 of file variant_vector.cc.

82 {
83 vector_.clear();
84 vartype_ = VT_EMPTY;
85}

◆ Size()

size_t base::win::VariantVector::Size ( ) const
inline

Definition at line 48 of file variant_vector.h.

48{ return vector_.size(); }

◆ Type()

VARTYPE base::win::VariantVector::Type ( ) const
inline

Definition at line 45 of file variant_vector.h.

45{ return vartype_; }

The documentation for this class was generated from the following files: