1 /*****************************************************************************
2 * utils.h: ActiveX control for VLC
3 *****************************************************************************
4 * Copyright (C) 2005 VideoLAN
6 * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
21 *****************************************************************************/
31 extern char *CStrFromBSTR(int codePage, BSTR bstr);
32 extern BSTR BSTRFromCStr(int codePage, const char *s);
35 extern HRESULT GetObjectProperty(LPUNKNOWN object, DISPID dispID, VARIANT& v);
38 template<class T> class VLCEnum : IUnknown
43 VLCEnum(REFIID riid, std::vector<T> &);
44 VLCEnum(const VLCEnum<T> &);
45 virtual ~VLCEnum() {};
47 VLCEnum<T>& operator=(const VLCEnum<T> &t);
50 STDMETHODIMP QueryInterface(REFIID riid, void **);
51 STDMETHODIMP_(ULONG) AddRef(void);
52 STDMETHODIMP_(ULONG) Release(void);
55 STDMETHODIMP Next(ULONG, T *, ULONG *);
56 STDMETHODIMP Skip(ULONG);
57 STDMETHODIMP Reset(void);
58 // cloning is implemented by subclasses and must use copy constructor
59 //STDMETHODIMP Clone(VLCEnum<T> **);
60 // cloning is implemented by subclasses and must use copy constructor
62 typedef void (*retainer)(T);
64 void setRetainOperation(retainer retain) { _retain = retain; };
70 typename std::vector<T>::iterator _i;
76 VLCEnum<T>::VLCEnum(REFIID riid, std::vector<T> &v) :
86 VLCEnum<T>::VLCEnum(const VLCEnum<T> &e) :
94 VLCEnum<T>& VLCEnum<T>::operator=(const VLCEnum<T> &e)
97 this->_riid = e._riid;
103 STDMETHODIMP VLCEnum<T>::QueryInterface(REFIID riid, void **ppv)
105 if( NULL == ppv ) return E_POINTER;
106 if( (IID_IUnknown == riid)
107 && ( _riid == riid) ) {
109 *ppv = reinterpret_cast<LPVOID>(this);
112 return E_NOINTERFACE;
116 STDMETHODIMP_(ULONG) VLCEnum<T>::AddRef(void)
118 return InterlockedIncrement(&_refcount);
122 STDMETHODIMP_(ULONG) VLCEnum<T>::Release(void)
124 ULONG refcount = InterlockedDecrement(&_refcount);
134 STDMETHODIMP VLCEnum<T>::Next(ULONG celt, T *rgelt, ULONG *pceltFetched)
139 if( (celt > 1) && (NULL == pceltFetched) )
143 typename std::vector<T>::iterator end = _v.end();
145 while( (c < celt) && (_i != end) )
148 if( NULL != _retain ) _retain(rgelt[c]);
153 if( NULL != pceltFetched )
156 return (c == celt) ? S_OK : S_FALSE;
160 STDMETHODIMP VLCEnum<T>::Skip(ULONG celt)
163 typename std::vector<T>::iterator end = _v.end();
165 while( (c < celt) && (_i != end) )
170 return (c == celt) ? S_OK : S_FALSE;
174 STDMETHODIMP VLCEnum<T>::Reset(void)