bool CGuid::ConvertFrom(const CString& csguid) { if (csguid.GetLength() < GUID_STRING_LEN - 4) { return false; } return ConvertFrom((LPCTSTR)csguid); }
bool CGuid::ConvertFrom(BSTR bstrGuid) { if (bstrGuid == NULL) { return false; } UINT nLen = ::SysStringLen(bstrGuid); if (nLen < GUID_STRING_LEN - 4) { return false; } CString csguid = bstrGuid; if (csguid.GetAt(0) == TCHAR('{')) { ATLASSERT(csguid.Find(TCHAR('}'))!=-1); return ConvertFrom(csguid.Mid(1, csguid.GetLength()-2)); } else { return ConvertFrom(csguid); } }
bool CGuid::Create(CComBSTR& bstrGuid) { return ConvertFrom(bstrGuid); }
bool CGuid::ConvertFrom(const CComBSTR& bstrGuid) { return ConvertFrom(bstrGuid.m_str); }
CGuid& CGuid::operator=(const CString& g) { ConvertFrom(g); return *this; }
CGuid& CGuid::operator=(LPCTSTR g) { ATLASSERT(g); ConvertFrom(g); return *this; }
CGuid& CGuid::operator=(const CComBSTR& g) { ATLASSERT(g.m_str); ConvertFrom(g); return *this; }
//---------------------------------------------------------------------------------------- bool OldDataRemapTable::Build(const std::wstring& bitMaskString, unsigned int sourceBitCount, bool specifyConversionTableState, bool auseConversionTableTo, bool auseConversionTableFrom) { //Convert bitMaskString to a binary value and load into bitMask StringToIntBase2(bitMaskString, bitMask); bitCountOriginal = sourceBitCount; //Build properties about the bitmask bitCountConverted = 0; discardBottomBitCount = 0; discardTopBitCount = 0; bool foundFirstSetBit = false; unsigned int bitMaskCopy = bitMask; for(unsigned int i = 0; i < sourceBitCount; ++i) { bool bit = (bitMaskCopy & 0x01) != 0; if(bit) { discardTopBitCount = 0; ++bitCountConverted; foundFirstSetBit = true; } else { if(!foundFirstSetBit) { ++discardBottomBitCount; } else { ++discardTopBitCount; } } bitMaskCopy >>= 1; } //Determine whether to use physical conversion tables if(specifyConversionTableState) { useConversionTableFrom = auseConversionTableFrom; useConversionTableTo = auseConversionTableTo; } else { //##FIX## Take out these magic numbers. The caller should have some say in what //these limits should be. Provide a way for the caller to be able to specify //memory usage maximums, or conversion table bitcount limits, and use those saved //limits here. We can use these magic numbers as defaults for the limits. useConversionTableTo = ((bitCountOriginal - (discardBottomBitCount + discardTopBitCount)) <= 20); useConversionTableFrom = (bitCountConverted <= 20); } //Build the physical conversion tables if(useConversionTableTo) { useConversionTableTo = false; conversionTableToSize = (1 << (bitCountOriginal - (discardBottomBitCount + discardTopBitCount))); conversionTableTo.resize(conversionTableToSize, 0); unsigned int nextNumber = 0; for(unsigned int i = 0; i < conversionTableToSize; ++i) { conversionTableTo[i] = ConvertTo(nextNumber); nextNumber += (1 << discardBottomBitCount); } useConversionTableTo = true; } if(useConversionTableFrom) { useConversionTableFrom = false; conversionTableFromSize = (1 << bitCountConverted); conversionTableFrom.resize(conversionTableFromSize, 0); for(unsigned int i = 0; i < conversionTableFromSize; ++i) { conversionTableFrom[i] = ConvertFrom(i); } useConversionTableFrom = true; } return true; }