|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 using System; |
|
18 using System.Collections.Generic; |
|
19 using System.Collections.ObjectModel; |
|
20 using System.Text; |
|
21 |
|
22 namespace SymbianImageLib.Common.Content |
|
23 { |
|
24 public class SIContentList : IEnumerable<SIContent> |
|
25 { |
|
26 #region Constructors |
|
27 public SIContentList() |
|
28 { |
|
29 } |
|
30 #endregion |
|
31 |
|
32 #region API |
|
33 public bool TryToGetFile( string aFileName, out SIContent aFile ) |
|
34 { |
|
35 aFile = null; |
|
36 bool ret = iList.Contains( aFileName ); |
|
37 if ( ret ) |
|
38 { |
|
39 aFile = iList[ aFileName ]; |
|
40 } |
|
41 return ret; |
|
42 } |
|
43 |
|
44 public bool Contains( SIContent aFile ) |
|
45 { |
|
46 return iList.Contains( aFile ); |
|
47 } |
|
48 |
|
49 public void Add( SIContent aFile ) |
|
50 { |
|
51 if ( iList.Contains( aFile ) ) |
|
52 { |
|
53 throw new ArgumentException( "Specified file is already part of the list" ); |
|
54 } |
|
55 iList.Add( aFile ); |
|
56 } |
|
57 |
|
58 public void Remove( SIContent aFile ) |
|
59 { |
|
60 if ( iList.Contains( aFile ) ) |
|
61 { |
|
62 iList.Remove( aFile ); |
|
63 } |
|
64 } |
|
65 #endregion |
|
66 |
|
67 #region Properties |
|
68 public int Count |
|
69 { |
|
70 get { return iList.Count; } |
|
71 } |
|
72 |
|
73 public SIContent this[ int aIndex ] |
|
74 { |
|
75 get { return iList[ aIndex ]; } |
|
76 } |
|
77 |
|
78 public SIContent this[ string aFileName ] |
|
79 { |
|
80 get |
|
81 { |
|
82 string key = aFileName.ToUpper(); |
|
83 return iList[ key ]; |
|
84 } |
|
85 } |
|
86 #endregion |
|
87 |
|
88 #region Internal class |
|
89 private class FileList : KeyedCollection<string, SIContent> |
|
90 { |
|
91 #region Constructors |
|
92 public FileList() |
|
93 { |
|
94 } |
|
95 #endregion |
|
96 |
|
97 #region From KeyedCollection |
|
98 protected override string GetKeyForItem( SIContent aItem ) |
|
99 { |
|
100 return aItem.FileName.ToUpper(); |
|
101 } |
|
102 #endregion |
|
103 } |
|
104 #endregion |
|
105 |
|
106 #region From IEnumerable<SymbianImageContentFile> |
|
107 public IEnumerator<SIContent> GetEnumerator() |
|
108 { |
|
109 foreach ( SIContent file in iList ) |
|
110 { |
|
111 yield return file; |
|
112 } |
|
113 } |
|
114 |
|
115 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() |
|
116 { |
|
117 foreach ( SIContent file in iList ) |
|
118 { |
|
119 yield return file; |
|
120 } |
|
121 } |
|
122 #endregion |
|
123 |
|
124 #region Data members |
|
125 private FileList iList = new FileList(); |
|
126 #endregion |
|
127 } |
|
128 } |