[vlc-commits] activex: Simplify use of VLCEnumIterator
Hugo Beauzée-Luyssen
git at videolan.org
Fri Apr 17 13:31:14 CEST 2015
npapi-vlc | branch: cleanup | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Tue Apr 14 14:33:02 2015 +0200| [f377e88a7a7656a26bbac18c10de8e5fa1bac03e] | committer: Hugo Beauzée-Luyssen
activex: Simplify use of VLCEnumIterator
> http://git.videolan.org/gitweb.cgi/npapi-vlc.git/?a=commit;h=f377e88a7a7656a26bbac18c10de8e5fa1bac03e
---
activex/connectioncontainer.cpp | 43 ++++++++-----------------------
activex/dataobject.cpp | 19 ++++----------
activex/plugin.cpp | 1 -
activex/utils.h | 53 +++++++++++++++++----------------------
4 files changed, 38 insertions(+), 78 deletions(-)
diff --git a/activex/connectioncontainer.cpp b/activex/connectioncontainer.cpp
index d335128..b906cab 100644
--- a/activex/connectioncontainer.cpp
+++ b/activex/connectioncontainer.cpp
@@ -51,22 +51,11 @@ struct VLCEnumConnectionsDereference
}
};
-class VLCEnumConnections : public VLCEnumIterator<IID_IEnumConnections,
- IEnumConnections,
- CONNECTDATA,
- std::map<DWORD,LPUNKNOWN>::iterator,
- VLCEnumConnectionsDereference>
-{
-public:
- VLCEnumConnections(std::map<DWORD,LPUNKNOWN> &m) :
- VLCEnumIterator<IID_IEnumConnections,
- IEnumConnections,
- CONNECTDATA,
- std::map<DWORD,LPUNKNOWN>::iterator,
- VLCEnumConnectionsDereference> (m.begin(), m.end())
- {
- }
-};
+using VLCEnumConnections = VLCEnumIterator<IID_IEnumConnections,
+ IEnumConnections,
+ CONNECTDATA,
+ std::map<DWORD,LPUNKNOWN>,
+ VLCEnumConnectionsDereference>;
////////////////////////////////////////////////////////////////////////////////////////////////
@@ -81,23 +70,11 @@ struct VLCEnumConnectionPointsDereference
}
};
-class VLCEnumConnectionPoints: public VLCEnumIterator<IID_IEnumConnectionPoints,
- IEnumConnectionPoints,
- LPCONNECTIONPOINT,
- std::vector<LPCONNECTIONPOINT>::iterator,
- VLCEnumConnectionPointsDereference>
-{
-public:
- VLCEnumConnectionPoints(std::vector<LPCONNECTIONPOINT>& v) :
- VLCEnumIterator<IID_IEnumConnectionPoints,
- IEnumConnectionPoints,
- LPCONNECTIONPOINT,
- std::vector<LPCONNECTIONPOINT>::iterator,
- VLCEnumConnectionPointsDereference> (v.begin(), v.end())
- {
- }
-};
-
+using VLCEnumConnectionPoints = VLCEnumIterator<IID_IEnumConnectionPoints,
+ IEnumConnectionPoints,
+ LPCONNECTIONPOINT,
+ std::vector<LPCONNECTIONPOINT>,
+ VLCEnumConnectionPointsDereference>;
////////////////////////////////////////////////////////////////////////////////////////////////
// EventSystemProxyWnd
////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/activex/dataobject.cpp b/activex/dataobject.cpp
index 1727de4..52a1ac0 100644
--- a/activex/dataobject.cpp
+++ b/activex/dataobject.cpp
@@ -46,19 +46,10 @@ static const FORMATETC _enhMetaFileFormatEtc =
TYMED_ENHMF,
};
-class VLCEnumFORMATETC : public VLCEnumIterator<IID_IEnumFORMATETC,
- IEnumFORMATETC,
- FORMATETC,
- vector<FORMATETC>::iterator>
-{
-public:
- VLCEnumFORMATETC(vector<FORMATETC> v) :
- VLCEnumIterator<IID_IEnumFORMATETC,
- IEnumFORMATETC,
- FORMATETC,
- vector<FORMATETC>::iterator>(v.begin(), v.end())
- {};
-};
+using VLCEnumFORMATETC = VLCEnumIterator<IID_IEnumFORMATETC,
+ IEnumFORMATETC,
+ FORMATETC,
+ std::vector<FORMATETC>>;
//////////////////////////////////////////////////////////////////////////////
@@ -246,7 +237,7 @@ STDMETHODIMP VLCDataObject::QueryGetData(LPFORMATETC pFormatEtc)
default:
return DV_E_FORMATETC;
}
-
+
if( pFormatEtc->dwAspect != formatEtc->dwAspect )
return DV_E_DVASPECT;
diff --git a/activex/plugin.cpp b/activex/plugin.cpp
index 0410c6d..edeffc6 100644
--- a/activex/plugin.cpp
+++ b/activex/plugin.cpp
@@ -50,7 +50,6 @@
#include <servprov.h>
#include <shlwapi.h>
#include <wininet.h>
-#include <assert.h>
using namespace std;
diff --git a/activex/utils.h b/activex/utils.h
index 6234ab3..c4e3cef 100644
--- a/activex/utils.h
+++ b/activex/utils.h
@@ -52,32 +52,26 @@ struct VLCDereference
T operator()(const Iterator& i) const
{
return *i;
- };
+ }
};
-template<REFIID EnumeratorIID, class Enumerator, typename T, class Iterator, typename Dereference = VLCDereference<T, Iterator> >
+template<REFIID EnumeratorIID, class Enumerator, typename T, class Container, typename Dereference = VLCDereference<T, typename Container::iterator> >
class VLCEnumIterator : public Enumerator
{
public:
- VLCEnumIterator(const Iterator& from, const Iterator& to) :
+ VLCEnumIterator(Container& container) :
_refcount(1),
- _begin(from),
- _curr(from),
- _end(to)
- {};
-
- VLCEnumIterator(const VLCEnumIterator& e) :
- Enumerator(),
- _refcount(e._refcount),
- _begin(e._begin),
- _curr(e._curr),
- _end(e._end)
- {};
-
- virtual ~VLCEnumIterator()
- {};
+ _begin(begin(container)),
+ _curr(_begin),
+ _end(end(container))
+ {
+ }
+
+ VLCEnumIterator(const VLCEnumIterator& e) = default;
+
+ virtual ~VLCEnumIterator() = default;
// IUnknown methods
STDMETHODIMP QueryInterface(REFIID riid, void **ppv)
@@ -93,12 +87,12 @@ public:
}
// standalone object
return E_NOINTERFACE;
- };
+ }
- STDMETHODIMP_(ULONG) AddRef(void)
+ STDMETHODIMP_(ULONG) AddRef()
{
return InterlockedIncrement(&_refcount);
- };
+ }
STDMETHODIMP_(ULONG) Release(void)
{
@@ -109,7 +103,7 @@ public:
return 0;
}
return refcount;
- };
+ }
// IEnumXXXX methods
@@ -134,7 +128,7 @@ public:
*pceltFetched = c;
return (c == celt) ? S_OK : S_FALSE;
- };
+ }
STDMETHODIMP Skip(ULONG celt)
{
@@ -146,29 +140,28 @@ public:
++c;
}
return (c == celt) ? S_OK : S_FALSE;
- };
+ }
- STDMETHODIMP Reset(void)
+ STDMETHODIMP Reset()
{
_curr = _begin;
return S_OK;
- };
+ }
STDMETHODIMP Clone(Enumerator **ppEnum)
{
if( NULL == ppEnum )
return E_POINTER;
- *ppEnum = dynamic_cast<Enumerator *>(new VLCEnumIterator(*this));
+ *ppEnum = new VLCEnumIterator(*this);
return (NULL != *ppEnum ) ? S_OK : E_OUTOFMEMORY;
- };
+ }
private:
LONG _refcount;
- Iterator _begin, _curr, _end;
+ typename Container::iterator _begin, _curr, _end;
Dereference dereference;
-
};
#endif
More information about the vlc-commits
mailing list