/[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 102 - (show annotations) (download)
Sat Jul 17 13:54:18 2010 UTC (9 years, 1 month ago) by william
File size: 3548 byte(s)
add compiler directive to write exceptions to console or not

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

  ViewVC Help
Powered by ViewVC 1.1.22