|
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.Text; |
|
20 using System.Text.RegularExpressions; |
|
21 using System.Reflection; |
|
22 using SymbianParserLib.Enums; |
|
23 using SymbianParserLib.Elements; |
|
24 using SymbianParserLib.Elements.SubFields; |
|
25 |
|
26 namespace SymbianParserLib.RegExTranslators.Cache |
|
27 { |
|
28 internal class RegExTranslatorCache |
|
29 { |
|
30 #region Constructors |
|
31 public RegExTranslatorCache() |
|
32 { |
|
33 } |
|
34 #endregion |
|
35 |
|
36 #region API |
|
37 public ParserLine CreateClone( string aKey ) |
|
38 { |
|
39 ParserLine ret = null; |
|
40 // |
|
41 lock ( iEntries ) |
|
42 { |
|
43 if ( Exists( aKey ) ) |
|
44 { |
|
45 RegExTranslatorCacheEntry entry = iEntries[ aKey ]; |
|
46 ret = entry.Clone(); |
|
47 } |
|
48 } |
|
49 // |
|
50 return ret; |
|
51 } |
|
52 |
|
53 public void Add( string aKey, ParserLine aLine ) |
|
54 { |
|
55 System.Diagnostics.Debug.Assert( !string.IsNullOrEmpty( aKey ) ); |
|
56 System.Diagnostics.Debug.Assert( aLine != null ); |
|
57 System.Diagnostics.Debug.Assert( !string.IsNullOrEmpty( aLine.OriginalValue ) ); |
|
58 System.Diagnostics.Debug.Assert( !string.IsNullOrEmpty( aLine.FinalValue ) ); |
|
59 System.Diagnostics.Debug.Assert( iEntries != null ); |
|
60 |
|
61 try |
|
62 { |
|
63 lock ( iEntries ) |
|
64 { |
|
65 if ( Exists( aKey ) == false ) |
|
66 { |
|
67 RegExTranslatorCacheEntry entry = new RegExTranslatorCacheEntry( aLine ); |
|
68 iEntries.Add( aKey, entry ); |
|
69 } |
|
70 } |
|
71 } |
|
72 catch ( Exception ) |
|
73 { |
|
74 SymbianUtils.SymDebug.SymDebugger.Break(); |
|
75 } |
|
76 } |
|
77 |
|
78 public bool Exists( string aKey ) |
|
79 { |
|
80 lock ( iEntries ) |
|
81 { |
|
82 bool ret = iEntries.ContainsKey( aKey ); |
|
83 return ret; |
|
84 } |
|
85 } |
|
86 #endregion |
|
87 |
|
88 #region Properties |
|
89 #endregion |
|
90 |
|
91 #region Internal methods |
|
92 #endregion |
|
93 |
|
94 #region Internal constants |
|
95 #endregion |
|
96 |
|
97 #region From System.Object |
|
98 #endregion |
|
99 |
|
100 #region Data members |
|
101 private Dictionary<string, RegExTranslatorCacheEntry> iEntries = new Dictionary<string, RegExTranslatorCacheEntry>(); |
|
102 #endregion |
|
103 } |
|
104 } |