Commit bca93013 authored by Damien Fouilleul's avatar Damien Fouilleul

-activex: implement _NewEnum property on log.messages collection to allow for...

-activex: implement _NewEnum property on log.messages collection to allow for "For each message in log.messages" construct in VB and other languages
parent 214647c6
...@@ -46,7 +46,7 @@ extern LPWSTR CombineURL(LPCWSTR baseUrl, LPCWSTR url); ...@@ -46,7 +46,7 @@ extern LPWSTR CombineURL(LPCWSTR baseUrl, LPCWSTR url);
/**************************************************************************************************/ /**************************************************************************************************/
/* this function object is used to dereference the iterator into a value */ /* this function object is used to dereference the iterator into a value */
template <class T, class Iterator> template <typename T, class Iterator>
struct VLCDereference struct VLCDereference
{ {
T operator()(const Iterator& i) const T operator()(const Iterator& i) const
...@@ -55,7 +55,7 @@ struct VLCDereference ...@@ -55,7 +55,7 @@ struct VLCDereference
}; };
}; };
template<REFIID EnumeratorIID, class Enumerator, class T, class Iterator, typename Dereference = VLCDereference<T, Iterator> > template<REFIID EnumeratorIID, class Enumerator, typename T, class Iterator, typename Dereference = VLCDereference<T, Iterator> >
class VLCEnumIterator : public Enumerator class VLCEnumIterator : public Enumerator
{ {
......
...@@ -853,6 +853,89 @@ STDMETHODIMP VLCLog::put_verbosity(long verbosity) ...@@ -853,6 +853,89 @@ STDMETHODIMP VLCLog::put_verbosity(long verbosity)
/*******************************************************************************/ /*******************************************************************************/
/* STL forward iterator used by VLCEnumIterator class to implement IEnumVARIANT */
class VLCMessageSTLIterator
{
public:
VLCMessageSTLIterator(IVLCMessageIterator* iter) : iter(iter), msg(NULL)
{
// get first message
operator++();
};
VLCMessageSTLIterator(const VLCMessageSTLIterator& other)
{
iter = other.iter;
if( iter )
iter->AddRef();
msg = other.msg;
if( msg )
msg->AddRef();
};
virtual ~VLCMessageSTLIterator()
{
if( msg )
msg->Release();
if( iter )
iter->Release();
};
// we only need prefix ++ operator
VLCMessageSTLIterator& operator++()
{
VARIANT_BOOL hasNext = VARIANT_FALSE;
if( iter )
{
iter->get_hasNext(&hasNext);
if( msg )
{
msg->Release();
msg = NULL;
}
if( VARIANT_TRUE == hasNext ) {
iter->next(&msg);
}
}
return *this;
};
VARIANT operator*() const
{
VARIANT v;
VariantInit(&v);
if( msg )
{
if( SUCCEEDED(msg->QueryInterface(IID_IDispatch, (LPVOID*)&V_DISPATCH(&v))) )
{
V_VT(&v) = VT_DISPATCH;
}
}
return v;
};
bool operator==(const VLCMessageSTLIterator& other) const
{
return msg == other.msg;
};
bool operator!=(const VLCMessageSTLIterator& other) const
{
return msg != other.msg;
};
private:
IVLCMessageIterator* iter;
IVLCMessage* msg;
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////
VLCMessages::~VLCMessages() VLCMessages::~VLCMessages()
{ {
if( _p_typeinfo ) if( _p_typeinfo )
...@@ -935,9 +1018,16 @@ STDMETHODIMP VLCMessages::get__NewEnum(LPUNKNOWN* _NewEnum) ...@@ -935,9 +1018,16 @@ STDMETHODIMP VLCMessages::get__NewEnum(LPUNKNOWN* _NewEnum)
if( NULL == _NewEnum ) if( NULL == _NewEnum )
return E_POINTER; return E_POINTER;
// TODO IVLCMessageIterator* iter = NULL;
*_NewEnum = NULL; iterator(&iter);
return E_NOTIMPL;
*_NewEnum= new VLCEnumIterator<IID_IEnumVARIANT,
IEnumVARIANT,
VARIANT,
VLCMessageSTLIterator>
(VLCMessageSTLIterator(iter), VLCMessageSTLIterator(NULL));
return *_NewEnum ? S_OK : E_OUTOFMEMORY;
}; };
STDMETHODIMP VLCMessages::clear() STDMETHODIMP VLCMessages::clear()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment