00001 00032 #include "stdafx.h" 00033 #include "TBits.h" 00034 00035 // Can't use this for convenient notation below: 00036 // using AxPipe::Stock::TBits; 00037 // because the Doxygen get's confused. 00038 00039 namespace AxPipe { 00040 namespace Stock { 00041 00042 // Instantiate explicitly to generate code for supported bit-lengths. 00043 template TBits<128>; 00044 template TBits<160>; 00045 template TBits<256>; 00046 00049 template<int iBits> TBits<iBits>::TBits() { 00050 ZeroMemory(m_Bits, sizeof m_Bits); 00051 } 00052 00057 template<int iBits> TBits<iBits>::TBits(unsigned char *bpInit, int cb) { 00058 ZeroMemory(m_Bits, sizeof m_Bits); 00059 CopyMemory(m_Bits, bpInit, cb < sizeof m_Bits ? cb : sizeof m_Bits); 00060 } 00061 00067 template<int iBits> void * 00068 TBits<iBits>::GetLeft(const int n) { 00069 return &m_Bits; 00070 } 00071 00075 template<int iBits> void * 00076 TBits<iBits>::GetRight(const int n) { 00077 return &m_Bits[sizeof m_Bits - n/8]; 00078 } 00079 00084 template<int iBits> TBits<iBits>& 00085 TBits<iBits>::operator += (const TBits<iBits>& rhs) { 00086 bool bCarry = false; 00087 for (int i = sizeof m_Bits; i >= 0; i--) { 00088 bCarry = (m_Bits[i] += rhs.m_Bits[i] + (unsigned char)bCarry) < rhs.m_Bits[i]; 00089 } 00090 return *this; 00091 } 00092 00096 template<int iBits> TBits<iBits>& 00097 TBits<iBits>::operator ^=(const TBits<iBits>& rhs) { 00098 size_t cb = sizeof m_Bits; 00099 unsigned char *dst = m_Bits; 00100 const unsigned char *src = rhs.m_Bits; 00101 while (cb--) { 00102 *dst++ ^= *src++; 00103 } 00104 return *this; 00105 } 00106 00110 template<int iBits> TBits<iBits>& 00111 TBits<iBits>::operator =(const TBits<iBits>& rhs) { 00112 CopyMemory(&m_Bits, &rhs.m_Bits, sizeof m_Bits); 00113 return *this; 00114 } 00115 } 00116 }