Who can help with conversion C++ code to Delphi?
Code:
private: CArray<byte> m_Packed; CArray<byte> m_Unpacked; class CUnpack { public: CUnpack() { m_PackedOffset = 0; m_Stage = 0; } CArray<byte> AddByte(byte InB) { m_Packed.PushBack(InB); CArray<byte> UnpackedChunk; for ( ; ; ) { if (m_Stage == 0) { {code} } } return UnpackedChunk; }
a) “CArray<byte> m_Packed” in Delphi it should look like “m_Packed : array of byte ”or I’m wrong?
b) What does this mean “for ( ; ; )”?
c) What actually do PopFront and PushBack?
Code:
dword GetPackedBits(dword BitCount) { if (BitCount > 16) return 0; if (!HasBits(BitCount)) Notify("Unpack bit stream overflow"); dword AlBitCount = BitCount + m_PackedOffset; dword AlByteCount = (AlBitCount + 7) / 8; dword V = 0; for (dword i = 0; i < AlByteCount; i++) V |= dword(m_Packed[i]) << (24 - i * 8); V <<= m_PackedOffset; V >>= 32 - BitCount; m_PackedOffset += BitCount; dword FreeBytes = m_PackedOffset / 8; if (FreeBytes) m_Packed.PopFront(FreeBytes); m_PackedOffset %= 8; return V; }
Code:
function GetPackedBits(BitCount : dword): dword; var AlBitCount : dword; V : dword; i : integer; FreeBytes : dword; AlByteCount: dword; begin if (BitCount > 16) then result:= 0; if ( not HasBits(BitCount)) then begin {Notify('Unpack bit stream overflow');} end; AlBitCount := BitCount + m_PackedOffset; AlByteCount := (AlBitCount + 7) / 8; V := 0; for i := 0 to AlByteCount - 1 do V:= mod or m_Packed[i] shl (24 - i * 8); V:= mod shl m_PackedOffset; V:= mod shr 32 - BitCount; m_PackedOffset:= mod + BitCount; FreeBytes := m_PackedOffset / 8; if (FreeBytes) then m_Packed.PopFront(FreeBytes); m_PackedOffset:= mod mod 8; result:= V; end;