00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00014
00021 #if !defined(ZIPARCHIVE_BYTESWRITER_DOT_H)
00022 #define ZIPARCHIVE_BYTESWRITER_DOT_H
00023
00024 #if _MSC_VER > 1000
00025 #pragma once
00026 #endif
00027
00028 #include "ZipCompatibility.h"
00029
00030 namespace ZipArchiveLib
00031 {
00036 class ZIP_API CBytesWriter
00037 {
00038 public:
00039
00040 #ifndef _ZIP_BIG_ENDIAN
00041
00053 static void ReadBytes(WORD& uDestination, const char* pSource, int iCount = 2)
00054 {
00055 uDestination = 0;
00056 memcpy(&uDestination, pSource, iCount);
00057 }
00058
00059 static void ReadBytes(DWORD& uDestination, const char* pSource, int iCount = 4)
00060 {
00061 uDestination = 0;
00062 memcpy(&uDestination, pSource, iCount);
00063 }
00064
00065
00066 #ifndef _ZIP_STRICT_U16
00067 static void ReadBytes(int& iDestination, const char* pSource, int iCount)
00068 {
00069 iDestination = 0;
00070 memcpy(&iDestination, pSource, iCount);
00071 }
00072 #endif
00073
00074
00075 static void WriteBytes(char* pDestination, WORD uSource)
00076 {
00077 memcpy(pDestination, &uSource, 2);
00078 }
00079
00092 static void WriteBytes(char* pDestination, DWORD uSource, int iCount = 4)
00093 {
00094 memcpy(pDestination, &uSource, iCount);
00095 }
00096
00097 #ifndef _ZIP_STRICT_U16
00098 static void WriteBytes(char* pDestination, int uSource, int iCount)
00099 {
00100 memcpy(pDestination, &uSource, iCount);
00101 }
00102 #endif
00103
00104 #else
00105
00106 static void ReadBytes(char* pDestination, const char* pSource, int iDestSize, int iCount)
00107 {
00108 int i = iCount - iDestSize;
00109 while (i < 0)
00110 {
00111 *pDestination++ = 0;
00112 i++;
00113 }
00114 for (; i < iCount; i++)
00115 (pDestination)[i] = pSource[iCount - i - 1];
00116 }
00117
00118 static void ReadBytes(WORD& uDestination, const char* pSource, int iCount = 2)
00119 {
00120 ReadBytes((char*)&uDestination, pSource, 2, iCount);
00121 }
00122
00123 static void ReadBytes(DWORD& uDestination, const char* pSource, int iCount = 4)
00124 {
00125 ReadBytes((char*)&uDestination, pSource, 4, iCount);
00126 }
00127
00128
00129 #ifndef _ZIP_STRICT_U16
00130 static void ReadBytes(int& iDestination, const char* pSource, int iCount)
00131 {
00132 ReadBytes((char*)&iDestination, pSource, sizeof(int), iCount);
00133 }
00134 #endif
00135
00136
00137 static void WriteBytes(char* pDestination, WORD uSource)
00138 {
00139 for (int i = 0; i < 2; i++)
00140 pDestination[i] = ((char*)&uSource)[2 - i - 1];
00141 }
00142
00143 static void WriteBytes(char* pDestination, DWORD uSource, int iCount = 4)
00144 {
00145 for (int i = 0; i < iCount; i++)
00146 pDestination[i] = ((char*)&uSource)[4 - i - 1];
00147 }
00148
00149 #ifndef _ZIP_STRICT_U16
00150 static void WriteBytes(char* pDestination, int iSource, int iCount)
00151 {
00152 for (int i = 0; i < iCount; i++)
00153 pDestination[i] = ((char*)&iSource)[sizeof(int) - i - 1];
00154 }
00155 #endif
00156
00157 #endif
00158
00159 static DWORD WriteSafeU32(DWORD uValue)
00160 {
00161 return uValue;
00162 }
00163
00164 #ifdef _ZIP_STRICT_U16
00165 static WORD WriteSafeU16(WORD uValue)
00166 {
00167 return uValue;
00168 }
00169 #else
00170 static WORD WriteSafeU16(int uValue)
00171 {
00172 return (WORD)uValue;
00173 }
00174 #endif
00175
00176
00177 };
00178 }
00179
00180 #endif