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

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
49 {
50 StackTrace st = new StackTrace(true);
51 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
52 Console.WriteLine(st.ToString());
53 #endif
54 return default(granny_header);
55 }
56 }
57 internal static granny_header ReadFromNative(gr2lib.core.coretypes.native.granny_grn_file_header native)
58 {
59 try
60 {
61 granny_header managed = new granny_header();
62
63 managed.Version = native.Version;
64 managed.TotalSize = native.TotalSize;
65 managed.CRC = native.CRC;
66 managed.SectionArrayOffset = native.SectionArrayOffset;
67 managed.SectionArrayCount = native.SectionArrayCount;
68
69 // grn_reference
70
71 #if HAVE_GRN_REFERENCE
72 if (native.RootObjectTypeDefinition != IntPtr.Zero)
73 {
74 //managed.RootObjectTypeDefinition = granny_reference.ReadFromMemory(native.RootObjectTypeDefinition);
75 managed.RootObjectTypeDefinition = new granny_reference();
76 }
77 if (native.RootObject != IntPtr.Zero)
78 {
79 //managed.RootObject = granny_reference.ReadFromMemory(native.RootObject);
80 managed.RootObject = new granny_reference();
81 }
82 #endif
83
84 //managed.TypeTag = native.TypeTag;
85 managed.ExtraTags = native.ExtraTags;
86 managed.StringDatabaseCRC = native.StringDatabaseCRC;
87 managed.ReservedUnused = native.ReservedUnused;
88 //process header
89 return managed;
90 }
91 catch
92 {
93 StackTrace st = new StackTrace(true);
94 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
95 Console.WriteLine(st.ToString());
96 #endif
97 return default(granny_header);
98 }
99 }
100
101 #region INativePointer Members
102 private IntPtr _NativePointer;
103 public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
104 #endregion
105
106 #region igranny_header members
107
108 private Int32 _Version;
109 private Int32 _TotalSize;
110 private Int32 _CRC;
111 private Int32 _SectionArrayOffset;
112 private Int32 _SectionArrayCount;
113 #if HAVE_GRN_REFERENCE
114 private granny_reference _RootObjectTypeDefinition;
115 private granny_reference _RootObject;
116 #endif
117 private Int32 _TypeTag;
118 private Int32[] _ExtraTags; //4
119 private Int32 _StringDatabaseCRC;
120 private Int32[] _ReservedUnused; //3
121
122
123 public Int32 Version { get { return _Version; } set { _Version = value; } }
124 public Int32 TotalSize { get { return _TotalSize; } set { _TotalSize = value; } }
125 public Int32 CRC { get { return _CRC; } set { _CRC = value; } }
126 public Int32 SectionArrayOffset { get { return _SectionArrayOffset; } set { _SectionArrayOffset = value; } }
127 public Int32 SectionArrayCount { get { return _SectionArrayCount; } set { _SectionArrayCount = value; } }
128 #if HAVE_GRN_REFERENCE
129 public granny_reference RootObjectTypeDefinition { get { return _RootObjectTypeDefinition; } set { _RootObjectTypeDefinition = value; } }
130 public granny_reference RootObject { get { return _RootObject; } set { _RootObject = value; } }
131 #endif
132 public Int32 TypeTag { get { return _TypeTag; } set { _TypeTag = value; } }
133 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
134 public Int32 StringDatabaseCRC { get { return _StringDatabaseCRC; } set { _StringDatabaseCRC = value; } }
135 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
136 #endregion
137 }
138 }

  ViewVC Help
Powered by ViewVC 1.1.22