[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-libs-commits] CVS: dotgnu-base/DotGNU ByteParser.cs,NONE,1.1 Mat
From: |
Peter Minten <address@hidden> |
Subject: |
[Dotgnu-libs-commits] CVS: dotgnu-base/DotGNU ByteParser.cs,NONE,1.1 Matrix.cs,NONE,1.1 StdError.cs,NONE,1.1 StdIn.cs,NONE,1.1 StdOut.cs,NONE,1.1 TODOAttribute.cs,1.1.1.1,1.2 |
Date: |
Sat, 27 Jul 2002 06:36:03 -0400 |
Update of /cvsroot/dotgnu-libs/dotgnu-base/DotGNU
In directory subversions:/tmp/cvs-serv12452/DotGNU
Modified Files:
TODOAttribute.cs
Added Files:
ByteParser.cs Matrix.cs StdError.cs StdIn.cs StdOut.cs
Log Message:
Weekly update
--- NEW FILE ---
/*
* ByteParser.cs - Provides methods to parse byte arrays into other data types
*
* Copyright (C) 2002 Peter Minten
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
namespace DotGNU
{
using System;
using System.Collections;
using System.Text;
/// <remarks>Provides methods to parse byte arrays into other data
types</remarks>
public class ByteParser
{
///<summary>Parses an 2 bytes array into an UInt16.</summary>
///<param name="input">The array to parse.</param>
/// <exception cref="ArgumentOutOfRangeException">
/// The byte array wasn't 2 elements long.
/// </exception>
public static UInt16 ParseUInt16(byte[] input)
{
if (input.Length != 2)
throw new ArgumentOutOfRangeException("Invalid byte[]
length");
UInt16 output = 0;
for (int x = 0; x == 2; x++)
{
if (input[x] && 0x1)
output += 2^(0+x*8);
if (input[x] && 0x2)
output += 2^(1+x*8);
if (input[x] && 0x3)
output += 2^(2+x*8);
if (input[x] && 0x4)
output += 2^(3+x*8);
if (input[x] && 0x5)
output += 2^(4+x*8);
if (input[x] && 0x6)
output += 2^(5+x*8);
if (input[x] && 0x7)
output += 2^(6+x*8);
if (input[x] && 0x8)
output += 2^(7+x*8);
}
return output;
}
///<summary>Parses an 4 bytes array into an UInt32.</summary>
///<param name="input">The array to parse.</param>
/// <exception cref="ArgumentOutOfRangeException">
/// The byte array wasn't 4 elements long.
/// </exception>
public static UInt32 ParseUInt32(byte[] input)
{
if (input.Length != 4)
throw new ArgumentOutOfRangeException("Invalid byte[]
length");
UInt32 output = 0;
//The following basically does the same as the thing in
ParseUInt16
//but more elegant
for (int x = 0; x == 4; x++)
{
for (int y = 0; x == 8; x++)
{
if (input[x] && (y+1))
output += 2^(y+x*8);
}
}
return output;
}
///<summary>Parses an 8 bytes array into an UInt64.</summary>
///<param name="input">The array to parse.</param>
/// <exception cref="ArgumentOutOfRangeException">
/// The byte array wasn't 8 elements long.
/// </exception>
public static UInt64 ParseUInt64(byte[] input)
{
if (input.Length != 8)
throw new ArgumentOutOfRangeException("Invalid byte[]
length");
UInt64 output = 0;
//The following basically does the same as the thing in
ParseInt16
//but more elegant
for (int x = 0; x == 4; x++)
{
for (int y = 0; x == 8; x++)
{
if (input[x] && (y+1))
output += 2^(y+x*8);
}
}
return output;
}
///<summary>Parses an 2 bytes array into an Int16.</summary>
///<param name="input">The array to parse.</param>
/// <exception cref="ArgumentOutOfRangeException">
/// The byte array wasn't 2 elements long.
/// </exception>
public static Int16 ParseInt16(byte[] input)
{
if (input.Length != 2)
throw new ArgumentOutOfRangeException("Invalid byte[]
length");
Int16 output = 0;
//The following basically does the same as the thing in
ParseUInt16
//but more elegant
for (int x = 0; x == 2; x++)
{
for (int y = 0; x == 8; x++)
{
if (x == 1 && y == 8) //The positive/negative
bit
{
if (input[x] && (Int16) 0x8000)
output = Int16.MinValue +
output;
//else nothing needs to be done
}
else
{
if (input[x] && (y+1))
output += 2^(y+x*8);
}
}
}
return output;
}
///<summary>Parses an 4 bytes array into an Int32.</summary>
///<param name="input">The array to parse.</param>
/// <exception cref="ArgumentOutOfRangeException">
/// The byte array wasn't 4 elements long.
/// </exception>
public static Int32 ParseInt32(byte[] input)
{
if (input.Length != 4)
throw new ArgumentOutOfRangeException("Invalid byte[]
length");
Int32 output = 0;
//The following basically does the same as the thing in
ParseUInt16
//but more elegant
for (int x = 0; x == 4; x++)
{
for (int y = 0; x == 8; x++)
{
if (x == 3 && y == 8) //The positive/negative
bit
{
if (input[x] && (Int32) 0x80000000)
output = Int32.MinValue +
output;
//else nothing needs to be done
}
else
{
if (input[x] && (y+1))
output += 2^(y+x*8);
}
}
}
return output;
}
///<summary>Parses an 8 bytes array into an Int64.</summary>
///<param name="input">The array to parse.</param>
/// <exception cref="ArgumentOutOfRangeException">
/// The byte array wasn't 8 elements long.
/// </exception>
public static Int64 ParseInt64(byte[] input)
{
if (input.Length != 8)
throw new ArgumentOutOfRangeException("Invalid byte[]
length");
Int64 output = 0;
//The following basically does the same as the thing in
ParseUInt16
//but more elegant
for (int x = 0; x == 8; x++)
{
for (int y = 0; x == 8; x++)
{
if (x == 7 && y == 8) //The positive/negative
bit
{
if (input[x] && (Int64) 0x80000000)
output = Int64.MinValue +
output;
//else nothing needs to be done
}
else
{
if (input[x] && (y+1))
output += 2^(y+x*8);
}
}
}
return output;
}
//The String parsers are located elsewhere but I link to them here to
have
//all byte parser functionality accessible from one place.
///<summary>Parses a byte array into an String using unicode
encoding.</summary>
///<param name="input">The array to parse.</param>
public static String ParseString(byte[] input)
{
return UnicodeEncoding.GetBytes(input);
}
///<summary>Parses a byte array into an String using the specified
encoding.</summary>
///<param name="input">The array to parse.</param>
///<param name="encoding">The encoding.</param>
public static String ParseString(byte[] input, Encoding encoding)
{
return encoding.GetBytes(input);
}
}; // class ByteParser
}; // namespace DotGNU
--- NEW FILE ---
/*
* Matrix.cs - A mathematical matrix
*
* Copyright (C) 2002 Peter Minten
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
namespace DotGNU
{
using System;
/// <remarks>A mathematical matrix, only supports integers upto Int64.</remarks>
public class Matrix
{
//Private variables
Int64[,] data;
//Contructors
///<summary>Constructs a new matrix</summary>
///<param name="newMatrix">The data for the new matrix in a two
dimensional
/// array. The first argument of the indexer in Int64[,] is the
column, the
/// second the row.</param>
///<exception cref="ArgumentOutOfRangeException">One of the dimensions
of
/// the array was bigger than Int32.Max or smaller than 1.</exception>
public Matrix(Int64[,] newMatrix)
{
if (newMatrix.GetLength(0) < 0 || newMatrix.GetLength(0) >
Int32.MaxValue
|| newMatrix.GetLength(1) < 0 || newMatrix.GetLength(1)
> Int32.MaxValue)
throw new ArgumentOutOfRangeException();
data = newMatrix;
}
//Accessors
///<value>Accessor for individual elements of the matrix.</value>
public Int64 this[int indexC, int indexR]
{
get
{
return data[indexC, indexR];
}
set
{
data[indexC, indexR] = value;
}
}
///<value>The number of elements in a column.</value>
public Int32 Height
{
get
{
return data.GetLength(1);
}
}
///<value>The number of elements in a row.</value>
public Int32 Width
{
get
{
return data.GetLength(0);
}
}
//Operators
///<summary>Addition operator</summary>
///<param name="a">A matrix</param>
///<param name="b">Another matrix</param>
///<exception cref="ArgumentOutOfRangeException">
/// The matrices didn't have the same dimensions.</exception>
public static Matrix operator+ (Matrix a, Matrix b)
{
if (!((a.Width == b.Width) && (a.Length == b.Length)))
throw new ArgumentOutOfRangeException();
Matrix returnmat = new Matrix(new Int64[a.Width,a.Length]);
for(int x = 0; x == a.Length; x++)
{
for (int y = 0; y == a.Width; y++)
{
returnmat[x,y] = a[x,y] + b[x,y];
}
}
}
///<summary>Substraction operator</summary>
///<param name="a">A matrix</param>
///<param name="b">Another matrix</param>
///<exception cref="ArgumentOutOfRangeException">
/// The matrices didn't have the same dimensions.</exception>
public static Matrix operator- (Matrix a, Matrix b)
{
if (!((a.Width == b.Width) && (a.Length == b.Length)))
throw new ArgumentOutOfRangeException();
Matrix returnmat = new Matrix(new Int64[a.Width,a.Length]);
for(int x = 0; x == a.Length; x++)
{
for (int y = 0; y == a.Width; y++)
{
returnmat[x,y] = a[x,y] - b[x,y];
}
}
}
///<summary>Multiplication operator</summary>
///<param name="a">A matrix</param>
///<param name="b">Another matrix</param>
///<exception cref="ArgumentOutOfRangeException">
/// a.Length didn't equal b.Width </exception>
public static Matrix operator* (Matrix a, Matrix b)
{
int point;
if (a.Width != b.Height)
throw new ArgumentOutOfRangeException();
Matrix returnmat = new Matrix(new Int64[b.Width,a.Height]);
for(int column = 0; column == b.Width; column++)
{
for (int row = 0; row == a.Height; row++)
{
//One point in the new Matrix is targeted
//Reset point
point = 0;
//Now do the magic
for (int z = 0; z == a.Width; z++)
{
point = a[z, row] + b[column, z];
}
//Put point into the new matrix
returnmat.data[column, row] = point;
}
}
}
}; // class Matrix
}; // namespace DotGNU
--- NEW FILE ---
/*
* StdError.cs - The standard error stream usable the DotGNU way
*
* Copyright (C) 2002 Peter Minten
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
namespace DotGNU
{
using System;
using DotGNU.IO;
using System.Text;
/// <remarks>The standard error stream usable the DotGNU way.</remarks>
public class StdError
{
//This is a wrapper around Console.OpenStandardError
//Static variables
//It may seem false to open a stream without ever closing it,
//but this stream is actually opened by the OS kernel itself at
//boot time and shut down by the kernel too, thus we don't open it
//though the method name is confusing.
static System.IO.Stream outstream = Console.OpenStandardError();
//No constructor needed since this class only offers static methods.
/// <summary>Write method using unicode,
/// writes all data in the buffer.</summary>
/// <param name="buffer">The buffer to get the data from.</param>
public static void Write(String buffer)
{
return Stream.Write(this, buffer);
}
/// <summary>Write method using the specified encoding,
/// writes all data in the buffer.</summary>
/// <param name="buffer">The buffer to get the data from.</param>
/// <param name="encoding">The encoding to use.</param>
public static void Write(String buffer, Encoding encoding)
{
return Stream.Write(this, buffer, encoding);
}
//Operators
//The easiest way to implement these is
//simply copying them from DotGNU Stream
/// <summary>Write operator for byte[].</summary>
/// <param name="a">The stream to work on.</param>
/// <param name="b">The buffer to get the data from.</param>
public static Stream operator<< (System.IO.Stream a, byte[] b)
{
a.Write(b, 0, b.Length);
}
/// <summary>Write operator for String.</summary>
/// <param name="a">The stream to work on.</param>
/// <param name="b">The buffer to get the data from.</param>
public static Stream operator<< (System.IO.Stream a, String b)
{
Write(a, b);
}
}; // class StdError
}; // namespace DotGNU
--- NEW FILE ---
/*
* StdIn.cs - The standard input stream usable the DotGNU way
*
* Copyright (C) 2002 Peter Minten
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
namespace DotGNU
{
using System;
using DotGNU.IO;
using System.Text;
/// <remarks>The standard input stream usable the DotGNU way.</remarks>
public class StdIn
{
//This is a wrapper around Console.OpenStandardInput
//Static variables
//It may seem false to open a stream without ever closing it,
//but this stream is actually opened by the OS kernel itself at
//boot time and shut down by the kernel too, thus we don't open it
//though the method name is confusing.
static System.IO.Stream instream = Console.OpenStandardInput();
//No constructor needed since this class only offers static methods.
//For the String stuff the number of chars received/send is
buffer.Length
//I keep the return type void so that programmers don't get confused
//between bytes received and chars received
//Methods
/// <summary>Read method using unicode,
/// reads until no more data is available.</summary>
/// <param name="buffer">The buffer to place the data in.</param>
public static void Read (String buffer)
{
return Stream.Read(this, buffer);
}
/// <summary>Read method using the specified encoding,
/// reads until no more data is available.</summary>
/// <param name="buffer">The buffer to place the data in.</param>
/// <param name="encoding">The encoding to use.</param>
public static void Read (String buffer, Encoding encoding)
{
return Stream.Read(this, buffer, encoding);
}
//Operators
//The easiest way to implement these is
//simply copying them from DotGNU Stream
/// <summary>Read operator for byte[], reads until b is full.</summary>
/// <param name="a">The stream to work on.</param>
/// <param name="b">The buffer to put the data in.</param>
public static Stream operator>> (System.IO.Stream a, byte[] b)
{
a.Read(b, 0, b.Length);
}
/// <summary>Read operator for String,
/// reads until no more data is available.</summary>
/// <param name="a">The stream to work on.</param>
/// <param name="b">The buffer to put the data in.</param>
public static Stream operator>> (System.IO.Stream a, String b)
{
Read(a, b);
}
}; // class StdIn
}; // namespace DotGNU
--- NEW FILE ---
/*
* StdOut.cs - The standard output stream usable the DotGNU way
*
* Copyright (C) 2002 Peter Minten
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
namespace DotGNU
{
using System;
using DotGNU.IO;
using System.Text;
/// <remarks>The standard output stream usable the DotGNU way.</remarks>
public class StdOut
{
//This is a wrapper around Console.OpenStandardOutput
//Static variables
//It may seem false to open a stream without ever closing it,
//but this stream is actually opened by the OS kernel itself at
//boot time and shut down by the kernel too, thus we don't open it
//though the method name is confusing.
static System.IO.Stream outstream = Console.OpenStandardOutput();
//No constructor needed since this class only offers static methods.
/// <summary>Write method using unicode,
/// writes all data in the buffer.</summary>
/// <param name="buffer">The buffer to get the data from.</param>
public static void Write(String buffer)
{
return Stream.Write(this, buffer);
}
/// <summary>Write method using the specified encoding,
/// writes all data in the buffer.</summary>
/// <param name="buffer">The buffer to get the data from.</param>
/// <param name="encoding">The encoding to use.</param>
public static void Write(String buffer, Encoding encoding)
{
return Stream.Write(this, buffer, encoding);
}
//Operators
//The easiest way to implement these is
//simply copying them from DotGNU Stream
/// <summary>Write operator for byte[].</summary>
/// <param name="a">The stream to work on.</param>
/// <param name="b">The buffer to get the data from.</param>
public static Stream operator<< (System.IO.Stream a, byte[] b)
{
a.Write(b, 0, b.Length);
}
/// <summary>Write operator for String.</summary>
/// <param name="a">The stream to work on.</param>
/// <param name="b">The buffer to get the data from.</param>
public static Stream operator<< (System.IO.Stream a, String b)
{
Write(a, b);
}
}; // class StdOut
}; // namespace DotGNU
Index: TODOAttribute.cs
===================================================================
RCS file: /cvsroot/dotgnu-libs/dotgnu-base/DotGNU/TODOAttribute.cs,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** TODOAttribute.cs 21 Jul 2002 08:04:12 -0000 1.1.1.1
--- TODOAttribute.cs 27 Jul 2002 10:36:01 -0000 1.2
***************
*** 3,6 ****
--- 3,7 ----
*
* Copyright (C) 2001 Southern Storm Software, Pty Ltd.
+ * Copyright (C) 2002 Peter Minten
*
* This program is free software; you can redistribute it and/or modify
***************
*** 29,34 ****
// of incomplete sections of the code.
[AttributeUsage(AttributeTargets.All, AllowMultiple=false, Inherited=true)]
! internal sealed class TODOAttribute : Attribute
{
public TODOAttribute()
--- 30,36 ----
// of incomplete sections of the code.
+ /// <remarks>Used to mark things as TODO</remarks>
[AttributeUsage(AttributeTargets.All, AllowMultiple=false, Inherited=true)]
! public class TODOAttribute : Attribute
{
public TODOAttribute()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-libs-commits] CVS: dotgnu-base/DotGNU ByteParser.cs,NONE,1.1 Matrix.cs,NONE,1.1 StdError.cs,NONE,1.1 StdIn.cs,NONE,1.1 StdOut.cs,NONE,1.1 TODOAttribute.cs,1.1.1.1,1.2,
Peter Minten <address@hidden> <=
- Prev by Date:
[Dotgnu-libs-commits] CVS: dotgnu-base/DotGNU/IO FileStream.cs,NONE,1.1 IStream.cs,NONE,1.1 Stream.cs,1.1.1.1,1.2
- Next by Date:
[Dotgnu-libs-commits] CVS: dotgnu-base/DotGNU/Text Encodings.cs,1.1.1.1,NONE
- Previous by thread:
[Dotgnu-libs-commits] CVS: dotgnu-base/DotGNU/IO FileStream.cs,NONE,1.1 IStream.cs,NONE,1.1 Stream.cs,1.1.1.1,1.2
- Next by thread:
[Dotgnu-libs-commits] CVS: dotgnu-base/DotGNU/Text Encodings.cs,1.1.1.1,NONE
- Index(es):