[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/Generics ReadOnlyCollection.cs,NONE,1
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/Generics ReadOnlyCollection.cs,NONE,1.1 ReadOnlyDeque.cs,NONE,1.1 ReadOnlyDictIterator.cs,NONE,1.1 ReadOnlyDictionary.cs,NONE,1.1 ReadOnlyList.cs,NONE,1.1 ReadOnlyQueue.cs,NONE,1.1 ReadOnlyStack.cs,NONE,1.1 ArrayQueue.cs,1.2,1.3 ArrayStack.cs,1.2,1.3 Generics.txt,1.3,1.4 IStack.cs,1.2,1.3LinkedList.cs,1.4,1.5 |
Date: |
Mon, 24 Feb 2003 01:56:32 -0500 |
Update of /cvsroot/dotgnu-pnet/pnetlib/Generics
In directory subversions:/tmp/cvs-serv5642/Generics
Modified Files:
ArrayQueue.cs ArrayStack.cs Generics.txt IDeque.cs IQueue.cs
IStack.cs LinkedList.cs
Added Files:
ReadOnlyCollection.cs ReadOnlyDeque.cs ReadOnlyDictIterator.cs
ReadOnlyDictionary.cs ReadOnlyList.cs ReadOnlyQueue.cs
ReadOnlyStack.cs
Log Message:
Add read-only wrapper classes, to replace the concrete-specific
"ReadOnly" methods.
--- NEW FILE ---
/*
* ReadOnlyCollection.cs - Wrap a collection to make it read-only.
*
* Copyright (C) 2003 Southern Storm Software, Pty Ltd.
*
* 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
* 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 Generics
{
using System;
public class ReadOnlyCollection<T> : ICollection<T>, ICloneable
{
// Internal state.
protected ICollection<T> coll;
// Constructor.
public ReadOnlyCollection(ICollection<T> coll)
{
if(coll == null)
{
throw new ArgumentNullException("coll");
}
this.coll = coll;
}
// Implement the ICollection<T> interface.
public void CopyTo(T[] array, int index)
{
coll.CopyTo(array, index);
}
public int Count
{
get
{
return coll.Count;
}
}
public bool IsSynchronized
{
get
{
return coll.IsSynchronized;
}
}
public Object SyncRoot
{
get
{
return coll.SyncRoot;
}
}
// Implement the IIterable<T> interface.
public IIterator<T> GetIterator()
{
return new
ReadOnlyIterator<T>(coll.GetIterator());
}
// Implement the ICloneable interface.
public virtual Object Clone()
{
if(coll is ICloneable)
{
return new ReadOnlyCollection<T>
((ICollection<T>)(((ICloneable)coll).Clone()));
}
else
{
throw new InvalidOperationException
(S._("Invalid_NotCloneable"));
}
}
}; // class ReadOnlyCollection<T>
}; // namespace Generics
--- NEW FILE ---
/*
* ReadOnlyDeque.cs - Wrap a deque to make it read-only.
*
* Copyright (C) 2003 Southern Storm Software, Pty Ltd.
*
* 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
* 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 Generics
{
using System;
public class ReadOnlyDeque<T> : ReadOnlyCollection<T>, IDeque<T>
{
// Internal state.
protected IDeque<T> deque;
// Constructor.
public ReadOnlyDeque(IDeque<T> deque) : base(deque)
{
this.deque = deque;
}
// Implement the IDeque<T> interface.
public void PushFront(T value)
{
throw new
InvalidOperationException(S._("NotSupp_ReadOnly"));
}
public void PushBack(T value)
{
throw new
InvalidOperationException(S._("NotSupp_ReadOnly"));
}
public T PopFront()
{
throw new
InvalidOperationException(S._("NotSupp_ReadOnly"));
}
public T PopBack()
{
throw new
InvalidOperationException(S._("NotSupp_ReadOnly"));
}
public T PeekFront()
{
return deque.PeekFront();
}
public T PeekEnd()
{
return deque.PeekEnd();
}
public T[] ToArray()
{
return deque.ToArray();
}
public bool IsFixedSize
{
get
{
return deque.IsFixedSize;
}
}
public bool IsReadOnly
{
get
{
return true;
}
}
// Implement the ICloneable interface.
public override Object Clone()
{
if(deque is ICloneable)
{
return new ReadOnlyDeque<T>
((IDeque<T>)(((ICloneable)deque).Clone()));
}
else
{
throw new InvalidOperationException
(S._("Invalid_NotCloneable"));
}
}
}; // class ReadOnlyDeque<T>
}; // namespace Generics
--- NEW FILE ---
/*
* ReadOnlyDictIterator.cs - Wrap an iterator to make it read-only.
*
* Copyright (C) 2003 Southern Storm Software, Pty Ltd.
*
* 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
* 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 Generics
{
using System;
internal sealed class ReadOnlyDictIterator<KeyT, ValueT>
: IDictionaryIterator<KeyT, ValueT>
{
// Internal state.
protected IDictionaryIterator<KeyT, ValueT> iterator;
// Constructor.
public ReadOnlyDictIterator(IDictionaryIterator<KeyT, ValueT> iterator)
{
this.iterator = iterator;
}
// Implement the IIterator<DictionaryEntry<KeyT, ValueT>> interface.
public bool MoveNext()
{
return iterator.MoveNext();
}
public void Reset()
{
iterator.Reset();
}
public void Remove()
{
throw new
InvalidOperationException(S._("NotSupp_ReadOnly"));
}
public DictionaryEntry<KeyT, ValueT> Current
{
get
{
return iterator.Current;
}
}
// Implement the IDictionaryIterator<KeyT, ValueT> interface.
public DictionaryEntry<KeyT, ValueT> Entry
{
get
{
return iterator.Entry;
}
}
public KeyT Key
{
get
{
return iterator.Key;
}
}
public ValueT Value
{
get
{
return iterator.Value;
}
set
{
throw new InvalidOperationException
(S._("NotSupp_ReadOnly"));
}
}
}; // class ReadOnlyDictIterator<KeyT, ValueT>
}; // namespace Generics
--- NEW FILE ---
/*
* ReadOnlyDictionary.cs - Wrap a dictionary to make it read-only.
*
* Copyright (C) 2003 Southern Storm Software, Pty Ltd.
*
* 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
* 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 Generics
{
using System;
public class ReadOnlyDictionary<KeyT, ValueT>
: ReadOnlyCollection< DictionaryEntry<KeyT, ValueT> >,
IDictionary<KeyT, ValueT>
{
// Internal state.
protected IDictionary<KeyT, ValueT> dict;
// Constructor.
public ReadOnlyDictionary(IDictionary<KeyT, ValueT> dict) : base(dict)
{
this.dict = dict;
}
// Implement the IDictionary<KeyT, ValueT> interface.
public void Add(KeyT key, ValueT value)
{
throw new
InvalidOperationException(S._("NotSupp_ReadOnly"));
}
public void Clear()
{
throw new
InvalidOperationException(S._("NotSupp_ReadOnly"));
}
public bool Contains(KeyT key)
{
return dict.Contains(key);
}
public new IDictionaryIterator<KeyT, ValueT> GetIterator()
{
return new ReadOnlyDictIterator<KeyT, ValueT>
(dict.GetIterator());
}
public void Remove(KeyT key)
{
throw new
InvalidOperationException(S._("NotSupp_ReadOnly"));
}
public bool IsFixedSize
{
get
{
return dict.IsFixedSize;
}
}
public bool IsReadOnly
{
get
{
return true;
}
}
public ValueT this[KeyT key]
{
get
{
return dict[key];
}
set
{
throw new InvalidOperationException
(S._("NotSupp_ReadOnly"));
}
}
public ICollection<KeyT> Keys
{
get
{
return new
ReadOnlyCollection<KeyT>(dict.Keys);
}
}
public ICollection<ValueT> Values
{
get
{
return new
ReadOnlyCollection<ValueT>(dict.Values);
}
}
// Implement the ICloneable interface.
public override Object Clone()
{
if(dict is ICloneable)
{
return new ReadOnlyDictionary<T>
((IDictionary<T>)(((ICloneable)dict).Clone()));
}
else
{
throw new InvalidOperationException
(S._("Invalid_NotCloneable"));
}
}
}; // class ReadOnlyDictionary<KeyT, ValueT>
}; // namespace Generics
--- NEW FILE ---
/*
* ReadOnlyList.cs - Wrap a list to make it read-only.
*
* Copyright (C) 2003 Southern Storm Software, Pty Ltd.
*
* 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
* 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 Generics
{
using System;
public class ReadOnlyList<T> : ReadOnlyCollection<T>, IList<T>
{
// Internal state.
protected IList<T> list;
// Constructor.
public ReadOnlyList(IList<T> list) : base(list)
{
this.list = list;
}
// Implement the IList<T> interface.
public int Add(T value)
{
throw new
InvalidOperationException(S._("NotSupp_ReadOnly"));
}
public void Clear()
{
throw new
InvalidOperationException(S._("NotSupp_ReadOnly"));
}
public bool Contains(T value)
{
return list.Contains(value);
}
public new IListIterator<T> GetIterator()
{
return new
ReadOnlyListIterator<T>(list.GetIterator());
}
public int IndexOf(T value)
{
return list.IndexOf(value);
}
public void Insert(int index, T value)
{
throw new
InvalidOperationException(S._("NotSupp_ReadOnly"));
}
public void Remove(T value)
{
throw new
InvalidOperationException(S._("NotSupp_ReadOnly"));
}
public void RemoveAt(int index)
{
throw new
InvalidOperationException(S._("NotSupp_ReadOnly"));
}
public bool IsFixedSize
{
get
{
return list.IsFixedSize;
}
}
public bool IsReadOnly
{
get
{
return true;
}
}
public T this[int index]
{
get
{
return list[index];
}
set
{
throw new InvalidOperationException
(S._("NotSupp_ReadOnly"));
}
}
// Implement the ICloneable interface.
public override Object Clone()
{
if(list is ICloneable)
{
return new ReadOnlyList<T>
((IDeque<T>)(((ICloneable)list).Clone()));
}
else
{
throw new InvalidOperationException
(S._("Invalid_NotCloneable"));
}
}
}; // class ReadOnlyList<T>
}; // namespace Generics
--- NEW FILE ---
/*
* ReadOnlyQueue.cs - Wrap a queue to make it read-only.
*
* Copyright (C) 2003 Southern Storm Software, Pty Ltd.
*
* 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
* 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 Generics
{
using System;
public class ReadOnlyQueue<T> : ReadOnlyCollection<T>, IQueue<T>
{
// Internal state.
protected IQueue<T> queue;
// Constructor.
public ReadOnlyQueue(IQueue<T> queue) : base(queue)
{
this.queue = queue;
}
// Implement the IQueue<T> interface.
public void Enqueue(T value)
{
throw new
InvalidOperationException(S._("NotSupp_ReadOnly"));
}
public T Dequeue()
{
throw new
InvalidOperationException(S._("NotSupp_ReadOnly"));
}
public T Peek()
{
return queue.Peek();
}
public T[] ToArray()
{
return queue.ToArray();
}
public bool IsFixedSize
{
get
{
return queue.IsFixedSize;
}
}
public bool IsReadOnly
{
get
{
return true;
}
}
// Implement the ICloneable interface.
public override Object Clone()
{
if(queue is ICloneable)
{
return new ReadOnlyQueue<T>
((IQueue<T>)(((ICloneable)queue).Clone()));
}
else
{
throw new InvalidOperationException
(S._("Invalid_NotCloneable"));
}
}
}; // class ReadOnlyQueue<T>
}; // namespace Generics
--- NEW FILE ---
/*
* ReadOnlyStack.cs - Wrap a stack to make it read-only.
*
* Copyright (C) 2003 Southern Storm Software, Pty Ltd.
*
* 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
* 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 Generics
{
using System;
public class ReadOnlyStack<T> : ReadOnlyCollection<T>, IStack<T>
{
// Internal state.
protected IStack<T> stack;
// Constructor.
public ReadOnlyStack(IStack<T> stack) : base(stack)
{
this.stack = stack;
}
// Implement the IStack<T> interface.
public void Push(T value)
{
throw new
InvalidOperationException(S._("NotSupp_ReadOnly"));
}
public T Pop()
{
throw new
InvalidOperationException(S._("NotSupp_ReadOnly"));
}
public T Peek()
{
return stack.Peek();
}
public T[] ToArray()
{
return stack.ToArray();
}
public bool IsFixedSize
{
get
{
return stack.IsFixedSize;
}
}
public bool IsReadOnly
{
get
{
return true;
}
}
// Implement the ICloneable interface.
public override Object Clone()
{
if(stack is ICloneable)
{
return new ReadOnlyStack<T>
((IStack<T>)(((ICloneable)stack).Clone()));
}
else
{
throw new InvalidOperationException
(S._("Invalid_NotCloneable"));
}
}
}; // class ReadOnlyStack<T>
}; // namespace Generics
Index: ArrayQueue.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Generics/ArrayQueue.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** ArrayQueue.cs 24 Feb 2003 04:36:25 -0000 1.2
--- ArrayQueue.cs 24 Feb 2003 06:56:27 -0000 1.3
***************
*** 159,171 ****
}
- // Determine if this queue is read-only.
- public virtual bool IsReadOnly
- {
- get
- {
- return false;
- }
- }
-
// Clear the contents of this queue.
public virtual void Clear()
--- 159,162 ----
***************
*** 296,299 ****
--- 287,304 ----
}
return array;
+ }
+ public virtual bool IsFixedSize
+ {
+ get
+ {
+ return false;
+ }
+ }
+ public virtual bool IsReadOnly
+ {
+ get
+ {
+ return false;
+ }
}
Index: ArrayStack.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Generics/ArrayStack.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** ArrayStack.cs 24 Feb 2003 04:36:26 -0000 1.2
--- ArrayStack.cs 24 Feb 2003 06:56:27 -0000 1.3
***************
*** 124,136 ****
}
- // Determine if this stack is read-only.
- public virtual bool IsReadOnly
- {
- get
- {
- return false;
- }
- }
-
// Clear the contents of this stack.
public virtual void Clear()
--- 124,127 ----
***************
*** 227,230 ****
--- 218,235 ----
}
return array;
+ }
+ public virtual bool IsFixedSize
+ {
+ get
+ {
+ return false;
+ }
+ }
+ public virtual bool IsReadOnly
+ {
+ get
+ {
+ return false;
+ }
}
Index: Generics.txt
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Generics/Generics.txt,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** Generics.txt 24 Feb 2003 04:36:26 -0000 1.3
--- Generics.txt 24 Feb 2003 06:56:27 -0000 1.4
***************
*** 36,39 ****
--- 36,40 ----
Invalid_EmptyList=The requested operation is invalid on an empty list
Invalid_KeyType=Invalid type for dictionary key
+ Invalid_NotCloneable=The specified collection is not cloneable
Invalid_UnderlyingModified=The underlying collection has been modified
Invalid_ValueType=Invalid type for collection value
Index: IDeque.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Generics/IDeque.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** IDeque.cs 24 Feb 2003 05:52:40 -0000 1.1
--- IDeque.cs 24 Feb 2003 06:56:27 -0000 1.2
***************
*** 37,40 ****
--- 37,42 ----
T PeekEnd();
T[] ToArray();
+ bool IsFixedSize { get; }
+ bool IsReadOnly { get; }
}; // interface IDeque<T>
Index: IQueue.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Generics/IQueue.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** IQueue.cs 24 Feb 2003 04:36:26 -0000 1.2
--- IQueue.cs 24 Feb 2003 06:56:27 -0000 1.3
***************
*** 34,37 ****
--- 34,39 ----
T Peek();
T[] ToArray();
+ bool IsFixedSize { get; }
+ bool IsReadOnly { get; }
}; // interface IQueue<T>
Index: IStack.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Generics/IStack.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** IStack.cs 24 Feb 2003 04:36:26 -0000 1.2
--- IStack.cs 24 Feb 2003 06:56:27 -0000 1.3
***************
*** 34,37 ****
--- 34,39 ----
T Peek();
T[] ToArray();
+ bool IsFixedSize { get; }
+ bool IsReadOnly { get; }
}; // interface IStack<T>
Index: LinkedList.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Generics/LinkedList.cs,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** LinkedList.cs 24 Feb 2003 05:52:40 -0000 1.4
--- LinkedList.cs 24 Feb 2003 06:56:27 -0000 1.5
***************
*** 237,240 ****
--- 237,254 ----
return array;
}
+ bool IDeque<T>.IsFixedSize
+ {
+ get
+ {
+ return IsFixedSize;
+ }
+ }
+ bool IDeque<T>.IsReadOnly
+ {
+ get
+ {
+ return IsReadOnly;
+ }
+ }
// Implement the IQueue<T> interface privately.
***************
*** 255,258 ****
--- 269,286 ----
return ToArray();
}
+ bool IQueue<T>.IsFixedSize
+ {
+ get
+ {
+ return IsFixedSize;
+ }
+ }
+ bool IQueue<T>.IsReadOnly
+ {
+ get
+ {
+ return IsReadOnly;
+ }
+ }
// Implement the IStack<T> interface privately.
***************
*** 272,275 ****
--- 300,317 ----
{
return ToArray();
+ }
+ bool IStack<T>.IsFixedSize
+ {
+ get
+ {
+ return IsFixedSize;
+ }
+ }
+ bool IStack<T>.IsReadOnly
+ {
+ get
+ {
+ return IsReadOnly;
+ }
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/Generics ReadOnlyCollection.cs,NONE,1.1 ReadOnlyDeque.cs,NONE,1.1 ReadOnlyDictIterator.cs,NONE,1.1 ReadOnlyDictionary.cs,NONE,1.1 ReadOnlyList.cs,NONE,1.1 ReadOnlyQueue.cs,NONE,1.1 ReadOnlyStack.cs,NONE,1.1 ArrayQueue.cs,1.2,1.3 ArrayStack.cs,1.2,1.3 Generics.txt,1.3,1.4 IStack.cs,1.2,1.3LinkedList.cs,1.4,1.5,
Rhys Weatherley <address@hidden> <=