5#ifndef BASE_WIN_SCOPED_SAFEARRAY_H_
6#define BASE_WIN_SCOPED_SAFEARRAY_H_
31 template <VARTYPE ElementVartype>
44 : safearray_(nullptr),
50 : safearray_(
std::exchange(other.safearray_, nullptr)),
51 vartype_(
std::exchange(other.vartype_, VT_EMPTY)),
52 array_(
std::exchange(other.array_, nullptr)),
53 array_size_(
std::exchange(other.array_size_, 0
U)) {}
58 safearray_ = std::exchange(other.safearray_,
nullptr);
59 vartype_ = std::exchange(other.vartype_, VT_EMPTY);
60 array_ = std::exchange(other.array_,
nullptr);
61 array_size_ = std::exchange(other.array_size_, 0
U);
67 VARTYPE
Type()
const {
return vartype_; }
69 size_t size()
const {
return array_size_; }
96 : safearray_(safearray),
99 array_size_(array_size) {}
103 SafeArrayUnaccessData(safearray_);
104 safearray_ =
nullptr;
110 SAFEARRAY* safearray_;
120 : safearray_(safearray) {}
124 r.safearray_ =
nullptr;
129 Reset(rvalue.Release());
137 template <VARTYPE ElementVartype>
139 if (!safearray_ || SafeArrayGetDim(safearray_) != 1)
143 HRESULT hr = SafeArrayGetVartype(safearray_, &vartype);
150 hr = SafeArrayAccessData(safearray_,
reinterpret_cast<void**
>(&array));
154 const size_t array_size = GetCount();
160 HRESULT hr = SafeArrayDestroy(safearray_);
162 safearray_ =
nullptr;
168 void Reset(SAFEARRAY* safearray =
nullptr) {
169 if (safearray != safearray_) {
171 safearray_ = safearray;
177 SAFEARRAY* safearray = safearray_;
178 safearray_ =
nullptr;
200 BASE_DCHECK(dimension < SafeArrayGetDim(safearray_));
201 HRESULT hr = SafeArrayGetLBound(safearray_, dimension + 1, &
lower);
203 hr = SafeArrayGetUBound(safearray_, dimension + 1, &upper);
205 return (upper -
lower + 1);
209 SAFEARRAY*
Get()
const {
return safearray_; }
217 SAFEARRAY* safearray_;
std::random_access_iterator_tag iterator_category
const_pointer data() const
const value_type * const_pointer
const_pointer end() const
const_reference operator[](int index) const
const value_type & const_reference
const_pointer begin() const
LockScope< ElementVartype > & operator=(LockScope< ElementVartype > &&other)
const_reference at(size_t index) const
LockScope(LockScope< ElementVartype > &&other)
reference operator[](int index)
ptrdiff_t difference_type
reference at(size_t index)
typename internal::VariantUtil< ElementVartype >::Type value_type
void Reset(SAFEARRAY *safearray=nullptr)
bool operator==(const ScopedSafearray &safearray2) const =delete
ScopedSafearray & operator=(ScopedSafearray &&rvalue)
ScopedSafearray(SAFEARRAY *safearray=nullptr)
ScopedSafearray(ScopedSafearray &&r) noexcept
size_t GetCount(UINT dimension=0) const
bool operator!=(const ScopedSafearray &safearray2) const =delete
std::optional< LockScope< ElementVartype > > CreateLockScope() const
typename VartypeToNativeType< ElementVartype >::Type Type
#define BASE_DCHECK(condition)
#define BASE_DISALLOW_COPY_AND_ASSIGN(TypeName)