123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- #ifndef BASE_WIN_VARIANT_VECTOR_H_
- #define BASE_WIN_VARIANT_VECTOR_H_
- #include <objbase.h>
- #include <oleauto.h>
- #include <type_traits>
- #include <utility>
- #include <vector>
- #include "base/base_export.h"
- #include "base/check.h"
- #include "base/logging.h"
- #include "base/no_destructor.h"
- #include "base/win/scoped_variant.h"
- #include "base/win/variant_util.h"
- namespace base {
- namespace win {
- class BASE_EXPORT VariantVector final {
- public:
- VariantVector();
- VariantVector(VariantVector&& other);
- VariantVector& operator=(VariantVector&& other);
- VariantVector(const VariantVector&) = delete;
- VariantVector& operator=(const VariantVector&) = delete;
- ~VariantVector();
- bool operator==(const VariantVector& other) const;
- bool operator!=(const VariantVector& other) const;
-
- VARTYPE Type() const { return vartype_; }
-
- size_t Size() const { return vector_.size(); }
-
- bool Empty() const { return vector_.empty(); }
-
- void Reset();
-
-
- template <VARTYPE ExpectedVartype,
- std::enable_if_t<ExpectedVartype != VT_BOOL, int> = 0>
- void Insert(typename internal::VariantUtil<ExpectedVartype>::Type value) {
- if (vartype_ == VT_EMPTY)
- vartype_ = ExpectedVartype;
- AssertVartype<ExpectedVartype>();
- ScopedVariant scoped_variant;
- scoped_variant.Set(value);
- vector_.push_back(std::move(scoped_variant));
- }
-
-
- template <VARTYPE ExpectedVartype,
- std::enable_if_t<ExpectedVartype == VT_BOOL, int> = 0>
- void Insert(bool value) {
- if (vartype_ == VT_EMPTY)
- vartype_ = ExpectedVartype;
- AssertVartype<ExpectedVartype>();
- ScopedVariant scoped_variant;
- scoped_variant.Set(value);
- vector_.push_back(std::move(scoped_variant));
- }
-
-
- template <>
- void Insert<VT_DATE>(typename internal::VariantUtil<VT_DATE>::Type value) {
- if (vartype_ == VT_EMPTY)
- vartype_ = VT_DATE;
- AssertVartype<VT_DATE>();
- ScopedVariant scoped_variant;
- scoped_variant.SetDate(value);
- vector_.push_back(std::move(scoped_variant));
- }
-
-
-
-
- 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;
- private:
-
-
- template <VARTYPE ExpectedVartype>
- void AssertVartype() const {
- DCHECK(internal::VariantUtil<ExpectedVartype>::IsConvertibleTo(vartype_))
- << "Type mismatch, " << ExpectedVartype << " is not convertible to "
- << Type();
- }
-
-
-
- template <VARTYPE ElementVartype>
- SAFEARRAY* CreateAndPopulateSafearray();
- VARTYPE vartype_ = VT_EMPTY;
- std::vector<ScopedVariant> vector_;
- };
- }
- }
- #endif
|