/[gr2lib]/trunk/gr2lib/core/coreclasses/header/granny_magic.cs
ViewVC logotype

Contents of /trunk/gr2lib/core/coreclasses/header/granny_magic.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 106 - (show annotations) (download)
Sat Jul 17 14:52:37 2010 UTC (10 years, 9 months ago) by william
File size: 3633 byte(s)
implement Granny2ExceptionWriter

1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using gr2lib.core.interfaces;
6 using gr2lib.core.helpers;
7 using System.Diagnostics;
8 using gr2lib.core.exceptions;
9
10 namespace gr2lib.core.coreclasses.header
11 {
12 public class granny_magic : igranny_magic
13 {
14 private const int GrannyGRNMagixValueCount = 4;
15 private const int GrannyGRNReservedCount = 2;
16
17 public granny_magic()
18 {
19 this.HeaderSize = 0;
20 this.HeaderFormat = 0;
21 this.MagicValue = new int[GrannyGRNMagixValueCount];
22 this.Reserved = new int[GrannyGRNReservedCount];
23
24 for (int i = 0; i < GrannyGRNMagixValueCount; i++) { this.MagicValue[i] = 0; }
25 for (int i = 0; i < GrannyGRNReservedCount; i++) { this.Reserved[i] = 0; }
26 }
27
28 internal static granny_magic ReadFromMemory(IntPtr pointer)
29 {
30 try
31 {
32 if (pointer == IntPtr.Zero) return null;
33 gr2lib.core.coretypes.native.granny_grn_file_magic_value native = Helpers.ReadFromMemory<gr2lib.core.coretypes.native.granny_grn_file_magic_value>(pointer);
34 granny_magic managed = ReadFromNative(native);
35 managed.NativePointer = pointer;
36 return managed;
37 }
38 catch (Exception ex)
39 {
40 StackTrace st = new StackTrace(true);
41 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
42 Granny2ExceptionWriter.WriteToConsole(ex,st);
43 #endif
44 return default(granny_magic);
45 }
46 }
47 internal static granny_magic ReadFromNative(gr2lib.core.coretypes.native.granny_grn_file_magic_value native)
48 {
49 try
50 {
51 granny_magic managed = new granny_magic();
52 //process magic
53
54 managed.MagicValue = native.MagicValue;
55 managed.HeaderSize = native.HeaderSize;
56 managed.HeaderFormat = native.HeaderFormat;
57 managed.Reserved = native.Reserved;
58
59 return managed;
60 }
61 catch (Exception ex)
62 {
63 StackTrace st = new StackTrace(true);
64 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
65 Granny2ExceptionWriter.WriteToConsole(ex,st);
66 #endif
67 return default(granny_magic);
68 }
69 }
70 #region INativePointer Members
71 private IntPtr _NativePointer;
72 public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
73 #endregion
74
75 #region igranny_magic members
76
77 private Int32[] _MagicValue;
78 private Int32 _HeaderSize;
79 private Int32 _HeaderFormat;
80 private Int32[] _Reserved;
81
82 public Int32[] MagicValue { get { return _MagicValue; } set { if (value.Length > GrannyGRNMagixValueCount) throw new InvalidOperationException("The size of MagicValue cannot be greater than " + GrannyGRNMagixValueCount); _MagicValue = value; } } // size 4
83 public Int32 HeaderSize { get { return _HeaderSize; } set { _HeaderSize = value; } }
84 public Int32 HeaderFormat { get { return _HeaderFormat; } set { _HeaderFormat = value; } }
85 public Int32[] Reserved { get { return _Reserved; } set { if (value.Length > GrannyGRNReservedCount) throw new InvalidOperationException("The size of Reserved cannot be greater than " + GrannyGRNReservedCount); _Reserved = value; } } // size 2
86 #endregion
87 }
88 }

  ViewVC Help
Powered by ViewVC 1.1.22