/[RomCheater]/trunk/RomCheater/Serialization/SearchResultWriter.cs
ViewVC logotype

Contents of /trunk/RomCheater/Serialization/SearchResultWriter.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 402 - (show annotations) (download)
Thu Jun 21 06:30:33 2012 UTC (9 years ago) by william
File size: 2500 byte(s)

1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.IO;
6
7 namespace RomCheater.Serialization
8 {
9 public interface ISearchResultWriter
10 {
11 void WriteResult<TValue>(uint address, TValue value) where TValue : IConvertible;
12 }
13 public class SearchResultWriter : SerializationWriter, ISearchResultWriter
14 {
15 public SearchResultWriter() : base() { }
16 public SearchResultWriter(int resultCount) : base(resultCount) { WriteHeader(); }
17 public SearchResultWriter(string filename) : base(filename) { WriteHeader(); }
18 public SearchResultWriter(string filename, int resultCount) : base(filename, resultCount, false) { WriteHeader(); }
19 public SearchResultWriter(string filename, int resultCount, bool delete) : base(filename, resultCount, delete) { WriteHeader(); }
20 #region ISearchResultWriter members
21 public void WriteResult<TValue>(uint address, TValue value) where TValue : IConvertible
22 {
23
24 Type t = typeof(TValue);
25
26 binWriter.Write(address);
27 switch (t.Name.ToLower())
28 {
29 case "byte":
30 binWriter.Write(Convert.ToByte(value));
31 break;
32 case "sbyte":
33 binWriter.Write(Convert.ToSByte(value));
34 break;
35 case "uint16":
36 binWriter.Write(Convert.ToUInt16(value));
37 break;
38 case "int16":
39 binWriter.Write(Convert.ToInt16(value));
40 break;
41 case "uint32":
42 binWriter.Write(Convert.ToUInt32(value));
43 break;
44 case "int32":
45 binWriter.Write(Convert.ToInt32(value));
46 break;
47 case "uint64":
48 binWriter.Write(Convert.ToUInt64(value));
49 break;
50 case "int64":
51 binWriter.Write(Convert.ToInt64(value));
52 break;
53 }
54 }
55 #endregion
56
57 private void WriteHeader()
58 {
59 // write magic: SRD
60 binWriter.Write(Encoding.UTF8.GetBytes("SRD"));
61 // write version (int)
62 binWriter.Write((int)1);
63 // write count (int)
64 binWriter.Write(ResultCount);
65 }
66 }
67 }

  ViewVC Help
Powered by ViewVC 1.1.22