-//\r
-// System.Collections.Stack\r
-//\r
-// Author:\r
-// Garrett Rooney (rooneg@electricjellyfish.net)\r
-//\r
-// (C) 2001 Garrett Rooney\r
-//\r
-\r
-namespace System.Collections {\r
-\r
- [Serializable]\r
- public class Stack : ICollection, IEnumerable, ICloneable {\r
-\r
- // properties\r
- private object[] contents;\r
- private int current = -1;\r
- private int count = 0;\r
- private int capacity = 16;\r
- private int modCount = 0;\r
-\r
- private void Resize(int ncapacity) {\r
- object[] ncontents = new object[ncapacity];\r
-\r
- Array.Copy(contents, ncontents, count);\r
-\r
- capacity = ncapacity;\r
- contents = ncontents;\r
- }\r
-\r
- public Stack() {\r
- contents = new object[capacity];\r
- }\r
-\r
- public Stack(ICollection collection) {\r
- capacity = collection.Count;\r
- contents = new object[capacity];\r
- current = capacity - 1;\r
- count = capacity;\r
-\r
- collection.CopyTo(contents, 0);\r
- }\r
-\r
- public Stack(int c) {\r
- capacity = c;\r
- contents = new object[capacity];\r
- }\r
-\r
- [Serializable]\r
- private class SyncStack : Stack {\r
-\r
- Stack stack;\r
-\r
- internal SyncStack(Stack s) {\r
- stack = s;\r
- }\r
- \r
- public override int Count {\r
- get { \r
- lock (stack) {\r
- return stack.Count; \r
- }\r
- }\r
- }\r
- \r
+//
+// System.Collections.Stack
+//
+// Author:
+// Garrett Rooney (rooneg@electricjellyfish.net)
+//
+// (C) 2001 Garrett Rooney
+//
+
+//
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System.Runtime.InteropServices;
+
+namespace System.Collections {
+
+#if NET_2_0
+ [ComVisible(true)]
+#endif
+ [Serializable]
+ public class Stack : ICollection, IEnumerable, ICloneable {
+
+ // properties
+ private object[] contents;
+ private int current = -1;
+ private int count;
+ private int capacity;
+ private int modCount;
+
+ const int default_capacity = 16;
+
+ private void Resize(int ncapacity)
+ {
+
+ ncapacity = Math.Max (ncapacity, 16);
+ object[] ncontents = new object[ncapacity];
+
+ Array.Copy(contents, ncontents, count);
+
+ capacity = ncapacity;
+ contents = ncontents;
+ }
+
+ public Stack ()
+ {
+ contents = new object[default_capacity];
+ capacity = default_capacity;
+ }
+
+ public Stack(ICollection col) : this (col == null ? 16 : col.Count) {
+ if (col == null)
+ throw new ArgumentNullException("col");
+
+ // We have to do this because msft seems to call the
+ // enumerator rather than CopyTo. This affects classes
+ // like bitarray.
+ foreach (object o in col)
+ Push (o);
+ }
+
+ public Stack (int initialCapacity)
+ {
+ if (initialCapacity < 0)
+ throw new ArgumentOutOfRangeException ("initialCapacity");
+
+ capacity = initialCapacity;
+ contents = new object[capacity];
+ }
+
+ [Serializable]
+ private class SyncStack : Stack {
+
+ Stack stack;
+
+ internal SyncStack(Stack s) {
+ stack = s;
+ }
+
+ public override int Count {
+ get {
+ lock (stack) {
+ return stack.Count;
+ }
+ }
+ }
+