MIMECode.h
上传用户:weimei12
上传日期:2022-08-11
资源大小:185k
文件大小:4k
- #pragma once
- /********************************************************************
- created: 2008:10:29 11:04
- author: 李欣
- filename: c:MyProjectSimpleMailSimpleMailMIMECode.h
- classname: CMIMECode
- purpose: a base class for Mime encoding
- *********************************************************************/
- class CMIMECode
- {
- public:
- CMIMECode();
- virtual ~CMIMECode();
- ///<summary>
- /// decode the string
- ///</summary>
- ///<param name = >
- /// the string to be decoded
- ///</param>
- /// <returns>
- /// the decoding result
- /// </returns>
- virtual CString Decode(IN LPCTSTR szDecoding) = 0;
- ///<summary>
- /// encode the string
- ///</summary>
- ///<param name = szEncoding>
- /// the string to be encoded
- ///</param>
- ///<param name = nSize>
- /// the size of szEncoding
- ///</param>
- /// <returns>
- /// the encoding result
- /// </returns>
- virtual CString Encode(IN LPCTSTR szEncoding, IN int nSize) = 0;
- protected:
- ///<summary>
- /// Test the certain bit whether it is 1
- ///</summary>
- ///<param name = nChar>
- /// the char to be tested
- ///</param>
- ///<param name = nWhich>
- /// the index of the bit to be tested
- ///</param>
- /// <returns>
- /// return true if it is 1
- /// </returns>
- bool TestBit(IN const char nChar, IN const int nWhich);
- ///<summary>
- /// Create a byte with the certain bit to be 1
- ///</summary>
- ///<param name = nWhich>
- /// the index of the bit to be set
- ///</param>
- /// <returns>
- /// the char created
- /// </returns>
- char MakeBit(IN const int nWhich);
- ///<summary>
- /// Create a byte with the certain continuous bits to be 1
- ///</summary>
- ///<param name = nFrom>
- /// the begin index of that range
- ///</param>
- ///<param name = nTo>
- /// the end index of that range
- ///</param>
- /// <returns>
- /// the char created
- /// </returns>
- char MakeBitSection(IN const int nFrom, IN const int nTo);
- ///<summary>
- /// Set the certain bit to 1
- ///</summary>
- ///<param name = nWhich>
- /// the index of the bit to be set
- ///</param>
- ///<param name = chOutChar>
- /// the char to be processed
- ///</param>
- void SetBit(IN const int nWhich, INOUT char& chOutChar);
- ///<summary>
- /// Set the certain bit to 0
- ///</summary>
- ///<param name = nWhich>
- /// the index of the bit to be set
- ///</param>
- ///<param name = chOutChar>
- /// the char to be processed
- ///</param>
- void ClearBit(IN const int nWhich, INOUT char& chOutChar);
- ///<summary>
- /// Set the tail to 0 and set the head to 1
- ///</summary>
- ///<param name = chOutChar>
- /// the char to be processed
- ///</param>
- void ClearHeadAndSetTail(INOUT char& chOutChar);
- };
- ///<summary>
- /// Test the certain bit whether it is 1
- ///</summary>
- inline bool CMIMECode::TestBit(const char nChar, const int nWhich)
- {
- if( (nChar & MakeBit(nWhich)) == 0 )
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- ///<summary>
- /// Create a byte with the certain bit to be 1
- ///</summary>
- inline char CMIMECode::MakeBit(IN const int nWhich)
- {
- return 1U << (7-nWhich) ;
- }
- ///<summary>
- /// Create a byte with the certain continuous bits to be 1
- ///</summary>
- inline char CMIMECode::MakeBitSection(IN const int nFrom, IN const int nTo)
- {
- char c = 0x00;
- for(int k = nFrom; k <= nTo; k++)
- {
- SetBit(k, c);
- }
- return c;
- }
- ///<summary>
- /// Set the certain bit to 1
- ///</summary>
- inline void CMIMECode::SetBit(const int nWhich, char& chOutChar)
- {
- chOutChar |= MakeBit(nWhich);
- }
- ///<summary>
- /// Set the certain bit to 0
- ///</summary>
- inline void CMIMECode::ClearBit(const int nWhich, char& chOutChar)
- {
- chOutChar &= ~ MakeBit(nWhich);
- }
- ///<summary>
- /// Set the tail to 0 and set the head to 1
- ///</summary>
- inline void CMIMECode::ClearHeadAndSetTail(char& chOutChar)
- {
- ClearBit(0, chOutChar);
- SetBit(7, chOutChar);
- }