~ifolder-dev/simias/trunk-packaging

« back to all changes in this revision

Viewing changes to src/core/Simias.log4net/src/Appender/.svn/text-base/AppenderCollection.cs.svn-base

  • Committer: Jorge O. Castro
  • Date: 2007-12-03 06:56:46 UTC
  • Revision ID: jorge@ubuntu.com-20071203065646-mupcnjcwgm5mnhyt
* Remove a bunch of .svn directories we no longer need.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#region Copyright & License
2
 
//
3
 
// Copyright 2001-2005 The Apache Software Foundation
4
 
//
5
 
// Licensed under the Apache License, Version 2.0 (the "License");
6
 
// you may not use this file except in compliance with the License.
7
 
// You may obtain a copy of the License at
8
 
//
9
 
// http://www.apache.org/licenses/LICENSE-2.0
10
 
//
11
 
// Unless required by applicable law or agreed to in writing, software
12
 
// distributed under the License is distributed on an "AS IS" BASIS,
13
 
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 
// See the License for the specific language governing permissions and
15
 
// limitations under the License.
16
 
//
17
 
#endregion
18
 
 
19
 
using System;
20
 
using System.Collections;
21
 
 
22
 
namespace log4net.Appender
23
 
{
24
 
        /// <summary>
25
 
        /// A strongly-typed collection of <see cref="IAppender"/> objects.
26
 
        /// </summary>
27
 
        /// <author>Nicko Cadell</author>
28
 
        public class AppenderCollection : ICollection, IList, IEnumerable, ICloneable
29
 
        {
30
 
                #region Interfaces
31
 
                /// <summary>
32
 
                /// Supports type-safe iteration over a <see cref="AppenderCollection"/>.
33
 
                /// </summary>
34
 
                /// <exclude/>
35
 
                public interface IAppenderCollectionEnumerator
36
 
                {
37
 
                        /// <summary>
38
 
                        /// Gets the current element in the collection.
39
 
                        /// </summary>
40
 
                        IAppender Current { get; }
41
 
 
42
 
                        /// <summary>
43
 
                        /// Advances the enumerator to the next element in the collection.
44
 
                        /// </summary>
45
 
                        /// <returns>
46
 
                        /// <c>true</c> if the enumerator was successfully advanced to the next element; 
47
 
                        /// <c>false</c> if the enumerator has passed the end of the collection.
48
 
                        /// </returns>
49
 
                        /// <exception cref="InvalidOperationException">
50
 
                        /// The collection was modified after the enumerator was created.
51
 
                        /// </exception>
52
 
                        bool MoveNext();
53
 
 
54
 
                        /// <summary>
55
 
                        /// Sets the enumerator to its initial position, before the first element in the collection.
56
 
                        /// </summary>
57
 
                        void Reset();
58
 
                }
59
 
                #endregion
60
 
 
61
 
                private const int DEFAULT_CAPACITY = 16;
62
 
 
63
 
                #region Implementation (data)
64
 
 
65
 
                private IAppender[] m_array;
66
 
                private int m_count = 0;
67
 
                private int m_version = 0;
68
 
 
69
 
                #endregion
70
 
        
71
 
                #region Static Wrappers
72
 
 
73
 
                /// <summary>
74
 
                /// Creates a read-only wrapper for a <c>AppenderCollection</c> instance.
75
 
                /// </summary>
76
 
                /// <param name="list">list to create a readonly wrapper arround</param>
77
 
                /// <returns>
78
 
                /// An <c>AppenderCollection</c> wrapper that is read-only.
79
 
                /// </returns>
80
 
                public static AppenderCollection ReadOnly(AppenderCollection list)
81
 
                {
82
 
                        if(list==null) throw new ArgumentNullException("list");
83
 
 
84
 
                        return new ReadOnlyAppenderCollection(list);
85
 
                }
86
 
 
87
 
                #endregion
88
 
 
89
 
                #region Static Fields
90
 
 
91
 
                /// <summary>
92
 
                /// An empty readonly static AppenderCollection
93
 
                /// </summary>
94
 
                public static readonly AppenderCollection EmptyCollection = ReadOnly(new AppenderCollection(0));
95
 
 
96
 
                #endregion
97
 
 
98
 
                #region Constructors
99
 
 
100
 
                /// <summary>
101
 
                /// Initializes a new instance of the <c>AppenderCollection</c> class
102
 
                /// that is empty and has the default initial capacity.
103
 
                /// </summary>
104
 
                public AppenderCollection()
105
 
                {
106
 
                        m_array = new IAppender[DEFAULT_CAPACITY];
107
 
                }
108
 
                
109
 
                /// <summary>
110
 
                /// Initializes a new instance of the <c>AppenderCollection</c> class
111
 
                /// that has the specified initial capacity.
112
 
                /// </summary>
113
 
                /// <param name="capacity">
114
 
                /// The number of elements that the new <c>AppenderCollection</c> is initially capable of storing.
115
 
                /// </param>
116
 
                public AppenderCollection(int capacity)
117
 
                {
118
 
                        m_array = new IAppender[capacity];
119
 
                }
120
 
 
121
 
                /// <summary>
122
 
                /// Initializes a new instance of the <c>AppenderCollection</c> class
123
 
                /// that contains elements copied from the specified <c>AppenderCollection</c>.
124
 
                /// </summary>
125
 
                /// <param name="c">The <c>AppenderCollection</c> whose elements are copied to the new collection.</param>
126
 
                public AppenderCollection(AppenderCollection c)
127
 
                {
128
 
                        m_array = new IAppender[c.Count];
129
 
                        AddRange(c);
130
 
                }
131
 
 
132
 
                /// <summary>
133
 
                /// Initializes a new instance of the <c>AppenderCollection</c> class
134
 
                /// that contains elements copied from the specified <see cref="IAppender"/> array.
135
 
                /// </summary>
136
 
                /// <param name="a">The <see cref="IAppender"/> array whose elements are copied to the new list.</param>
137
 
                public AppenderCollection(IAppender[] a)
138
 
                {
139
 
                        m_array = new IAppender[a.Length];
140
 
                        AddRange(a);
141
 
                }
142
 
                
143
 
                /// <summary>
144
 
                /// Initializes a new instance of the <c>AppenderCollection</c> class
145
 
                /// that contains elements copied from the specified <see cref="IAppender"/> collection.
146
 
                /// </summary>
147
 
                /// <param name="col">The <see cref="IAppender"/> collection whose elements are copied to the new list.</param>
148
 
                public AppenderCollection(ICollection col)
149
 
                {
150
 
                        m_array = new IAppender[col.Count];
151
 
                        AddRange(col);
152
 
                }
153
 
 
154
 
                /// <summary>
155
 
                /// Type visible only to our subclasses
156
 
                /// Used to access protected constructor
157
 
                /// </summary>
158
 
                /// <exclude/>
159
 
                internal protected enum Tag 
160
 
                {
161
 
                        /// <summary>
162
 
                        /// A value
163
 
                        /// </summary>
164
 
                        Default
165
 
                }
166
 
 
167
 
                /// <summary>
168
 
                /// Allow subclasses to avoid our default constructors
169
 
                /// </summary>
170
 
                /// <param name="tag"></param>
171
 
                /// <exclude/>
172
 
                internal protected AppenderCollection(Tag tag)
173
 
                {
174
 
                        m_array = null;
175
 
                }
176
 
 
177
 
                #endregion
178
 
                
179
 
                #region Operations (type-safe ICollection)
180
 
 
181
 
                /// <summary>
182
 
                /// Gets the number of elements actually contained in the <c>AppenderCollection</c>.
183
 
                /// </summary>
184
 
                public virtual int Count
185
 
                {
186
 
                        get { return m_count; }
187
 
                }
188
 
 
189
 
                /// <summary>
190
 
                /// Copies the entire <c>AppenderCollection</c> to a one-dimensional
191
 
                /// <see cref="IAppender"/> array.
192
 
                /// </summary>
193
 
                /// <param name="array">The one-dimensional <see cref="IAppender"/> array to copy to.</param>
194
 
                public virtual void CopyTo(IAppender[] array)
195
 
                {
196
 
                        this.CopyTo(array, 0);
197
 
                }
198
 
 
199
 
                /// <summary>
200
 
                /// Copies the entire <c>AppenderCollection</c> to a one-dimensional
201
 
                /// <see cref="IAppender"/> array, starting at the specified index of the target array.
202
 
                /// </summary>
203
 
                /// <param name="array">The one-dimensional <see cref="IAppender"/> array to copy to.</param>
204
 
                /// <param name="start">The zero-based index in <paramref name="array"/> at which copying begins.</param>
205
 
                public virtual void CopyTo(IAppender[] array, int start)
206
 
                {
207
 
                        if (m_count > array.GetUpperBound(0) + 1 - start)
208
 
                        {
209
 
                                throw new System.ArgumentException("Destination array was not long enough.");
210
 
                        }
211
 
                        
212
 
                        Array.Copy(m_array, 0, array, start, m_count); 
213
 
                }
214
 
 
215
 
                /// <summary>
216
 
                /// Gets a value indicating whether access to the collection is synchronized (thread-safe).
217
 
                /// </summary>
218
 
                /// <returns>true if access to the ICollection is synchronized (thread-safe); otherwise, false.</returns>
219
 
                public virtual bool IsSynchronized
220
 
                {
221
 
                        get { return m_array.IsSynchronized; }
222
 
                }
223
 
 
224
 
                /// <summary>
225
 
                /// Gets an object that can be used to synchronize access to the collection.
226
 
                /// </summary>
227
 
                public virtual object SyncRoot
228
 
                {
229
 
                        get { return m_array.SyncRoot; }
230
 
                }
231
 
 
232
 
                #endregion
233
 
                
234
 
                #region Operations (type-safe IList)
235
 
 
236
 
                /// <summary>
237
 
                /// Gets or sets the <see cref="IAppender"/> at the specified index.
238
 
                /// </summary>
239
 
                /// <param name="index">The zero-based index of the element to get or set.</param>
240
 
                /// <exception cref="ArgumentOutOfRangeException">
241
 
                ///             <para><paramref name="index"/> is less than zero</para>
242
 
                ///             <para>-or-</para>
243
 
                ///             <para><paramref name="index"/> is equal to or greater than <see cref="AppenderCollection.Count"/>.</para>
244
 
                /// </exception>
245
 
                public virtual IAppender this[int index]
246
 
                {
247
 
                        get
248
 
                        {
249
 
                                ValidateIndex(index); // throws
250
 
                                return m_array[index]; 
251
 
                        }
252
 
                        set
253
 
                        {
254
 
                                ValidateIndex(index); // throws
255
 
                                ++m_version; 
256
 
                                m_array[index] = value; 
257
 
                        }
258
 
                }
259
 
 
260
 
                /// <summary>
261
 
                /// Adds a <see cref="IAppender"/> to the end of the <c>AppenderCollection</c>.
262
 
                /// </summary>
263
 
                /// <param name="item">The <see cref="IAppender"/> to be added to the end of the <c>AppenderCollection</c>.</param>
264
 
                /// <returns>The index at which the value has been added.</returns>
265
 
                public virtual int Add(IAppender item)
266
 
                {
267
 
                        if (m_count == m_array.Length)
268
 
                        {
269
 
                                EnsureCapacity(m_count + 1);
270
 
                        }
271
 
 
272
 
                        m_array[m_count] = item;
273
 
                        m_version++;
274
 
 
275
 
                        return m_count++;
276
 
                }
277
 
                
278
 
                /// <summary>
279
 
                /// Removes all elements from the <c>AppenderCollection</c>.
280
 
                /// </summary>
281
 
                public virtual void Clear()
282
 
                {
283
 
                        ++m_version;
284
 
                        m_array = new IAppender[DEFAULT_CAPACITY];
285
 
                        m_count = 0;
286
 
                }
287
 
                
288
 
                /// <summary>
289
 
                /// Creates a shallow copy of the <see cref="AppenderCollection"/>.
290
 
                /// </summary>
291
 
                /// <returns>A new <see cref="AppenderCollection"/> with a shallow copy of the collection data.</returns>
292
 
                public virtual object Clone()
293
 
                {
294
 
                        AppenderCollection newCol = new AppenderCollection(m_count);
295
 
                        Array.Copy(m_array, 0, newCol.m_array, 0, m_count);
296
 
                        newCol.m_count = m_count;
297
 
                        newCol.m_version = m_version;
298
 
 
299
 
                        return newCol;
300
 
                }
301
 
 
302
 
                /// <summary>
303
 
                /// Determines whether a given <see cref="IAppender"/> is in the <c>AppenderCollection</c>.
304
 
                /// </summary>
305
 
                /// <param name="item">The <see cref="IAppender"/> to check for.</param>
306
 
                /// <returns><c>true</c> if <paramref name="item"/> is found in the <c>AppenderCollection</c>; otherwise, <c>false</c>.</returns>
307
 
                public virtual bool Contains(IAppender item)
308
 
                {
309
 
                        for (int i=0; i != m_count; ++i)
310
 
                        {
311
 
                                if (m_array[i].Equals(item))
312
 
                                {
313
 
                                        return true;
314
 
                                }
315
 
                        }
316
 
                        return false;
317
 
                }
318
 
 
319
 
                /// <summary>
320
 
                /// Returns the zero-based index of the first occurrence of a <see cref="IAppender"/>
321
 
                /// in the <c>AppenderCollection</c>.
322
 
                /// </summary>
323
 
                /// <param name="item">The <see cref="IAppender"/> to locate in the <c>AppenderCollection</c>.</param>
324
 
                /// <returns>
325
 
                /// The zero-based index of the first occurrence of <paramref name="item"/> 
326
 
                /// in the entire <c>AppenderCollection</c>, if found; otherwise, -1.
327
 
                /// </returns>
328
 
                public virtual int IndexOf(IAppender item)
329
 
                {
330
 
                        for (int i=0; i != m_count; ++i)
331
 
                        {
332
 
                                if (m_array[i].Equals(item))
333
 
                                {
334
 
                                        return i;
335
 
                                }
336
 
                        }
337
 
                        return -1;
338
 
                }
339
 
 
340
 
                /// <summary>
341
 
                /// Inserts an element into the <c>AppenderCollection</c> at the specified index.
342
 
                /// </summary>
343
 
                /// <param name="index">The zero-based index at which <paramref name="item"/> should be inserted.</param>
344
 
                /// <param name="item">The <see cref="IAppender"/> to insert.</param>
345
 
                /// <exception cref="ArgumentOutOfRangeException">
346
 
                /// <para><paramref name="index"/> is less than zero</para>
347
 
                /// <para>-or-</para>
348
 
                /// <para><paramref name="index"/> is equal to or greater than <see cref="AppenderCollection.Count"/>.</para>
349
 
                /// </exception>
350
 
                public virtual void Insert(int index, IAppender item)
351
 
                {
352
 
                        ValidateIndex(index, true); // throws
353
 
                        
354
 
                        if (m_count == m_array.Length)
355
 
                        {
356
 
                                EnsureCapacity(m_count + 1);
357
 
                        }
358
 
 
359
 
                        if (index < m_count)
360
 
                        {
361
 
                                Array.Copy(m_array, index, m_array, index + 1, m_count - index);
362
 
                        }
363
 
 
364
 
                        m_array[index] = item;
365
 
                        m_count++;
366
 
                        m_version++;
367
 
                }
368
 
 
369
 
                /// <summary>
370
 
                /// Removes the first occurrence of a specific <see cref="IAppender"/> from the <c>AppenderCollection</c>.
371
 
                /// </summary>
372
 
                /// <param name="item">The <see cref="IAppender"/> to remove from the <c>AppenderCollection</c>.</param>
373
 
                /// <exception cref="ArgumentException">
374
 
                /// The specified <see cref="IAppender"/> was not found in the <c>AppenderCollection</c>.
375
 
                /// </exception>
376
 
                public virtual void Remove(IAppender item)
377
 
                {                  
378
 
                        int i = IndexOf(item);
379
 
                        if (i < 0)
380
 
                        {
381
 
                                throw new System.ArgumentException("Cannot remove the specified item because it was not found in the specified Collection.");
382
 
                        }
383
 
                        
384
 
                        ++m_version;
385
 
                        RemoveAt(i);
386
 
                }
387
 
 
388
 
                /// <summary>
389
 
                /// Removes the element at the specified index of the <c>AppenderCollection</c>.
390
 
                /// </summary>
391
 
                /// <param name="index">The zero-based index of the element to remove.</param>
392
 
                /// <exception cref="ArgumentOutOfRangeException">
393
 
                /// <para><paramref name="index"/> is less than zero</para>
394
 
                /// <para>-or-</para>
395
 
                /// <para><paramref name="index"/> is equal to or greater than <see cref="AppenderCollection.Count"/>.</para>
396
 
                /// </exception>
397
 
                public virtual void RemoveAt(int index)
398
 
                {
399
 
                        ValidateIndex(index); // throws
400
 
                        
401
 
                        m_count--;
402
 
 
403
 
                        if (index < m_count)
404
 
                        {
405
 
                                Array.Copy(m_array, index + 1, m_array, index, m_count - index);
406
 
                        }
407
 
                        
408
 
                        // We can't set the deleted entry equal to null, because it might be a value type.
409
 
                        // Instead, we'll create an empty single-element array of the right type and copy it 
410
 
                        // over the entry we want to erase.
411
 
                        IAppender[] temp = new IAppender[1];
412
 
                        Array.Copy(temp, 0, m_array, m_count, 1);
413
 
                        m_version++;
414
 
                }
415
 
 
416
 
                /// <summary>
417
 
                /// Gets a value indicating whether the collection has a fixed size.
418
 
                /// </summary>
419
 
                /// <value>true if the collection has a fixed size; otherwise, false. The default is false</value>
420
 
                public virtual bool IsFixedSize
421
 
                {
422
 
                        get { return false; }
423
 
                }
424
 
 
425
 
                /// <summary>
426
 
                /// Gets a value indicating whether the IList is read-only.
427
 
                /// </summary>
428
 
                /// <value>true if the collection is read-only; otherwise, false. The default is false</value>
429
 
                public virtual bool IsReadOnly
430
 
                {
431
 
                        get { return false; }
432
 
                }
433
 
 
434
 
                #endregion
435
 
 
436
 
                #region Operations (type-safe IEnumerable)
437
 
                
438
 
                /// <summary>
439
 
                /// Returns an enumerator that can iterate through the <c>AppenderCollection</c>.
440
 
                /// </summary>
441
 
                /// <returns>An <see cref="Enumerator"/> for the entire <c>AppenderCollection</c>.</returns>
442
 
                public virtual IAppenderCollectionEnumerator GetEnumerator()
443
 
                {
444
 
                        return new Enumerator(this);
445
 
                }
446
 
 
447
 
                #endregion
448
 
 
449
 
                #region Public helpers (just to mimic some nice features of ArrayList)
450
 
                
451
 
                /// <summary>
452
 
                /// Gets or sets the number of elements the <c>AppenderCollection</c> can contain.
453
 
                /// </summary>
454
 
                public virtual int Capacity
455
 
                {
456
 
                        get 
457
 
                        { 
458
 
                                return m_array.Length; 
459
 
                        }
460
 
                        set
461
 
                        {
462
 
                                if (value < m_count)
463
 
                                {
464
 
                                        value = m_count;
465
 
                                }
466
 
 
467
 
                                if (value != m_array.Length)
468
 
                                {
469
 
                                        if (value > 0)
470
 
                                        {
471
 
                                                IAppender[] temp = new IAppender[value];
472
 
                                                Array.Copy(m_array, 0, temp, 0, m_count);
473
 
                                                m_array = temp;
474
 
                                        }
475
 
                                        else
476
 
                                        {
477
 
                                                m_array = new IAppender[DEFAULT_CAPACITY];
478
 
                                        }
479
 
                                }
480
 
                        }
481
 
                }
482
 
 
483
 
                /// <summary>
484
 
                /// Adds the elements of another <c>AppenderCollection</c> to the current <c>AppenderCollection</c>.
485
 
                /// </summary>
486
 
                /// <param name="x">The <c>AppenderCollection</c> whose elements should be added to the end of the current <c>AppenderCollection</c>.</param>
487
 
                /// <returns>The new <see cref="AppenderCollection.Count"/> of the <c>AppenderCollection</c>.</returns>
488
 
                public virtual int AddRange(AppenderCollection x)
489
 
                {
490
 
                        if (m_count + x.Count >= m_array.Length)
491
 
                        {
492
 
                                EnsureCapacity(m_count + x.Count);
493
 
                        }
494
 
                        
495
 
                        Array.Copy(x.m_array, 0, m_array, m_count, x.Count);
496
 
                        m_count += x.Count;
497
 
                        m_version++;
498
 
 
499
 
                        return m_count;
500
 
                }
501
 
 
502
 
                /// <summary>
503
 
                /// Adds the elements of a <see cref="IAppender"/> array to the current <c>AppenderCollection</c>.
504
 
                /// </summary>
505
 
                /// <param name="x">The <see cref="IAppender"/> array whose elements should be added to the end of the <c>AppenderCollection</c>.</param>
506
 
                /// <returns>The new <see cref="AppenderCollection.Count"/> of the <c>AppenderCollection</c>.</returns>
507
 
                public virtual int AddRange(IAppender[] x)
508
 
                {
509
 
                        if (m_count + x.Length >= m_array.Length)
510
 
                        {
511
 
                                EnsureCapacity(m_count + x.Length);
512
 
                        }
513
 
 
514
 
                        Array.Copy(x, 0, m_array, m_count, x.Length);
515
 
                        m_count += x.Length;
516
 
                        m_version++;
517
 
 
518
 
                        return m_count;
519
 
                }
520
 
                
521
 
                /// <summary>
522
 
                /// Adds the elements of a <see cref="IAppender"/> collection to the current <c>AppenderCollection</c>.
523
 
                /// </summary>
524
 
                /// <param name="col">The <see cref="IAppender"/> collection whose elements should be added to the end of the <c>AppenderCollection</c>.</param>
525
 
                /// <returns>The new <see cref="AppenderCollection.Count"/> of the <c>AppenderCollection</c>.</returns>
526
 
                public virtual int AddRange(ICollection col)
527
 
                {
528
 
                        if (m_count + col.Count >= m_array.Length)
529
 
                        {
530
 
                                EnsureCapacity(m_count + col.Count);
531
 
                        }
532
 
 
533
 
                        foreach(object item in col)
534
 
                        {
535
 
                                Add((IAppender)item);
536
 
                        }
537
 
 
538
 
                        return m_count;
539
 
                }
540
 
 
541
 
                /// <summary>
542
 
                /// Sets the capacity to the actual number of elements.
543
 
                /// </summary>
544
 
                public virtual void TrimToSize()
545
 
                {
546
 
                        this.Capacity = m_count;
547
 
                }
548
 
 
549
 
                /// <summary>
550
 
                /// Return the collection elements as an array
551
 
                /// </summary>
552
 
                /// <returns>the array</returns>
553
 
                public virtual IAppender[] ToArray()
554
 
                {
555
 
                        IAppender[] resultArray = new IAppender[m_count];
556
 
                        if (m_count > 0)
557
 
                        {
558
 
                                Array.Copy(m_array, 0, resultArray, 0, m_count);
559
 
                        }
560
 
                        return resultArray;
561
 
                }
562
 
 
563
 
                #endregion
564
 
 
565
 
                #region Implementation (helpers)
566
 
 
567
 
                /// <exception cref="ArgumentOutOfRangeException">
568
 
                /// <para><paramref name="index"/> is less than zero</para>
569
 
                /// <para>-or-</para>
570
 
                /// <para><paramref name="index"/> is equal to or greater than <see cref="AppenderCollection.Count"/>.</para>
571
 
                /// </exception>
572
 
                private void ValidateIndex(int i)
573
 
                {
574
 
                        ValidateIndex(i, false);
575
 
                }
576
 
 
577
 
                /// <exception cref="ArgumentOutOfRangeException">
578
 
                /// <para><paramref name="index"/> is less than zero</para>
579
 
                /// <para>-or-</para>
580
 
                /// <para><paramref name="index"/> is equal to or greater than <see cref="AppenderCollection.Count"/>.</para>
581
 
                /// </exception>
582
 
                private void ValidateIndex(int i, bool allowEqualEnd)
583
 
                {
584
 
                        int max = (allowEqualEnd) ? (m_count) : (m_count-1);
585
 
                        if (i < 0 || i > max)
586
 
                        {
587
 
                                throw log4net.Util.SystemInfo.CreateArgumentOutOfRangeException("i", (object)i, "Index was out of range. Must be non-negative and less than the size of the collection. [" + (object)i + "] Specified argument was out of the range of valid values.");
588
 
                        }
589
 
                }
590
 
 
591
 
                private void EnsureCapacity(int min)
592
 
                {
593
 
                        int newCapacity = ((m_array.Length == 0) ? DEFAULT_CAPACITY : m_array.Length * 2);
594
 
                        if (newCapacity < min)
595
 
                        {
596
 
                                newCapacity = min;
597
 
                        }
598
 
 
599
 
                        this.Capacity = newCapacity;
600
 
                }
601
 
 
602
 
                #endregion
603
 
                
604
 
                #region Implementation (ICollection)
605
 
 
606
 
                void ICollection.CopyTo(Array array, int start)
607
 
                {
608
 
                        if (m_count > 0)
609
 
                        {
610
 
                                Array.Copy(m_array, 0, array, start, m_count);
611
 
                        }
612
 
                }
613
 
 
614
 
                #endregion
615
 
 
616
 
                #region Implementation (IList)
617
 
 
618
 
                object IList.this[int i]
619
 
                {
620
 
                        get { return (object)this[i]; }
621
 
                        set { this[i] = (IAppender)value; }
622
 
                }
623
 
 
624
 
                int IList.Add(object x)
625
 
                {
626
 
                        return this.Add((IAppender)x);
627
 
                }
628
 
 
629
 
                bool IList.Contains(object x)
630
 
                {
631
 
                        return this.Contains((IAppender)x);
632
 
                }
633
 
 
634
 
                int IList.IndexOf(object x)
635
 
                {
636
 
                        return this.IndexOf((IAppender)x);
637
 
                }
638
 
 
639
 
                void IList.Insert(int pos, object x)
640
 
                {
641
 
                        this.Insert(pos, (IAppender)x);
642
 
                }
643
 
 
644
 
                void IList.Remove(object x)
645
 
                {
646
 
                        this.Remove((IAppender)x);
647
 
                }
648
 
 
649
 
                void IList.RemoveAt(int pos)
650
 
                {
651
 
                        this.RemoveAt(pos);
652
 
                }
653
 
 
654
 
                #endregion
655
 
 
656
 
                #region Implementation (IEnumerable)
657
 
 
658
 
                IEnumerator IEnumerable.GetEnumerator()
659
 
                {
660
 
                        return (IEnumerator)(this.GetEnumerator());
661
 
                }
662
 
 
663
 
                #endregion
664
 
 
665
 
                #region Nested enumerator class
666
 
 
667
 
                /// <summary>
668
 
                /// Supports simple iteration over a <see cref="AppenderCollection"/>.
669
 
                /// </summary>
670
 
                /// <exclude/>
671
 
                private sealed class Enumerator : IEnumerator, IAppenderCollectionEnumerator
672
 
                {
673
 
                        #region Implementation (data)
674
 
                        
675
 
                        private readonly AppenderCollection m_collection;
676
 
                        private int m_index;
677
 
                        private int m_version;
678
 
                        
679
 
                        #endregion
680
 
                
681
 
                        #region Construction
682
 
                        
683
 
                        /// <summary>
684
 
                        /// Initializes a new instance of the <c>Enumerator</c> class.
685
 
                        /// </summary>
686
 
                        /// <param name="tc"></param>
687
 
                        internal Enumerator(AppenderCollection tc)
688
 
                        {
689
 
                                m_collection = tc;
690
 
                                m_index = -1;
691
 
                                m_version = tc.m_version;
692
 
                        }
693
 
                        
694
 
                        #endregion
695
 
        
696
 
                        #region Operations (type-safe IEnumerator)
697
 
                        
698
 
                        /// <summary>
699
 
                        /// Gets the current element in the collection.
700
 
                        /// </summary>
701
 
                        public IAppender Current
702
 
                        {
703
 
                                get { return m_collection[m_index]; }
704
 
                        }
705
 
 
706
 
                        /// <summary>
707
 
                        /// Advances the enumerator to the next element in the collection.
708
 
                        /// </summary>
709
 
                        /// <returns>
710
 
                        /// <c>true</c> if the enumerator was successfully advanced to the next element; 
711
 
                        /// <c>false</c> if the enumerator has passed the end of the collection.
712
 
                        /// </returns>
713
 
                        /// <exception cref="InvalidOperationException">
714
 
                        /// The collection was modified after the enumerator was created.
715
 
                        /// </exception>
716
 
                        public bool MoveNext()
717
 
                        {
718
 
                                if (m_version != m_collection.m_version)
719
 
                                {
720
 
                                        throw new System.InvalidOperationException("Collection was modified; enumeration operation may not execute.");
721
 
                                }
722
 
 
723
 
                                ++m_index;
724
 
                                return (m_index < m_collection.Count);
725
 
                        }
726
 
 
727
 
                        /// <summary>
728
 
                        /// Sets the enumerator to its initial position, before the first element in the collection.
729
 
                        /// </summary>
730
 
                        public void Reset()
731
 
                        {
732
 
                                m_index = -1;
733
 
                        }
734
 
                        #endregion
735
 
        
736
 
                        #region Implementation (IEnumerator)
737
 
                        
738
 
                        object IEnumerator.Current
739
 
                        {
740
 
                                get { return this.Current; }
741
 
                        }
742
 
                        
743
 
                        #endregion
744
 
                }
745
 
 
746
 
                #endregion
747
 
 
748
 
                #region Nested Read Only Wrapper class
749
 
 
750
 
                /// <exclude/>
751
 
                private sealed class ReadOnlyAppenderCollection : AppenderCollection, ICollection
752
 
                {
753
 
                        #region Implementation (data)
754
 
 
755
 
                        private readonly AppenderCollection m_collection;
756
 
 
757
 
                        #endregion
758
 
 
759
 
                        #region Construction
760
 
 
761
 
                        internal ReadOnlyAppenderCollection(AppenderCollection list) : base(Tag.Default)
762
 
                        {
763
 
                                m_collection = list;
764
 
                        }
765
 
 
766
 
                        #endregion
767
 
 
768
 
                        #region Type-safe ICollection
769
 
 
770
 
                        public override void CopyTo(IAppender[] array)
771
 
                        {
772
 
                                m_collection.CopyTo(array);
773
 
                        }
774
 
 
775
 
                        public override void CopyTo(IAppender[] array, int start)
776
 
                        {
777
 
                                m_collection.CopyTo(array,start);
778
 
                        }
779
 
 
780
 
                        void ICollection.CopyTo(Array array, int start)
781
 
                        {
782
 
                                ((ICollection)m_collection).CopyTo(array, start);
783
 
                        }
784
 
 
785
 
                        public override int Count
786
 
                        {
787
 
                                get { return m_collection.Count; }
788
 
                        }
789
 
 
790
 
                        public override bool IsSynchronized
791
 
                        {
792
 
                                get { return m_collection.IsSynchronized; }
793
 
                        }
794
 
 
795
 
                        public override object SyncRoot
796
 
                        {
797
 
                                get { return this.m_collection.SyncRoot; }
798
 
                        }
799
 
 
800
 
                        #endregion
801
 
 
802
 
                        #region Type-safe IList
803
 
 
804
 
                        public override IAppender this[int i]
805
 
                        {
806
 
                                get { return m_collection[i]; }
807
 
                                set { throw new NotSupportedException("This is a Read Only Collection and can not be modified"); }
808
 
                        }
809
 
 
810
 
                        public override int Add(IAppender x)
811
 
                        {
812
 
                                throw new NotSupportedException("This is a Read Only Collection and can not be modified");
813
 
                        }
814
 
 
815
 
                        public override void Clear()
816
 
                        {
817
 
                                throw new NotSupportedException("This is a Read Only Collection and can not be modified");
818
 
                        }
819
 
 
820
 
                        public override bool Contains(IAppender x)
821
 
                        {
822
 
                                return m_collection.Contains(x);
823
 
                        }
824
 
 
825
 
                        public override int IndexOf(IAppender x)
826
 
                        {
827
 
                                return m_collection.IndexOf(x);
828
 
                        }
829
 
 
830
 
                        public override void Insert(int pos, IAppender x)
831
 
                        {
832
 
                                throw new NotSupportedException("This is a Read Only Collection and can not be modified");
833
 
                        }
834
 
 
835
 
                        public override void Remove(IAppender x)
836
 
                        {
837
 
                                throw new NotSupportedException("This is a Read Only Collection and can not be modified");
838
 
                        }
839
 
 
840
 
                        public override void RemoveAt(int pos)
841
 
                        {
842
 
                                throw new NotSupportedException("This is a Read Only Collection and can not be modified");
843
 
                        }
844
 
 
845
 
                        public override bool IsFixedSize
846
 
                        {
847
 
                                get { return true; }
848
 
                        }
849
 
 
850
 
                        public override bool IsReadOnly
851
 
                        {
852
 
                                get { return true; }
853
 
                        }
854
 
 
855
 
                        #endregion
856
 
 
857
 
                        #region Type-safe IEnumerable
858
 
 
859
 
                        public override IAppenderCollectionEnumerator GetEnumerator()
860
 
                        {
861
 
                                return m_collection.GetEnumerator();
862
 
                        }
863
 
 
864
 
                        #endregion
865
 
 
866
 
                        #region Public Helpers
867
 
 
868
 
                        // (just to mimic some nice features of ArrayList)
869
 
                        public override int Capacity
870
 
                        {
871
 
                                get { return m_collection.Capacity; }
872
 
                                set { throw new NotSupportedException("This is a Read Only Collection and can not be modified"); }
873
 
                        }
874
 
 
875
 
                        public override int AddRange(AppenderCollection x)
876
 
                        {
877
 
                                throw new NotSupportedException("This is a Read Only Collection and can not be modified");
878
 
                        }
879
 
 
880
 
                        public override int AddRange(IAppender[] x)
881
 
                        {
882
 
                                throw new NotSupportedException("This is a Read Only Collection and can not be modified");
883
 
                        }
884
 
 
885
 
                        #endregion
886
 
                }
887
 
 
888
 
                #endregion
889
 
        }
890
 
 
891
 
}