ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/gr2lib/trunk/gr2lib/core/coreclasses/header/granny_magic.cs
Revision: 106
Committed: Sat Jul 17 14:52:37 2010 UTC (13 years, 2 months ago) by william
File size: 3633 byte(s)
Log Message:
implement Granny2ExceptionWriter

File Contents

# User Rev Content
1 william 94 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 william 106 using gr2lib.core.exceptions;
9 william 94
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 william 106 catch (Exception ex)
39 william 94 {
40     StackTrace st = new StackTrace(true);
41 william 102 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
42 william 106 Granny2ExceptionWriter.WriteToConsole(ex,st);
43 william 102 #endif
44 william 94 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 william 106 catch (Exception ex)
62 william 94 {
63     StackTrace st = new StackTrace(true);
64 william 102 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
65 william 106 Granny2ExceptionWriter.WriteToConsole(ex,st);
66 william 102 #endif
67 william 94 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     }