[Csmail-patches] CVS: csmail/src/CSMail.Utils StateBag.cs,NONE,1.1 StateItem.cs,NONE,1.1 ChangeLog,1
Status: Pre-Alpha
Brought to you by:
mastergaurav
From: Gaurav V. <mas...@us...> - 2002-09-13 05:54:09
|
Update of /cvsroot/csmail/csmail/src/CSMail.Utils In directory usw-pr-cvs1:/tmp/cvs-serv1365 Modified Files: ChangeLog Added Files: StateBag.cs StateItem.cs Log Message: 2002-09-13 * StateBag.cs : Added new class. * StateItem.cs : Added new class. --- NEW FILE --- /** * Namespace: CSMail * Class: StateBag * * Author: Gaurav Vaish * Maintainer: mastergaurav AT users DOT sf DOT net * * (C) Gaurav Vaish (2002) */ using System; using System.Collections; using System.Collections.Specialized; namespace CSMail.Utils { public sealed class StateBag : IDictionary, ICollection, IEnumerable { private bool ignoreCase; private bool marked; private HybridDictionary bag; public StateBag(bool ignoreCase) { Initialize(ignoreCase); } public StateBag() { Initialize(false); } private void Initialize(bool ignoreCase) { this.ignoreCase = ignoreCase; marked = false; bag = new HybridDictionary(ignoreCase); } public int Count { get { return bag.Count; } } public object this[string key] { get { if(key == null || key.Length == 0) { throw new ArgumentException ("[this] Key_Cannot_Be_Null"); } object val = bag [key]; if(val is StateItem) { return ((StateItem) val).Value; } return null; } set { Add(key, value); } } object IDictionary.this[object key] { get { return this[(string) key]; } set { Add((string)key, value); } } public ICollection Keys { get { return bag.Keys; } } public ICollection Values { get { return bag.Values; } } public StateItem Add(string key, object value) { if (key == null || key.Length == 0) throw new ArgumentException ("[Add] Key_Cannot_Be_Null"); StateItem val = (StateItem)bag[key]; if(val == null) { if(value != null || marked) { val = new StateItem(value); bag.Add (key, val); } } else if(value == null && !marked) { bag.Remove (key); } else { val.Value = value; } if(val != null && marked) { val.IsDirty = true; } return val; } public void Clear() { bag.Clear(); } public IDictionaryEnumerator GetEnumerator() { return bag.GetEnumerator(); } public bool IsItemDirty(string key) { object o = bag[key]; if (o is StateItem) return ((StateItem) o).IsDirty; return false; } public void Remove(string key) { bag.Remove(key); } /// <summary> /// Undocumented /// </summary> public void SetItemDirty(string key, bool dirty) { if (bag[key] is StateItem) { ((StateItem) bag [key]).IsDirty = dirty; } } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } void ICollection.CopyTo(Array array, int index) { Values.CopyTo(array, index); } bool ICollection.IsSynchronized { get { return false; } } object ICollection.SyncRoot { get { return this; } } void IDictionary.Add(object key, object value) { Add((string) key, value); } void IDictionary.Remove(object key) { Remove((string) key); } bool IDictionary.Contains(object key) { return bag.Contains((string) key); } bool IDictionary.IsFixedSize { get { return false; } } bool IDictionary.IsReadOnly { get { return false; } } } } --- NEW FILE --- /** * Namespace: CSMail * Class: StateItem * * Author: Gaurav Vaish * Maintainer: mastergaurav AT users DOT sf DOT net * * (C) Gaurav Vaish (2002) */ namespace CSMail.Utils { public sealed class StateItem { private object val; private bool isDirty; private StateItem() { } internal StateItem(object value) { this.val = value; } public bool IsDirty { get { return isDirty; } set { isDirty = value; } } public object Value { get { return val; } set { this.val = value; } } } } Index: ChangeLog =================================================================== RCS file: /cvsroot/csmail/csmail/src/CSMail.Utils/ChangeLog,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- ChangeLog 30 Aug 2002 10:32:41 -0000 1.8 +++ ChangeLog 13 Sep 2002 05:54:06 -0000 1.9 @@ -1,4 +1,9 @@ +2002-09-13 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + + * StateBag.cs : Added new class. + * StateItem.cs : Added new class. + 2002-08-30 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> * Properties.cs : Changed value type to object. |