Visualization Library 2.0.0-b5

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
ChecksumImpl.cs
Go to the documentation of this file.
1 //
2 // © Copyright Henrik Ravn 2004
3 //
4 // Use, modification and distribution are subject to the Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 
8 using System;
9 using System.Runtime.InteropServices;
10 using System.Text;
11 
12 
13 namespace DotZLib
14 {
15  #region ChecksumGeneratorBase
16  public abstract class ChecksumGeneratorBase : ChecksumGenerator
21  {
25  protected uint _current;
26 
32  {
33  _current = 0;
34  }
35 
40  public ChecksumGeneratorBase(uint initialValue)
41  {
42  _current = initialValue;
43  }
44 
48  public void Reset() { _current = 0; }
49 
53  public uint Value { get { return _current; } }
54 
66  public abstract void Update(byte[] data, int offset, int count);
67 
72  public void Update(byte[] data)
73  {
74  Update(data, 0, data.Length);
75  }
76 
82  public void Update(string data)
83  {
84  Update(Encoding.UTF8.GetBytes(data));
85  }
86 
92  public void Update(string data, Encoding encoding)
93  {
94  Update(encoding.GetBytes(data));
95  }
96 
97  }
98  #endregion
99 
100  #region CRC32
101  public sealed class CRC32Checksum : ChecksumGeneratorBase
105  {
106  #region DLL imports
107 
108  [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)]
109  private static extern uint crc32(uint crc, int data, uint length);
110 
111  #endregion
112 
116  public CRC32Checksum() : base() {}
117 
122  public CRC32Checksum(uint initialValue) : base(initialValue) {}
123 
133  public override void Update(byte[] data, int offset, int count)
134  {
135  if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException();
136  if ((offset+count) > data.Length) throw new ArgumentException();
137  GCHandle hData = GCHandle.Alloc(data, GCHandleType.Pinned);
138  try
139  {
140  _current = crc32(_current, hData.AddrOfPinnedObject().ToInt32()+offset, (uint)count);
141  }
142  finally
143  {
144  hData.Free();
145  }
146  }
147 
148  }
149  #endregion
150 
151  #region Adler
152  public sealed class AdlerChecksum : ChecksumGeneratorBase
156  {
157  #region DLL imports
158 
159  [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)]
160  private static extern uint adler32(uint adler, int data, uint length);
161 
162  #endregion
163 
167  public AdlerChecksum() : base() {}
168 
173  public AdlerChecksum(uint initialValue) : base(initialValue) {}
174 
184  public override void Update(byte[] data, int offset, int count)
185  {
186  if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException();
187  if ((offset+count) > data.Length) throw new ArgumentException();
188  GCHandle hData = GCHandle.Alloc(data, GCHandleType.Pinned);
189  try
190  {
191  _current = adler32(_current, hData.AddrOfPinnedObject().ToInt32()+offset, (uint)count);
192  }
193  finally
194  {
195  hData.Free();
196  }
197  }
198 
199  }
200  #endregion
201 
202 }
Implements a CRC32 checksum generator
GLenum GLuint GLenum GLsizei length
override void Update(byte[] data, int offset, int count)
Updates the current checksum with part of an array of bytes
AdlerChecksum()
Initializes a new instance of the Adler checksum generator
unsigned char byte
Definition: tif_acorn.c:69
abstract void Update(byte[] data, int offset, int count)
Updates the current checksum with part of an array of bytes
void Update(string data, Encoding encoding)
Updates the current checksum with the data from a string, using a specific encoding ...
Definition: ChecksumImpl.cs:92
ChecksumGeneratorBase()
Initializes a new instance of the checksum generator base - the current checksum is set to zero ...
Definition: ChecksumImpl.cs:31
unsigned int uint
Definition: gzlog.c:242
void Update(byte[] data)
Updates the current checksum with an array of bytes.
Definition: ChecksumImpl.cs:72
override void Update(byte[] data, int offset, int count)
Updates the current checksum with part of an array of bytes
void Reset()
Resets the current checksum to zero
Definition: ChecksumImpl.cs:48
CRC32Checksum(uint initialValue)
Initializes a new instance of the CRC32 checksum generator with a specified value ...
GLsizei GLsizei GLenum GLenum const GLvoid * data
uint Value
Gets the current checksum value
Definition: ChecksumImpl.cs:53
CRC32Checksum()
Initializes a new instance of the CRC32 checksum generator
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
Definition: crc32.c:204
void Update(string data)
Updates the current checksum with the data from a string
Definition: ChecksumImpl.cs:82
uint _current
The value of the current checksum
Definition: ChecksumImpl.cs:25
Implements the common functionality needed for all ChecksumGenerators
Definition: ChecksumImpl.cs:20
GLintptr offset
Declares methods and properties that enables a running checksum to be calculated
Definition: DotZLib.cs:114
Implements a checksum generator that computes the Adler checksum on data
ChecksumGeneratorBase(uint initialValue)
Initializes a new instance of the checksum generator basewith a specified value
Definition: ChecksumImpl.cs:40
GLuint GLuint GLsizei count
AdlerChecksum(uint initialValue)
Initializes a new instance of the Adler checksum generator with a specified value ...
uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
Definition: adler32.c:65