Over-matching template operators << and >> replaced with variants for selected data-types only

This commit is contained in:
Simon Rozman 2017-04-25 00:34:43 +02:00
parent cf1869f495
commit 5de934285e

View File

@ -621,7 +621,7 @@ public:
friend inline BOOL operator <<(CStream &f, const COpList &list); friend inline BOOL operator <<(CStream &f, const COpList &list);
friend inline BOOL operator >>(CStream &f, COpList &list); friend inline BOOL operator >>(CStream &f, COpList &list);
protected: public:
enum OPERATION { enum OPERATION {
OP_ROLLBACK_ENABLE = 1, OP_ROLLBACK_ENABLE = 1,
OP_FILE_DELETE, OP_FILE_DELETE,
@ -760,35 +760,48 @@ namespace MSICA {
// Inline operators // Inline operators
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
template <class T> #define MSICALIB_STREAM_DATA(T) \
inline BOOL operator <<(CStream &f, const T &val) inline BOOL operator <<(CStream &f, const T &val) \
{ { \
DWORD dwWritten; DWORD dwWritten; \
\
if (!::WriteFile(f, &val, sizeof(T), &dwWritten, NULL)) return FALSE; if (!::WriteFile(f, &val, sizeof(T), &dwWritten, NULL)) return FALSE; \
if (dwWritten != sizeof(T)) { if (dwWritten != sizeof(T)) { \
::SetLastError(ERROR_WRITE_FAULT); ::SetLastError(ERROR_WRITE_FAULT); \
return FALSE; return FALSE; \
} } \
\
return TRUE; return TRUE; \
} \
\
inline BOOL operator >>(CStream &f, T &val) \
{ \
DWORD dwRead; \
\
if (!::ReadFile(f, &val, sizeof(T), &dwRead, NULL)) return FALSE; \
if (dwRead != sizeof(T)) { \
::SetLastError(ERROR_READ_FAULT); \
return FALSE; \
} \
\
return TRUE; \
} }
MSICALIB_STREAM_DATA(short)
MSICALIB_STREAM_DATA(unsigned short)
MSICALIB_STREAM_DATA(long)
MSICALIB_STREAM_DATA(unsigned long)
MSICALIB_STREAM_DATA(int)
MSICALIB_STREAM_DATA(size_t)
#ifndef _WIN64
MSICALIB_STREAM_DATA(DWORDLONG)
#endif
MSICALIB_STREAM_DATA(HKEY)
MSICALIB_STREAM_DATA(GUID)
MSICALIB_STREAM_DATA(TASK_TRIGGER)
MSICALIB_STREAM_DATA(COpList::OPERATION)
template <class T> #undef MSICALIB_STREAM_DATA
inline BOOL operator >>(CStream &f, T &val)
{
DWORD dwRead;
if (!::ReadFile(f, &val, sizeof(T), &dwRead, NULL)) return FALSE;
if (dwRead != sizeof(T)) {
::SetLastError(ERROR_READ_FAULT);
return FALSE;
}
return TRUE;
}
template <class _Ty, class _Ax> template <class _Ty, class _Ax>
inline BOOL operator <<(CStream &f, const std::vector<_Ty, _Ax> &val) inline BOOL operator <<(CStream &f, const std::vector<_Ty, _Ax> &val)