system: add safearray_accessor_with_size
Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
bfda0e962b
commit
16e2384419
@ -547,12 +547,8 @@ namespace stdex
|
|||||||
///
|
///
|
||||||
size_t write_sa(_In_ LPSAFEARRAY sa)
|
size_t write_sa(_In_ LPSAFEARRAY sa)
|
||||||
{
|
{
|
||||||
long ubound, lbound;
|
safearray_accessor_with_size<uint8_t> a(sa);
|
||||||
if (FAILED(SafeArrayGetUBound(sa, 1, &ubound)) ||
|
return write(a.data(), a.size());
|
||||||
FAILED(SafeArrayGetLBound(sa, 1, &lbound)))
|
|
||||||
throw std::invalid_argument("SafeArrayGet[UL]Bound failed");
|
|
||||||
safearray_accessor<void> a(sa);
|
|
||||||
return write(a.data(), static_cast<size_t>(ubound) - lbound + 1);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -231,6 +231,32 @@ namespace stdex
|
|||||||
T* m_data;
|
T* m_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
class safearray_accessor_with_size : public safearray_accessor<T>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
safearray_accessor_with_size(_In_ LPSAFEARRAY sa) : safearray_accessor<T>(sa)
|
||||||
|
{
|
||||||
|
m_size = SafeArrayGetElemsize(sa);
|
||||||
|
for (UINT d = 1, dim = SafeArrayGetDim(sa); d <= dim; ++d) {
|
||||||
|
long ubound, lbound;
|
||||||
|
if (FAILED(SafeArrayGetUBound(sa, d, &ubound)) ||
|
||||||
|
FAILED(SafeArrayGetLBound(sa, d, &lbound)))
|
||||||
|
throw std::invalid_argument("SafeArrayGet[UL]Bound failed");
|
||||||
|
m_size *= static_cast<size_t>(ubound) - lbound + 1;
|
||||||
|
}
|
||||||
|
m_size /= sizeof(T);
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Return size in number of elements
|
||||||
|
///
|
||||||
|
size_t size() const { return m_size; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
size_t m_size;
|
||||||
|
};
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Deleter for unique_ptr using SafeArrayDestroy
|
/// Deleter for unique_ptr using SafeArrayDestroy
|
||||||
///
|
///
|
||||||
|
Loading…
x
Reference in New Issue
Block a user