The rectangle packers now throw a proper exception when there is no more space available; Moved interface implementations of the TransformingReadOnlyCollection into a separate file to keep the main body of the class readable

git-svn-id: file:///srv/devel/repo-conversion/nusu@40 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
Markus Ewald 2007-07-16 20:09:51 +00:00
parent acbb07d6b5
commit fba9d87e65
10 changed files with 538 additions and 424 deletions

View File

@ -86,6 +86,11 @@
<XNAUseContentPipeline>false</XNAUseContentPipeline>
<Name>TransformingReadOnlyCollection</Name>
</Compile>
<Compile Include="Source\Collections\TransformingReadOnlyCollection.Interfaces.cs">
<XNAUseContentPipeline>false</XNAUseContentPipeline>
<Name>TransformingReadOnlyCollection.Interfaces</Name>
<DependentUpon>TransformingReadOnlyCollection.cs</DependentUpon>
</Compile>
<Compile Include="Source\Collections\UnintrusivePriorityQueue.cs">
<XNAUseContentPipeline>false</XNAUseContentPipeline>
<Name>UnintrusivePriorityQueue</Name>
@ -152,6 +157,10 @@
<Name>CygonRectanglePacker.Test</Name>
<DependentUpon>CygonRectanglePacker.cs</DependentUpon>
</Compile>
<Compile Include="Source\Packing\OutOfSpaceException.cs">
<XNAUseContentPipeline>false</XNAUseContentPipeline>
<Name>OutOfSpaceException</Name>
</Compile>
<Compile Include="Source\Packing\RectanglePacker.cs">
<XNAUseContentPipeline>false</XNAUseContentPipeline>
<Name>RectanglePacker</Name>

View File

@ -17,6 +17,7 @@ You should have received a copy of the IBM Common Public
License along with this library
*/
#endregion
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@ -98,7 +99,7 @@ namespace Nuclex.Support.Collections {
/// <summary>Called when the collection is being cleared</summary>
/// <remarks>
/// Instead of called the OnRemoved() method for each item in the collection when
/// Instead of calling the OnRemoved() method for each item in the collection when
/// it is being cleared, this variant only triggers the OnClearing() method
/// to allow the implementer some room for optimizations.
/// </remarks>

View File

@ -26,14 +26,6 @@ namespace Nuclex.Support.Collections {
/// <typeparam name="ParentType">Type of the parent object</typeparam>
public class Parentable<ParentType> {
/// <summary>Assigns a new parent to this instance</summary>
internal void SetParent(ParentType parent) {
ParentType oldParent = this.parent;
this.parent = parent;
OnParentChanged(oldParent);
}
/// <summary>The parent object that owns this instance</summary>
protected ParentType Parent {
get { return this.parent; }
@ -48,6 +40,14 @@ namespace Nuclex.Support.Collections {
/// <param name="oldParent">Previous owner of the instance</param>
protected virtual void OnParentChanged(ParentType oldParent) { }
/// <summary>Assigns a new parent to this instance</summary>
protected internal void SetParent(ParentType parent) {
ParentType oldParent = this.parent;
this.parent = parent;
OnParentChanged(oldParent);
}
/// <summary>Current parent of this object</summary>
private ParentType parent;

View File

@ -47,32 +47,37 @@ namespace Nuclex.Support.Collections {
/// <summary>Called when an item has been added to the collection</summary>
/// <param name="item">Item that has been added to the collection</param>
protected virtual void OnAdded(ItemType item) {
protected override void OnAdded(ItemType item) {
item.SetParent(this.parent);
}
/// <summary>Called when an item has been removed from the collection</summary>
/// <param name="item">Item that has been removed from the collection</param>
protected virtual void OnRemoved(ItemType item) {
protected override void OnRemoved(ItemType item) {
item.SetParent(default(ParentType));
}
/// <summary>Disposes the collection and optionally all items contained therein</summary>
/// <summary>Called when the collection is being cleared</summary>
protected override void OnClearing() {
// Unset the parent of all objects before allowing the list to be emptied
for(int index = 0; index < base.Count; ++index)
base[index].SetParent(default(ParentType));
}
/// <summary>Disposes all items contained in the collection</summary>
/// <remarks>
/// <para>
/// This method is intended to support collections that need to dispose of their
/// items. The ParentingCollection will first detach all items from the parent
/// object and then call Dispose() on any item that implements IDisposable.
/// This method is intended to support collections that need to dispose their
/// items. It will unparent all of the collections items and call Dispose()
/// on any item that implements IDisposable.
/// </para>
/// <para>
/// The items contained in the collection are not disconnected from their parent
/// (eg. Reparent()ed to null) because this is out of the scope for the
/// ParentingCollection&lt;&gt; class to decide and provokes the potentially
/// risky situation that an item, when it is Dispose()d, might try to disconnect
/// some events or perform other maintenance work on its parent object that
/// would then be no longer available. If you wish to disconnect the items from
/// their parent prior to disposing them, add a Reparent(null); call before the
/// line with InternalDispose(true); in your custom Dispose() method.
/// Do not call this method during a GC run (eg. from your destructor) as it
/// will access the contained items in order to unparent and to Dispose() them,
/// which leads to undefined behavior since the object might have already been
/// collected by the GC.
/// </para>
/// </remarks>
protected void DisposeItems() {

View File

@ -0,0 +1,434 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
This library 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
IBM Common Public License for more details.
You should have received a copy of the IBM Common Public
License along with this library
*/
#endregion
using System;
using System.Threading;
using System.Collections;
using System.Collections.Generic;
namespace Nuclex.Support.Collections {
// More than 400 lines of code just to implement the .NET collection interfaces.
// Shows the niceties of having to support languages without generics and using
// an inferior design to make collections "more convenient" for the user :/
partial class TransformingReadOnlyCollection<
ContainedItemType, ExposedItemType
> {
#region IList<ExposedItemType> Members
/// <summary>
/// Determines the index of a specific item in the TransformingReadOnlyCollection.
/// </summary>
/// <param name="item">
/// The object to locate in the TransformingReadOnlyCollection.
/// </param>
/// <returns>
/// The index of item if found in the list; otherwise, -1.
/// </returns>
int IList<ExposedItemType>.IndexOf(ExposedItemType item) {
return IndexOf(item);
}
/// <summary>
/// Inserts an item to the TransformingReadOnlyCollection at the specified index.
/// </summary>
/// <param name="index">
/// The zero-based index at which item should be inserted.
/// </param>
/// <param name="item">
/// The object to insert into the TransformingReadOnlyCollection
/// </param>
/// <exception cref="System.NotSupportedException">
/// The TransformingReadOnlyCollection is read-only.
/// </exception>
/// <exception cref="System.ArgumentOutOfRangeException">
/// index is not a valid index in the TransformingReadOnlyCollection.
/// </exception>
void IList<ExposedItemType>.Insert(int index, ExposedItemType item) {
throw new NotSupportedException("The collection is ready-only");
}
/// <summary>
/// Removes the TransformingReadOnlyCollection item at the specified index.
/// </summary>
/// <param name="index">The zero-based index of the item to remove.</param>
/// <exception cref="System.NotSupportedException">
/// The TransformingReadOnlyCollection is read-only.
/// </exception>
/// <exception cref="System.ArgumentOutOfRangeException">
/// Index is not a valid index in the TransformingReadOnlyCollection.
/// </exception>
void IList<ExposedItemType>.RemoveAt(int index) {
throw new NotSupportedException("The collection is ready-only");
}
/// <summary>Gets or sets the element at the specified index.</summary>
/// <param name="index">The zero-based index of the element to get or set.</param>
/// <returns>The element at the specified index.</returns>
/// <exception cref="System.ArgumentOutOfRangeException">
/// Index is not a valid index in the TransformingReadOnlyCollection.
/// </exception>
/// <exception cref="System.NotSupportedException">
/// The property is set and the TransformingReadOnlyCollection is read-only
/// </exception>
ExposedItemType IList<ExposedItemType>.this[int index] {
get {
return this[index];
}
set {
throw new NotSupportedException("The collection is ready-only");
}
}
#endregion
#region ICollection<ExposedItemType> Members
/// <summary>Adds an item to the TransformingReadOnlyCollection.</summary>
/// <param name="item">The object to add to the TransformingReadOnlyCollection</param>
/// <exception cref="System.NotSupportedException">
/// The TransformingReadOnlyCollection is read-only.
/// </exception>
void ICollection<ExposedItemType>.Add(ExposedItemType item) {
throw new NotSupportedException("The collection is ready-only");
}
/// <summary>Removes all items from the TransformingReadOnlyCollection</summary>
/// <exception cref="System.NotSupportedException">
/// The TransformingReadOnlyCollection is read-only.
/// </exception>
void ICollection<ExposedItemType>.Clear() {
throw new NotSupportedException("The collection is ready-only");
}
/// <summary>
/// Determines whether the TransformingReadOnlyCollection contains a specific value.
/// </summary>
/// <param name="item">
/// The object to locate in the TransformingReadOnlyCollection.
/// </param>
/// <returns>
/// True if item is found in the TransformingReadOnlyCollection; otherwise, false.
/// </returns>
bool ICollection<ExposedItemType>.Contains(ExposedItemType item) {
return Contains(item);
}
/// <summary>
/// Copies the elements of the TransformingReadOnlyCollection to an System.Array,
/// starting at a particular System.Array index.
/// </summary>
/// <param name="array">
/// The one-dimensional System.Array that is the destination of the elements
/// copied from TransformingReadOnlyCollection. The System.Array must have
/// zero-based indexing.
/// </param>
/// <param name="arrayIndex">
/// The zero-based index in array at which copying begins
/// </param>
/// <exception cref="System.ArgumentOutOfRangeException">
/// ArrayIndex is less than 0.
/// </exception>
/// <exception cref="System.ArgumentNullException">
/// Array is null.
/// </exception>
/// <exception cref="System.ArgumentException">
/// Array is multidimensional or arrayIndex is equal to or greater than the
/// length of array or the number of elements in the source
/// TransformingReadOnlyCollection is greater than the available
/// space from arrayIndex to the end of the destination array or type T cannot
/// be cast automatically to the type of the destination array.
/// </exception>
void ICollection<ExposedItemType>.CopyTo(ExposedItemType[] array, int arrayIndex) {
CopyTo(array, arrayIndex);
}
/// <summary>
/// Removes the first occurrence of a specific object from the
/// TransformingReadOnlyCollection.
/// </summary>
/// <param name="item">
/// The object to remove from the TransformingReadOnlyCollection
/// </param>
/// <returns>
/// True if item was successfully removed from the TransformingReadOnlyCollection;
/// otherwise, false. This method also returns false if item is not found in the
/// original TransformingReadOnlyCollection.
/// </returns>
/// <exception cref="System.NotSupportedException">
/// The TransformingReadOnlyCollection is read-only.
/// </exception>
bool ICollection<ExposedItemType>.Remove(ExposedItemType item) {
throw new NotSupportedException("The collection is ready-only");
}
/// <summary>
/// The number of elements contained in the TransformingReadOnlyCollection.
/// </summary>
int ICollection<ExposedItemType>.Count {
get { return Count; }
}
/// <summary>
/// A value indicating whether the TransformingReadOnlyCollection is read-only.
/// </summary>
bool ICollection<ExposedItemType>.IsReadOnly {
get { return true; }
}
#endregion
#region IEnumerable<ExposedItemType> Members
/// <summary>Returns an enumerator that iterates through the collection.</summary>
/// <returns>
/// A System.Collections.Generic.IEnumerator&lt;ExposedItemType&gt; that can be used
/// to iterate through the collection.
/// </returns>
IEnumerator<ExposedItemType> IEnumerable<ExposedItemType>.GetEnumerator() {
return GetEnumerator();
}
#endregion
#region IEnumerable Members
/// <summary>Returns an enumerator that iterates through a collection.</summary>
/// <returns>
/// A System.Collections.IEnumerator object that can be used to iterate through
/// the collection.
/// </returns>
IEnumerator IEnumerable.GetEnumerator() {
return GetEnumerator();
}
#endregion
#region IList Members
/// <summary>Adds an item to the TransformingReadOnlyCollection.</summary>
/// <param name="value">
/// The System.Object to add to the TransformingReadOnlyCollection.
/// </param>
/// <returns>The position into which the new element was inserted.</returns>
/// <exception cref="System.NotSupportedException">
/// The System.Collections.IList is read-only or the TransformingReadOnlyCollection
/// has a fixed size.
/// </exception>
int IList.Add(object value) {
throw new NotSupportedException("The collection is ready-only");
}
/// <summary>Removes all items from the TransformingReadOnlyCollection.</summary>
/// <exception cref="System.NotSupportedException">
/// The TransformingReadOnlyCollection is read-only.
/// </exception>
void IList.Clear() {
throw new NotSupportedException("The collection is ready-only");
}
/// <summary>
/// Determines whether the TransformingReadOnlyCollection contains a specific value.
/// </summary>
/// <param name="value">
/// The System.Object to locate in the TransformingReadOnlyCollection.
/// </param>
/// <returns>
/// True if the System.Object is found in the TransformingReadOnlyCollection;
/// otherwise, false.
/// </returns>
bool IList.Contains(object value) {
return Contains((ExposedItemType)value);
}
/// <summary>
/// Determines the index of a specific item in the TransformingReadOnlyCollection.
/// </summary>
/// <param name="value">
/// The System.Object to locate in the TransformingReadOnlyCollection.
/// </param>
/// <returns>
/// The index of value if found in the list; otherwise, -1.
/// </returns>
int IList.IndexOf(object value) {
return IndexOf((ExposedItemType)value);
}
/// <summary>
/// Inserts an item to the TransformingReadOnlyCollection at the specified index.
/// </summary>
/// <param name="index">
/// The zero-based index at which value should be inserted.
/// </param>
/// <param name="value">
/// The System.Object to insert into the TransformingReadOnlyCollection.
/// </param>
/// <exception cref="System.ArgumentOutOfRangeException">
/// Index is not a valid index in the TransformingReadOnlyCollection.
/// </exception>
/// <exception cref="System.NotSupportedException">
/// The System.Collections.IList is read-only or the TransformingReadOnlyCollection
/// has a fixed size.
/// </exception>
/// <exception cref="System.NullReferenceException">
/// Value is null reference in the TransformingReadOnlyCollection.
/// </exception>
void IList.Insert(int index, object value) {
throw new NotSupportedException("The collection is ready-only");
}
/// <summary>
/// A value indicating whether the TransformingReadOnlyCollection has a fixed
/// size.
/// </summary>
bool IList.IsFixedSize {
get { return true; }
}
/// <summary>
/// A value indicating whether the index is not a valid index in the is read-only.
/// </summary>
bool IList.IsReadOnly {
get { return true; }
}
/// <summary>
/// Removes the first occurrence of a specific object from the
/// TransformingReadOnlyCollection.
/// </summary>
/// <param name="value">
/// The System.Object to remove from the TransformingReadOnlyCollection.
/// </param>
/// <exception cref="System.NotSupportedException">
/// The TransformingReadOnlyCollection is read-only or the
/// TransformingReadOnlyCollection has a fixed size.
/// </exception>
void IList.Remove(object value) {
throw new NotSupportedException("The collection is ready-only");
}
/// <summary>
/// Removes the TransformingReadOnlyCollection item at the specified index.
/// </summary>
/// <param name="index">The zero-based index of the item to remove.</param>
/// <exception cref="System.ArgumentOutOfRangeException">
/// Index is not a valid index in the TransformingReadOnlyCollection.
/// </exception>
/// <exception cref="System.NotSupportedException">
/// The TransformingReadOnlyCollection is read-only or the
/// TransformingReadOnlyCollection has a fixed size.
/// </exception>
void IList.RemoveAt(int index) {
throw new NotSupportedException("The collection is ready-only");
}
/// <summary>Gets or sets the element at the specified index.</summary>
/// <param name="index">The zero-based index of the element to get or set.</param>
/// <returns>The element at the specified index</returns>
/// <exception cref="System.ArgumentOutOfRangeException">
/// Index is not a valid index in the TransformingReadOnlyCollection
/// </exception>
/// <exception cref="System.NotSupportedException">
/// The property is set and the TransformingReadOnlyCollection is read-only.
/// </exception>
object IList.this[int index] {
get {
return this[index];
}
set {
throw new NotSupportedException("The collection is ready-only");
}
}
#endregion
#region ICollection Members
/// <summary>
/// Copies the elements of the TransformingReadOnlyCollection to an System.Array,
/// starting at a particular System.Array index.
/// </summary>
/// <param name="array">
/// The one-dimensional System.Array that is the destination of the elements
/// copied from TransformingReadOnlyCollection. The System.Array must have zero-based
/// indexing.
/// </param>
/// <param name="index">The zero-based index in array at which copying begins.</param>
/// <exception cref="System.ArgumentNullException">
/// Array is null.
/// </exception>
/// <exception cref="System.ArgumentOutOfRangeException">
/// Index is less than zero.
/// </exception>
/// <exception cref="System.ArgumentException">
/// Array is multidimensional or index is equal to or greater than the length
/// of array or the number of elements in the source TransformingReadOnlyCollection
/// is greater than the available space from index to the end of the destination
/// array.
/// </exception>
/// <exception cref="System.InvalidCastException">
/// The type of the source TransformingReadOnlyCollection cannot be cast
/// automatically to the type of the destination array.
/// </exception>
void ICollection.CopyTo(Array array, int index) {
CopyTo((ExposedItemType[])array, index);
}
/// <summary>
/// The number of elements contained in the TransformingReadOnlyCollection.
/// </summary>
int ICollection.Count {
get { return Count; }
}
/// <summary>
/// A value indicating whether access to the TransformingReadOnlyCollection
/// is synchronized (thread safe).
/// </summary>
bool ICollection.IsSynchronized {
get { return false; }
}
/// <summary>
/// An object that can be used to synchronize access to the
/// TransformingReadOnlyCollection.
/// </summary>
object ICollection.SyncRoot {
get {
if(this.syncRoot == null) {
ICollection is2 = this.items as ICollection;
if(is2 != null) {
this.syncRoot = is2.SyncRoot;
} else {
Interlocked.CompareExchange(ref this.syncRoot, new object(), null);
}
}
return this.syncRoot;
}
}
#endregion
}
} // namespace Nuclex.Support.Collections

View File

@ -17,11 +17,11 @@ You should have received a copy of the IBM Common Public
License along with this library
*/
#endregion
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading;
namespace Nuclex.Support.Collections {
@ -48,8 +48,9 @@ namespace Nuclex.Support.Collections {
/// downcast each time you need to access elements of the non-public type.
/// </para>
/// </remarks>
public abstract class TransformingReadOnlyCollection<ContainedItemType, ExposedItemType> :
IList<ExposedItemType>, IList {
public abstract partial class TransformingReadOnlyCollection<
ContainedItemType, ExposedItemType
> : IList<ExposedItemType>, IList {
#region class TransformingEnumerator
@ -276,402 +277,6 @@ namespace Nuclex.Support.Collections {
/// </remarks>
protected abstract ExposedItemType Transform(ContainedItemType item);
#region IList<ExposedItemType> Members
/// <summary>
/// Determines the index of a specific item in the TransformingReadOnlyCollection.
/// </summary>
/// <param name="item">
/// The object to locate in the TransformingReadOnlyCollection.
/// </param>
/// <returns>
/// The index of item if found in the list; otherwise, -1.
/// </returns>
int IList<ExposedItemType>.IndexOf(ExposedItemType item) {
return IndexOf(item);
}
/// <summary>
/// Inserts an item to the TransformingReadOnlyCollection at the specified index.
/// </summary>
/// <param name="index">
/// The zero-based index at which item should be inserted.
/// </param>
/// <param name="item">
/// The object to insert into the TransformingReadOnlyCollection
/// </param>
/// <exception cref="System.NotSupportedException">
/// The TransformingReadOnlyCollection is read-only.
/// </exception>
/// <exception cref="System.ArgumentOutOfRangeException">
/// index is not a valid index in the TransformingReadOnlyCollection.
/// </exception>
void IList<ExposedItemType>.Insert(int index, ExposedItemType item) {
throw new NotSupportedException("The collection is ready-only");
}
/// <summary>
/// Removes the TransformingReadOnlyCollection item at the specified index.
/// </summary>
/// <param name="index">The zero-based index of the item to remove.</param>
/// <exception cref="System.NotSupportedException">
/// The TransformingReadOnlyCollection is read-only.
/// </exception>
/// <exception cref="System.ArgumentOutOfRangeException">
/// Index is not a valid index in the TransformingReadOnlyCollection.
/// </exception>
void IList<ExposedItemType>.RemoveAt(int index) {
throw new NotSupportedException("The collection is ready-only");
}
/// <summary>Gets or sets the element at the specified index.</summary>
/// <param name="index">The zero-based index of the element to get or set.</param>
/// <returns>The element at the specified index.</returns>
/// <exception cref="System.ArgumentOutOfRangeException">
/// Index is not a valid index in the TransformingReadOnlyCollection.
/// </exception>
/// <exception cref="System.NotSupportedException">
/// The property is set and the TransformingReadOnlyCollection is read-only
/// </exception>
ExposedItemType IList<ExposedItemType>.this[int index] {
get {
return this[index];
}
set {
throw new NotSupportedException("The collection is ready-only");
}
}
#endregion
#region ICollection<ExposedItemType> Members
/// <summary>Adds an item to the TransformingReadOnlyCollection.</summary>
/// <param name="item">The object to add to the TransformingReadOnlyCollection</param>
/// <exception cref="System.NotSupportedException">
/// The TransformingReadOnlyCollection is read-only.
/// </exception>
void ICollection<ExposedItemType>.Add(ExposedItemType item) {
throw new NotSupportedException("The collection is ready-only");
}
/// <summary>Removes all items from the TransformingReadOnlyCollection</summary>
/// <exception cref="System.NotSupportedException">
/// The TransformingReadOnlyCollection is read-only.
/// </exception>
void ICollection<ExposedItemType>.Clear() {
throw new NotSupportedException("The collection is ready-only");
}
/// <summary>
/// Determines whether the TransformingReadOnlyCollection contains a specific value.
/// </summary>
/// <param name="item">
/// The object to locate in the TransformingReadOnlyCollection.
/// </param>
/// <returns>
/// True if item is found in the TransformingReadOnlyCollection; otherwise, false.
/// </returns>
bool ICollection<ExposedItemType>.Contains(ExposedItemType item) {
return Contains(item);
}
/// <summary>
/// Copies the elements of the TransformingReadOnlyCollection to an System.Array,
/// starting at a particular System.Array index.
/// </summary>
/// <param name="array">
/// The one-dimensional System.Array that is the destination of the elements
/// copied from TransformingReadOnlyCollection. The System.Array must have
/// zero-based indexing.
/// </param>
/// <param name="arrayIndex">
/// The zero-based index in array at which copying begins
/// </param>
/// <exception cref="System.ArgumentOutOfRangeException">
/// ArrayIndex is less than 0.
/// </exception>
/// <exception cref="System.ArgumentNullException">
/// Array is null.
/// </exception>
/// <exception cref="System.ArgumentException">
/// Array is multidimensional or arrayIndex is equal to or greater than the
/// length of array or the number of elements in the source
/// TransformingReadOnlyCollection is greater than the available
/// space from arrayIndex to the end of the destination array or type T cannot
/// be cast automatically to the type of the destination array.
/// </exception>
void ICollection<ExposedItemType>.CopyTo(ExposedItemType[] array, int arrayIndex) {
CopyTo(array, arrayIndex);
}
/// <summary>
/// Removes the first occurrence of a specific object from the
/// TransformingReadOnlyCollection.
/// </summary>
/// <param name="item">
/// The object to remove from the TransformingReadOnlyCollection
/// </param>
/// <returns>
/// True if item was successfully removed from the TransformingReadOnlyCollection;
/// otherwise, false. This method also returns false if item is not found in the
/// original TransformingReadOnlyCollection.
/// </returns>
/// <exception cref="System.NotSupportedException">
/// The TransformingReadOnlyCollection is read-only.
/// </exception>
bool ICollection<ExposedItemType>.Remove(ExposedItemType item) {
throw new NotSupportedException("The collection is ready-only");
}
/// <summary>
/// The number of elements contained in the TransformingReadOnlyCollection.
/// </summary>
int ICollection<ExposedItemType>.Count {
get { return Count; }
}
/// <summary>
/// A value indicating whether the TransformingReadOnlyCollection is read-only.
/// </summary>
bool ICollection<ExposedItemType>.IsReadOnly {
get { return true; }
}
#endregion
#region IEnumerable<ExposedItemType> Members
/// <summary>Returns an enumerator that iterates through the collection.</summary>
/// <returns>
/// A System.Collections.Generic.IEnumerator&lt;ExposedItemType&gt; that can be used
/// to iterate through the collection.
/// </returns>
IEnumerator<ExposedItemType> IEnumerable<ExposedItemType>.GetEnumerator() {
return GetEnumerator();
}
#endregion
#region IEnumerable Members
/// <summary>Returns an enumerator that iterates through a collection.</summary>
/// <returns>
/// A System.Collections.IEnumerator object that can be used to iterate through
/// the collection.
/// </returns>
IEnumerator IEnumerable.GetEnumerator() {
return GetEnumerator();
}
#endregion
#region IList Members
/// <summary>Adds an item to the TransformingReadOnlyCollection.</summary>
/// <param name="value">
/// The System.Object to add to the TransformingReadOnlyCollection.
/// </param>
/// <returns>The position into which the new element was inserted.</returns>
/// <exception cref="System.NotSupportedException">
/// The System.Collections.IList is read-only or the TransformingReadOnlyCollection
/// has a fixed size.
/// </exception>
int IList.Add(object value) {
throw new NotSupportedException("The collection is ready-only");
}
/// <summary>Removes all items from the TransformingReadOnlyCollection.</summary>
/// <exception cref="System.NotSupportedException">
/// The TransformingReadOnlyCollection is read-only.
/// </exception>
void IList.Clear() {
throw new NotSupportedException("The collection is ready-only");
}
/// <summary>
/// Determines whether the TransformingReadOnlyCollection contains a specific value.
/// </summary>
/// <param name="value">
/// The System.Object to locate in the TransformingReadOnlyCollection.
/// </param>
/// <returns>
/// True if the System.Object is found in the TransformingReadOnlyCollection;
/// otherwise, false.
/// </returns>
bool IList.Contains(object value) {
return Contains((ExposedItemType)value);
}
/// <summary>
/// Determines the index of a specific item in the TransformingReadOnlyCollection.
/// </summary>
/// <param name="value">
/// The System.Object to locate in the TransformingReadOnlyCollection.
/// </param>
/// <returns>
/// The index of value if found in the list; otherwise, -1.
/// </returns>
int IList.IndexOf(object value) {
return IndexOf((ExposedItemType)value);
}
/// <summary>
/// Inserts an item to the TransformingReadOnlyCollection at the specified index.
/// </summary>
/// <param name="index">
/// The zero-based index at which value should be inserted.
/// </param>
/// <param name="value">
/// The System.Object to insert into the TransformingReadOnlyCollection.
/// </param>
/// <exception cref="System.ArgumentOutOfRangeException">
/// Index is not a valid index in the TransformingReadOnlyCollection.
/// </exception>
/// <exception cref="System.NotSupportedException">
/// The System.Collections.IList is read-only or the TransformingReadOnlyCollection
/// has a fixed size.
/// </exception>
/// <exception cref="System.NullReferenceException">
/// Value is null reference in the TransformingReadOnlyCollection.
/// </exception>
void IList.Insert(int index, object value) {
throw new NotSupportedException("The collection is ready-only");
}
/// <summary>
/// A value indicating whether the TransformingReadOnlyCollection has a fixed
/// size.
/// </summary>
bool IList.IsFixedSize {
get { return true; }
}
/// <summary>
/// A value indicating whether the index is not a valid index in the is read-only.
/// </summary>
bool IList.IsReadOnly {
get { return true; }
}
/// <summary>
/// Removes the first occurrence of a specific object from the
/// TransformingReadOnlyCollection.
/// </summary>
/// <param name="value">
/// The System.Object to remove from the TransformingReadOnlyCollection.
/// </param>
/// <exception cref="System.NotSupportedException">
/// The TransformingReadOnlyCollection is read-only or the
/// TransformingReadOnlyCollection has a fixed size.
/// </exception>
void IList.Remove(object value) {
throw new NotSupportedException("The collection is ready-only");
}
/// <summary>
/// Removes the TransformingReadOnlyCollection item at the specified index.
/// </summary>
/// <param name="index">The zero-based index of the item to remove.</param>
/// <exception cref="System.ArgumentOutOfRangeException">
/// Index is not a valid index in the TransformingReadOnlyCollection.
/// </exception>
/// <exception cref="System.NotSupportedException">
/// The TransformingReadOnlyCollection is read-only or the
/// TransformingReadOnlyCollection has a fixed size.
/// </exception>
void IList.RemoveAt(int index) {
throw new NotSupportedException("The collection is ready-only");
}
/// <summary>Gets or sets the element at the specified index.</summary>
/// <param name="index">The zero-based index of the element to get or set.</param>
/// <returns>The element at the specified index</returns>
/// <exception cref="System.ArgumentOutOfRangeException">
/// Index is not a valid index in the TransformingReadOnlyCollection
/// </exception>
/// <exception cref="System.NotSupportedException">
/// The property is set and the TransformingReadOnlyCollection is read-only.
/// </exception>
object IList.this[int index] {
get {
return this[index];
}
set {
throw new NotSupportedException("The collection is ready-only");
}
}
#endregion
#region ICollection Members
/// <summary>
/// Copies the elements of the TransformingReadOnlyCollection to an System.Array,
/// starting at a particular System.Array index.
/// </summary>
/// <param name="array">
/// The one-dimensional System.Array that is the destination of the elements
/// copied from TransformingReadOnlyCollection. The System.Array must have zero-based
/// indexing.
/// </param>
/// <param name="index">The zero-based index in array at which copying begins.</param>
/// <exception cref="System.ArgumentNullException">
/// Array is null.
/// </exception>
/// <exception cref="System.ArgumentOutOfRangeException">
/// Index is less than zero.
/// </exception>
/// <exception cref="System.ArgumentException">
/// Array is multidimensional or index is equal to or greater than the length
/// of array or the number of elements in the source TransformingReadOnlyCollection
/// is greater than the available space from index to the end of the destination
/// array.
/// </exception>
/// <exception cref="System.InvalidCastException">
/// The type of the source TransformingReadOnlyCollection cannot be cast
/// automatically to the type of the destination array.
/// </exception>
void ICollection.CopyTo(Array array, int index) {
CopyTo((ExposedItemType[])array, index);
}
/// <summary>
/// The number of elements contained in the TransformingReadOnlyCollection.
/// </summary>
int ICollection.Count {
get { return Count; }
}
/// <summary>
/// A value indicating whether access to the TransformingReadOnlyCollection
/// is synchronized (thread safe).
/// </summary>
bool ICollection.IsSynchronized {
get { return false; }
}
/// <summary>
/// An object that can be used to synchronize access to the
/// TransformingReadOnlyCollection.
/// </summary>
object ICollection.SyncRoot {
get {
if(this.syncRoot == null) {
ICollection is2 = this.items as ICollection;
if(is2 != null) {
this.syncRoot = is2.SyncRoot;
} else {
Interlocked.CompareExchange(ref this.syncRoot, new object(), null);
}
}
return this.syncRoot;
}
}
#endregion
/// <summary>Items being transformed upon exposure by this collection</summary>
private IList<ContainedItemType> items;
/// <summary>Synchronization root for threaded accesses to this collection</summary>

View File

@ -17,6 +17,7 @@ You should have received a copy of the IBM Common Public
License along with this library
*/
#endregion
using System;
using System.Collections.Generic;
using System.Collections;

View File

@ -0,0 +1,58 @@
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
This library 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
IBM Common Public License for more details.
You should have received a copy of the IBM Common Public
License along with this library
*/
#endregion
using System;
using System.Collections.Generic;
namespace Nuclex.Support.Packing {
/// <summary>Insufficient space left in packing area to contain a given object</summary>
/// <remarks>
/// An exception being sent to you from deep space. Erm, no, wait, it's an exception
/// that occurs when a packing algorithm runs out of space and is unable to fit
/// the object you tried to pack into the remaining packing area.
/// </remarks>
[Serializable]
public class OutOfSpaceException : ApplicationException {
/// <summary>Initializes the exception</summary>
public OutOfSpaceException() { }
/// <summary>Initializes the exception with an error message</summary>
/// <param name="message">Error message describing the cause of the exception</param>
public OutOfSpaceException(string message) : base(message) { }
/// <summary>Initializes the exception as a followup exception</summary>
/// <param name="message">Error message describing the cause of the exception</param>
/// <param name="inner">Preceding exception that has caused this exception</param>
public OutOfSpaceException(string message, Exception inner) : base(message, inner) { }
/// <summary>Initializes the exception from its serialized state</summary>
/// <param name="info">Contains the serialized fields of the exception</param>
/// <param name="context">Additional environmental informations</param>
protected OutOfSpaceException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context
)
: base(info, context) { }
}
} // namespace Nuclex.Support.Packing

View File

@ -17,6 +17,7 @@ You should have received a copy of the IBM Common Public
License along with this library
*/
#endregion
using System;
using System.Collections.Generic;
@ -54,7 +55,7 @@ namespace Nuclex.Support.Packing {
Point point;
if(!TryPack(rectangleWidth, rectangleHeight, out point))
throw new Exception("Rectangle does not fit in packing area");
throw new OutOfSpaceException("Rectangle does not fit in packing area");
return point;
}

View File

@ -41,7 +41,7 @@ namespace Nuclex.Support.Serialization {
// Read and verify the version of the file format this was saved in
int version = reader.ReadInt32();
if(version > 1)
throw new InvalidOperationException("File format is too new");
throw new InvalidOperationException("File format mismatch");
// Read all the serialized blueprints
int count = reader.ReadInt32();