ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater/Serialization/SearchResultReader.cs
(Generate patch)

Comparing trunk/RomCheater/Serialization/SearchResultReader.cs (file contents):
Revision 408 by william, Thu Jun 21 18:10:21 2012 UTC vs.
Revision 409 by william, Thu Jun 21 20:02:40 2012 UTC

--- trunk/RomCheater/Serialization/SearchResultReader.cs	2012/06/21 18:10:21	408
+++ trunk/RomCheater/Serialization/SearchResultReader.cs	2012/06/21 20:02:40	409
@@ -9,13 +9,7 @@ namespace RomCheater.Serialization
 {
     public interface ISearchResultReader
     {
-        void CurrentAddress(out uint Address);
-        uint CurrentAddress();
-        void CurrentResult<TValue>(out TValue Value);
-        TValue CurrentResult<TValue>();
-
-        bool ReadCurrentAddess { get; }
-        bool ReadCurrentValue { get; }
+        ResultType<TValue> GetNextResult<TValue>() where TValue : IConvertible;
 
     }
     public class SearchResultReader : SerializationReader, ISearchResultReader
@@ -82,74 +76,43 @@ namespace RomCheater.Serialization
         #region ISearchResultReader members       
         public bool ReadCurrentAddess { get; private set; }
         public bool ReadCurrentValue { get; private set; }
-        public uint CurrentAddress()
-        {
-            uint Address = 0;
-            CurrentAddress(out Address);
-            return Address;
-        }
-        public void CurrentAddress(out uint Address)
-        {
-            Address = 0;
-            try
-            {
-                if (ReadCurrentAddess && !ReadCurrentValue)
-                {
-                    throw new InvalidOperationException("Cannot read Current Address because the current Value has not been read. Please call CurrentResult<TValue>() first.");
-                }
-                Address = binReader.ReadUInt32();
-                ReadCurrentAddess = true;
-                ReadCurrentValue = false;
-            }
-            catch (System.IO.EndOfStreamException) { }
-        }
-        public TValue CurrentResult<TValue>()
+
+        public ResultType<TValue> GetNextResult<TValue>() where TValue : IConvertible
         {
+            ResultType<TValue> result = new ResultType<TValue>();
+
+            uint Address = binReader.ReadUInt32();
             TValue Value = default(TValue);
-            CurrentResult<TValue>(out Value);
-            return Value;
-        }
-        public void CurrentResult<TValue>(out TValue Value)
-        {
-            Value = default(TValue);
-            if (!ReadCurrentAddess)
-            {
-                throw new InvalidOperationException("Cannot read Current Value because the current Address has not been read. Please call CurrentAddress() first.");
-            }
-            try
+            Type t = typeof(TValue);
+            switch (t.Name.ToLower())
             {
-                Type t = typeof(TValue);
-                switch (t.Name.ToLower())
-                {
-                    case "byte":
-                        Value = (TValue)Convert.ChangeType(binReader.ReadByte(), typeof(TValue));
-                        break;
-                    case "sbyte":
-                        Value = (TValue)Convert.ChangeType(binReader.ReadSByte(), typeof(TValue));
-                        break;
-                    case "uint16":
-                        Value = (TValue)Convert.ChangeType(binReader.ReadUInt16(), typeof(TValue));
-                        break;
-                    case "int16":
-                        Value = (TValue)Convert.ChangeType(binReader.ReadInt16(), typeof(TValue));
-                        break;
-                    case "uint32":
-                        Value = (TValue)Convert.ChangeType(binReader.ReadUInt32(), typeof(TValue));
-                        break;
-                    case "int32":
-                        Value = (TValue)Convert.ChangeType(binReader.ReadInt32(), typeof(TValue));
-                        break;
-                    case "uint64":
-                        Value = (TValue)Convert.ChangeType(binReader.ReadUInt64(), typeof(TValue));
-                        break;
-                    case "int64":
-                        Value = (TValue)Convert.ChangeType(binReader.ReadInt64(), typeof(TValue));
-                        break;
-                }
-                ReadCurrentValue = true;
-                ReadCurrentAddess = false;
+                case "byte":
+                    Value = (TValue)Convert.ChangeType(binReader.ReadByte(), typeof(TValue));
+                    break;
+                case "sbyte":
+                    Value = (TValue)Convert.ChangeType(binReader.ReadSByte(), typeof(TValue));
+                    break;
+                case "uint16":
+                    Value = (TValue)Convert.ChangeType(binReader.ReadUInt16(), typeof(TValue));
+                    break;
+                case "int16":
+                    Value = (TValue)Convert.ChangeType(binReader.ReadInt16(), typeof(TValue));
+                    break;
+                case "uint32":
+                    Value = (TValue)Convert.ChangeType(binReader.ReadUInt32(), typeof(TValue));
+                    break;
+                case "int32":
+                    Value = (TValue)Convert.ChangeType(binReader.ReadInt32(), typeof(TValue));
+                    break;
+                case "uint64":
+                    Value = (TValue)Convert.ChangeType(binReader.ReadUInt64(), typeof(TValue));
+                    break;
+                case "int64":
+                    Value = (TValue)Convert.ChangeType(binReader.ReadInt64(), typeof(TValue));
+                    break;
             }
-            catch (System.IO.EndOfStreamException) { }
+            result = new ResultType<TValue>(Address, Value);
+            return result;
         }
         #endregion
     }