/* Copyright 2008 The 'A Concurrent Hashtable' development team (http://www.codeplex.com/CH/People/ProjectPeople.aspx) This library is licensed under the GNU Library General Public License (LGPL). You should have received a copy of the license along with the source code. If not, an online copy of the license can be found at http://www.codeplex.com/CH/license. */ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; namespace Orvid.Concurrent.Collections { public abstract class DictionaryBase : IDictionary, ICollection>, IEnumerable>, IDictionary, ICollection, IEnumerable { internal DictionaryBase() { } protected abstract IDictionary InternalDictionary { get; } #region IDictionary Members void IDictionary.Add(object key, object value) { ((IDictionary)this).Add((EK)key, (EV)value); } void IDictionary.Clear() { ((IDictionary)this).Clear(); } bool IDictionary.Contains(object key) { return ((IDictionary)this).ContainsKey((EK)key); } class DictionaryEnumerator : IDictionaryEnumerator { public IEnumerator> _source; #region IDictionaryEnumerator Members DictionaryEntry IDictionaryEnumerator.Entry { get { var current = _source.Current; return new DictionaryEntry( current.Key, current.Value ); } } object IDictionaryEnumerator.Key { get { return _source.Current.Key; } } object IDictionaryEnumerator.Value { get { return _source.Current.Value; } } #endregion #region IEnumerator Members object IEnumerator.Current { get { return ((IDictionaryEnumerator)this).Entry; } } bool IEnumerator.MoveNext() { return _source.MoveNext(); } void IEnumerator.Reset() { _source.Reset(); } #endregion } IDictionaryEnumerator IDictionary.GetEnumerator() { return new DictionaryEnumerator { _source = ((IEnumerable>)this).GetEnumerator() }; } bool IDictionary.IsFixedSize { get { return false; } } bool IDictionary.IsReadOnly { get { return false; } } ICollection IDictionary.Keys { get { return (ICollection)((IDictionary)this).Keys; } } void IDictionary.Remove(object key) { ((IDictionary)this).Remove((EK)key); } ICollection IDictionary.Values { get { return (ICollection)((IDictionary)this).Values; } } object IDictionary.this[object key] { get { return ((IDictionary)this)[(EK)key]; } set { ((IDictionary)this)[(EK)key] = (EV)value; } } #endregion #region ICollection Members void ICollection.CopyTo(Array array, int index) { ((ICollection>)this).CopyTo((KeyValuePair[])array, index); } int ICollection.Count { get { return ((ICollection>)this).Count; } } bool ICollection.IsSynchronized { get { return true; } } object ICollection.SyncRoot { get { return this; } } #endregion #region IEnumerable Members IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable>)this).GetEnumerator(); } #endregion #region IDictionary Members void IDictionary.Add(EK key, EV value) { InternalDictionary.Add(key, value); } bool IDictionary.ContainsKey(EK key) { return InternalDictionary.ContainsKey(key); } ICollection IDictionary.Keys { get { return InternalDictionary.Keys; } } bool IDictionary.Remove(EK key) { return InternalDictionary.Remove(key); } bool IDictionary.TryGetValue(EK key, out EV value) { return InternalDictionary.TryGetValue(key, out value); } ICollection IDictionary.Values { get { return InternalDictionary.Values; } } EV IDictionary.this[EK key] { get { return InternalDictionary[key]; } set { InternalDictionary[key] = value; } } #endregion #region ICollection> Members void ICollection>.Add(KeyValuePair item) { InternalDictionary.Add(item); } void ICollection>.Clear() { InternalDictionary.Clear(); } bool ICollection>.Contains(KeyValuePair item) { return InternalDictionary.Contains(item); } void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) { InternalDictionary.CopyTo(array, arrayIndex); } int ICollection>.Count { get { return InternalDictionary.Count; } } bool ICollection>.IsReadOnly { get { return InternalDictionary.IsReadOnly; } } bool ICollection>.Remove(KeyValuePair item) { return InternalDictionary.Remove(item); } #endregion #region IEnumerable> Members IEnumerator> IEnumerable>.GetEnumerator() { return ((IEnumerable>)InternalDictionary).GetEnumerator(); } #endregion } }