OfficeOLE/include/office/MSCollection.hpp

41 lines
927 B
C++
Raw Permalink Normal View History

2024-06-07 20:45:14 +03:00
#pragma once
#include "comutil.h"
namespace MSO {
// CRTP for adding Collection access functions to wrapper classes
template <typename Collection, typename Item>
class MSCollection {
public:
using IndexType = long;
using IndexString = CString;
using size_type = long;
// Note: Do not warn about static_cast downcast
#pragma warning( push )
#pragma warning( disable : 26491 )
Item operator[](const IndexType& index) {
auto* collection = static_cast<Collection*>(this);
return collection->get_Item(_variant_t(index));
}
Item operator[](const IndexString& index) {
auto* collection = static_cast<Collection*>(this);
return collection->get_Item(_variant_t(index));
}
#pragma warning( pop )
size_type size() const {
auto* collection = static_cast<Collection*>(this);
return collection->GetCount();
}
private:
friend Collection;
MSCollection() = default;
};
} // namespace MSO