IntCollection: Removed VOID_SaveValue interface and members.
[VOID.git] / IntCollection.cs
blob:a/IntCollection.cs -> blob:b/IntCollection.cs
// //
// IntCollection.cs // IntCollection.cs
// //
// Author: // Author:
// toadicus <> // toadicus <>
// //
// Copyright (c) 2013 toadicus // Copyright (c) 2013 toadicus
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
using System; using System;
   
namespace VOID namespace VOID
{ {
public class IntCollection : IVOID_SaveValue public class IntCollection
{ {
public static implicit operator long(IntCollection c) public static implicit operator long(IntCollection c)
{ {
return c.collection; return c.collection;
} }
   
protected long mask; protected long mask;
   
public long collection { get; protected set; } public long collection { get; protected set; }
public ushort maxCount { get; protected set; } public ushort maxCount { get; protected set; }
public ushort wordLength { get; protected set; } public ushort wordLength { get; protected set; }
   
public Type type { get { return typeof(long); } }  
public object AsType { get { return this.collection; } }  
   
public void SetValue(object v)  
{  
this.collection = (long)v;  
}  
   
public IntCollection (ushort wordLength = 4, long initialCollection = 0) public IntCollection (ushort wordLength = 4, long initialCollection = 0)
{ {
this.collection = initialCollection; this.collection = initialCollection;
this.wordLength = wordLength; this.wordLength = wordLength;
this.maxCount = (ushort)((sizeof(long) * 8 - 1) / wordLength); this.maxCount = (ushort)((sizeof(long) * 8 - 1) / wordLength);
this.mask = ((1 << this.wordLength) - 1); this.mask = ((1 << this.wordLength) - 1);
} }
   
public ushort this[int idx] public ushort this[int idx]
{ {
get { get {
if (idx < 0) { if (idx < 0) {
idx += this.maxCount; idx += this.maxCount;
} }
   
if (idx >= maxCount || idx < 0) { if (idx >= maxCount || idx < 0) {
throw new IndexOutOfRangeException (); throw new IndexOutOfRangeException ();
} }
   
idx *= wordLength; idx *= wordLength;
   
return (ushort)((this.collection & (this.mask << idx)) >> idx); return (ushort)((this.collection & (this.mask << idx)) >> idx);
} }
set { set {
Console.WriteLine (value); Console.WriteLine (value);
if (idx < 0) { if (idx < 0) {
idx += this.maxCount; idx += this.maxCount;
} }
   
if (idx >= maxCount || idx < 0) { if (idx >= maxCount || idx < 0) {
throw new IndexOutOfRangeException (); throw new IndexOutOfRangeException ();
} }
   
idx *= wordLength; idx *= wordLength;
   
long packvalue = value & this.mask; long packvalue = value & this.mask;
Console.WriteLine (packvalue); Console.WriteLine (packvalue);
   
this.collection &= ~(this.mask << idx); this.collection &= ~(this.mask << idx);
this.collection |= packvalue << idx; this.collection |= packvalue << idx;
} }
} }
} }
} }