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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 97 - (show annotations) (download)
Sat Jul 17 05:53:44 2010 UTC (9 years, 7 months ago) by william
File size: 6081 byte(s)
Add:
#define HAVE_GRN_REFERENCE
when defined enables GRN_REFERENCE class, else disables it (the code does not work)

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

  ViewVC Help
Powered by ViewVC 1.1.22