//
// � Copyright Henrik Ravn 2004
//
// Use, modification and distribution are subject to the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
using System;
namespace DotZLib
{
/// <summary>
/// Implements the common functionality needed for all <see cref="Codec"/>s
/// </summary>
{
/// <summary>
/// Instance of the internal zlib buffer structure that is
/// passed to all functions in the zlib dll
/// </summary>
/// <summary>
/// True if the object instance has been disposed, false otherwise
/// </summary>
protected bool _isDisposed = false;
/// <summary>
/// The size of the internal buffers
/// </summary>
protected const int kBufferSize = 16384;
private byte[] _outBuffer = new byte[kBufferSize];
private byte[] _inBuffer = new byte[kBufferSize];
private uint _checksum = 0;
/// <summary>
/// Initializes a new instance of the <c>CodeBase</c> class.
/// </summary>
public CodecBase()
{
try
{
}
catch (Exception)
{
CleanUp(false);
throw;
}
}
/// <summary>
/// Occurs when more processed data are available.
/// </summary>
public event DataAvailableHandler DataAvailable;
/// <summary>
/// Fires the <see cref="DataAvailable"/> event
/// </summary>
protected void OnDataAvailable()
{
{
if (DataAvailable != null)
resetOutput();
}
}
/// <summary>
/// Adds more data to the codec to be processed.
/// </summary>
/// <param name="data">Byte array containing the data to be added to the codec</param>
/// <remarks>Adding data may, or may not, raise the <c>DataAvailable</c> event</remarks>
{
}
/// <summary>
/// Adds more data to the codec to be processed.
/// </summary>
/// <param name="data">Byte array containing the data to be added to the codec</param>
/// <param name="offset">The index of the first byte to add from <c>data</c></param>
/// <param name="count">The number of bytes to add</param>
/// <remarks>Adding data may, or may not, raise the <c>DataAvailable</c> event</remarks>
/// <remarks>This must be implemented by a derived class</remarks>
/// <summary>
/// Finishes up any pending data that needs to be processed and handled.
/// </summary>
/// <remarks>This must be implemented by a derived class</remarks>
public abstract void Finish();
/// <summary>
/// Gets the checksum of the data that has been added so far
/// </summary>
/// <summary>
/// Destroys this instance
/// </summary>
~CodecBase()
{
CleanUp(false);
}
/// <summary>
/// Releases any unmanaged resources and calls the <see cref="CleanUp()"/> method of the derived class
/// </summary>
public void Dispose()
{
CleanUp(true);
}
/// <summary>
/// Performs any codec specific cleanup
/// </summary>
/// <remarks>This must be implemented by a derived class</remarks>
protected abstract void CleanUp();
// performs the release of the handles and calls the dereived CleanUp()
private void CleanUp(bool isDisposing)
{
if (!_isDisposed)
{
CleanUp();
if (_hInput.IsAllocated)
if (_hOutput.IsAllocated)
_isDisposed = true;
}
}
/// <summary>
/// Copies a number of bytes to the internal codec buffer - ready for proccesing
/// </summary>
/// <param name="data">The byte array that contains the data to copy</param>
/// <param name="startIndex">The index of the first byte to copy</param>
/// <param name="count">The number of bytes to copy from <c>data</c></param>
{
}
/// <summary>
/// Resets the internal output buffers to a known state - ready for processing
/// </summary>
protected void resetOutput()
{
}
/// <summary>
/// Updates the running checksum property
/// </summary>
/// <param name="newSum">The new checksum value</param>
protected void setChecksum(uint newSum)
{
}
}
}