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

Annotation of /trunk/gr2lib/core/coreclasses/header/granny_header.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 94 - (hide annotations) (download)
Sat Jul 17 05:09:42 2010 UTC (9 years, 6 months ago) by william
File size: 6135 byte(s)
add support for getting access to the Granny2 Header

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    
9     namespace gr2lib.core.coreclasses.header
10     {
11     public class granny_header : igranny_header
12     {
13     private const int GrannyGRNExtraTagCount = 4;
14     private const int GrannyGRNReservedUnusedCount = 3;
15    
16     public granny_header()
17     {
18     this.ExtraTags = new int[GrannyGRNExtraTagCount];
19     this.ReservedUnused = new int[GrannyGRNReservedUnusedCount];
20    
21     this.Version = 0;
22     this.TotalSize = 0;
23     this.CRC = 0;
24     this.SectionArrayOffset = 0;
25     this.SectionArrayCount = 0;
26     this.RootObjectTypeDefinition = new granny_reference();
27     this.RootObject = new granny_reference();
28     this.TypeTag = 0;
29     this.StringDatabaseCRC = 0;
30    
31     for (int i = 0; i < GrannyGRNExtraTagCount; i++) { this.ExtraTags[i] = 0; }
32     for (int i = 0; i < GrannyGRNReservedUnusedCount; i++) { this.ReservedUnused[i] = 0; }
33     }
34    
35     internal static granny_header ReadFromMemory(IntPtr pointer)
36     {
37     try
38     {
39     if (pointer == IntPtr.Zero) return null;
40     gr2lib.core.coretypes.native.granny_grn_file_header native = Helpers.ReadFromMemory<gr2lib.core.coretypes.native.granny_grn_file_header>(pointer);
41     granny_header managed = ReadFromNative(native);
42     managed.NativePointer = pointer;
43     return managed;
44     }
45     catch (Exception ex)
46     {
47     StackTrace st = new StackTrace(true);
48     Console.WriteLine(st.ToString() + "\n\n" + "Stack Trace: \n" + ex.ToString());
49     return default(granny_header);
50     }
51     }
52     internal static granny_header ReadFromNative(gr2lib.core.coretypes.native.granny_grn_file_header native)
53     {
54     try
55     {
56     granny_header managed = new granny_header();
57    
58     managed.Version = native.Version;
59     managed.TotalSize = native.TotalSize;
60     managed.CRC = native.CRC;
61     managed.SectionArrayOffset = native.SectionArrayOffset;
62     managed.SectionArrayCount = native.SectionArrayCount;
63    
64     // grn_reference
65    
66     if (native.RootObjectTypeDefinition != IntPtr.Zero)
67     {
68     //managed.RootObjectTypeDefinition = granny_reference.ReadFromMemory(native.RootObjectTypeDefinition);
69     managed.RootObjectTypeDefinition = new granny_reference();
70     }
71     else
72     {
73     managed.RootObjectTypeDefinition = new granny_reference();
74     }
75     if (native.RootObject != IntPtr.Zero)
76     {
77     //managed.RootObject = granny_reference.ReadFromMemory(native.RootObject);
78     managed.RootObject = new granny_reference();
79     }
80     else
81     {
82     managed.RootObject = new granny_reference();
83     }
84    
85     //managed.TypeTag = native.TypeTag;
86     managed.ExtraTags = native.ExtraTags;
87     managed.StringDatabaseCRC = native.StringDatabaseCRC;
88     managed.ReservedUnused = native.ReservedUnused;
89     //process header
90     return managed;
91     }
92     catch (Exception ex)
93     {
94     StackTrace st = new StackTrace(true);
95     Console.WriteLine(st.ToString() + "\n\n" + "Stack Trace: \n" + ex.ToString());
96     return default(granny_header);
97     }
98     }
99    
100     #region INativePointer Members
101     private IntPtr _NativePointer;
102     public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
103     #endregion
104    
105     #region igranny_header members
106    
107     private Int32 _Version;
108     private Int32 _TotalSize;
109     private Int32 _CRC;
110     private Int32 _SectionArrayOffset;
111     private Int32 _SectionArrayCount;
112     private granny_reference _RootObjectTypeDefinition;
113     private granny_reference _RootObject;
114     private Int32 _TypeTag;
115     private Int32[] _ExtraTags; //4
116     private Int32 _StringDatabaseCRC;
117     private Int32[] _ReservedUnused; //3
118    
119    
120     public Int32 Version { get { return _Version; } set { _Version = value; } }
121     public Int32 TotalSize { get { return _TotalSize; } set { _TotalSize = value; } }
122     public Int32 CRC { get { return _CRC; } set { _CRC = value; } }
123     public Int32 SectionArrayOffset { get { return _SectionArrayOffset; } set { _SectionArrayOffset = value; } }
124     public Int32 SectionArrayCount { get { return _SectionArrayCount; } set { _SectionArrayCount = value; } }
125     public granny_reference RootObjectTypeDefinition { get { return _RootObjectTypeDefinition; } set { _RootObjectTypeDefinition = value; } }
126     public granny_reference RootObject { get { return _RootObject; } set { _RootObject = value; } }
127     public Int32 TypeTag { get { return _TypeTag; } set { _TypeTag = value; } }
128     public Int32[] ExtraTags { get { return _ExtraTags; } set { if (value.Length > GrannyGRNExtraTagCount) throw new InvalidOperationException("The size of ExtraTags cannot be greater than " + GrannyGRNExtraTagCount); _ExtraTags = value; } } //4
129     public Int32 StringDatabaseCRC { get { return _StringDatabaseCRC; } set { _StringDatabaseCRC = value; } }
130     public Int32[] ReservedUnused { get { return _ReservedUnused; } set { if (value.Length > GrannyGRNReservedUnusedCount) throw new InvalidOperationException("The size of ReservedUnused cannot be greater than " + GrannyGRNReservedUnusedCount); _ReservedUnused = value; } } //3
131     #endregion
132     }
133     }

  ViewVC Help
Powered by ViewVC 1.1.22