/[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 186 - (show annotations) (download)
Sat Jul 24 02:23:18 2010 UTC (9 years, 6 months ago) by william
File size: 7078 byte(s)
continue to add xml documentation

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 using gr2lib.core.exceptions;
10
11 namespace gr2lib.core.coreclasses.header
12 {
13 /// <summary>
14 /// granny_header class
15 /// </summary>
16 public class granny_header : igranny_header
17 {
18 private const int GrannyGRNExtraTagCount = 4;
19 private const int GrannyGRNReservedUnusedCount = 3;
20
21 /// <summary>
22 /// default constructor
23 /// </summary>
24 public granny_header()
25 {
26 this.ExtraTags = new int[GrannyGRNExtraTagCount];
27 this.ReservedUnused = new int[GrannyGRNReservedUnusedCount];
28
29 this.Version = 0;
30 this.TotalSize = 0;
31 this.CRC = 0;
32 this.SectionArrayOffset = 0;
33 this.SectionArrayCount = 0;
34 #if HAVE_GRN_REFERENCE
35 this.RootObjectTypeDefinition = new granny_reference();
36 this.RootObject = new granny_reference();
37 #endif
38 this.TypeTag = 0;
39 this.StringDatabaseCRC = 0;
40
41 for (int i = 0; i < GrannyGRNExtraTagCount; i++) { this.ExtraTags[i] = 0; }
42 for (int i = 0; i < GrannyGRNReservedUnusedCount; i++) { this.ReservedUnused[i] = 0; }
43 }
44
45 internal static granny_header ReadFromMemory(IntPtr pointer)
46 {
47 try
48 {
49 if (pointer == IntPtr.Zero) return null;
50 gr2lib.core.coretypes.native.granny_grn_file_header native = Helpers.ReadFromMemory<gr2lib.core.coretypes.native.granny_grn_file_header>(pointer);
51 granny_header managed = ReadFromNative(native);
52 managed.NativePointer = pointer;
53 return managed;
54 }
55 catch (Exception ex)
56 {
57 StackTrace st = new StackTrace(true);
58 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
59 Granny2ExceptionWriter.WriteToConsole(ex,st);
60 #endif
61 return default(granny_header);
62 }
63 }
64 internal static granny_header ReadFromNative(gr2lib.core.coretypes.native.granny_grn_file_header native)
65 {
66 try
67 {
68 granny_header managed = new granny_header();
69
70 managed.Version = native.Version;
71 managed.TotalSize = native.TotalSize;
72 managed.CRC = native.CRC;
73 managed.SectionArrayOffset = native.SectionArrayOffset;
74 managed.SectionArrayCount = native.SectionArrayCount;
75
76 // grn_reference
77
78 #if HAVE_GRN_REFERENCE
79 if (native.RootObjectTypeDefinition != IntPtr.Zero)
80 {
81 //managed.RootObjectTypeDefinition = granny_reference.ReadFromMemory(native.RootObjectTypeDefinition);
82 managed.RootObjectTypeDefinition = new granny_reference();
83 }
84 if (native.RootObject != IntPtr.Zero)
85 {
86 //managed.RootObject = granny_reference.ReadFromMemory(native.RootObject);
87 managed.RootObject = new granny_reference();
88 }
89 #endif
90
91 //managed.TypeTag = native.TypeTag;
92 managed.ExtraTags = native.ExtraTags;
93 managed.StringDatabaseCRC = native.StringDatabaseCRC;
94 managed.ReservedUnused = native.ReservedUnused;
95 //process header
96 return managed;
97 }
98 catch (Exception ex)
99 {
100 StackTrace st = new StackTrace(true);
101 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
102 Granny2ExceptionWriter.WriteToConsole(ex,st);
103 #endif
104 return default(granny_header);
105 }
106 }
107
108 #region INativePointer Members
109 private IntPtr _NativePointer;
110 /// <summary>
111 /// When used in a derived class, gets the native pointer for this instance
112 /// </summary>
113 public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
114 #endregion
115
116 #region igranny_header members
117
118 private Int32 _Version;
119 private Int32 _TotalSize;
120 private Int32 _CRC;
121 private Int32 _SectionArrayOffset;
122 private Int32 _SectionArrayCount;
123 #if HAVE_GRN_REFERENCE
124 private granny_reference _RootObjectTypeDefinition;
125 private granny_reference _RootObject;
126 #endif
127 private Int32 _TypeTag;
128 private Int32[] _ExtraTags; //4
129 private Int32 _StringDatabaseCRC;
130 private Int32[] _ReservedUnused; //3
131
132 /// <summary>
133 /// Version
134 /// </summary>
135 public Int32 Version { get { return _Version; } set { _Version = value; } }
136 /// <summary>
137 /// TotalSize
138 /// </summary>
139 public Int32 TotalSize { get { return _TotalSize; } set { _TotalSize = value; } }
140 /// <summary>
141 /// CRC
142 /// </summary>
143 public Int32 CRC { get { return _CRC; } set { _CRC = value; } }
144 /// <summary>
145 /// SectionArrayOffset
146 /// </summary>
147 public Int32 SectionArrayOffset { get { return _SectionArrayOffset; } set { _SectionArrayOffset = value; } }
148 /// <summary>
149 /// SectionArrayCount
150 /// </summary>
151 public Int32 SectionArrayCount { get { return _SectionArrayCount; } set { _SectionArrayCount = value; } }
152 #if HAVE_GRN_REFERENCE
153 public granny_reference RootObjectTypeDefinition { get { return _RootObjectTypeDefinition; } set { _RootObjectTypeDefinition = value; } }
154 public granny_reference RootObject { get { return _RootObject; } set { _RootObject = value; } }
155 #endif
156 /// <summary>
157 /// TypeTag
158 /// </summary>
159 public Int32 TypeTag { get { return _TypeTag; } set { _TypeTag = value; } }
160 /// <summary>
161 /// ExtraTags[4]
162 /// </summary>
163 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
164 /// <summary>
165 /// StringDatabaseCRC
166 /// </summary>
167 public Int32 StringDatabaseCRC { get { return _StringDatabaseCRC; } set { _StringDatabaseCRC = value; } }
168 /// <summary>
169 /// ReservedUnused[3]
170 /// </summary>
171 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
172 #endregion
173 }
174 }

  ViewVC Help
Powered by ViewVC 1.1.22