/[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 186 - (hide 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 william 97 //#define HAVE_GRN_REFERENCE // when defined enabled GRN_REFERNCE in Header, else it is disabled
2     using System;
3 william 94 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 william 106 using gr2lib.core.exceptions;
10 william 94
11     namespace gr2lib.core.coreclasses.header
12     {
13 william 186 /// <summary>
14     /// granny_header class
15     /// </summary>
16 william 94 public class granny_header : igranny_header
17     {
18     private const int GrannyGRNExtraTagCount = 4;
19     private const int GrannyGRNReservedUnusedCount = 3;
20    
21 william 186 /// <summary>
22     /// default constructor
23     /// </summary>
24 william 94 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 william 97 #if HAVE_GRN_REFERENCE
35 william 94 this.RootObjectTypeDefinition = new granny_reference();
36     this.RootObject = new granny_reference();
37 william 97 #endif
38 william 94 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 william 106 catch (Exception ex)
56 william 94 {
57     StackTrace st = new StackTrace(true);
58 william 102 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
59 william 106 Granny2ExceptionWriter.WriteToConsole(ex,st);
60 william 102 #endif
61 william 94 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 william 97
76 william 94 // grn_reference
77    
78 william 97 #if HAVE_GRN_REFERENCE
79 william 94 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 william 97 #endif
90 william 94
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 william 106 catch (Exception ex)
99 william 94 {
100     StackTrace st = new StackTrace(true);
101 william 102 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
102 william 106 Granny2ExceptionWriter.WriteToConsole(ex,st);
103 william 102 #endif
104 william 94 return default(granny_header);
105     }
106     }
107    
108     #region INativePointer Members
109     private IntPtr _NativePointer;
110 william 186 /// <summary>
111     /// When used in a derived class, gets the native pointer for this instance
112     /// </summary>
113 william 94 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 william 97 #if HAVE_GRN_REFERENCE
124 william 94 private granny_reference _RootObjectTypeDefinition;
125     private granny_reference _RootObject;
126 william 97 #endif
127 william 94 private Int32 _TypeTag;
128     private Int32[] _ExtraTags; //4
129     private Int32 _StringDatabaseCRC;
130     private Int32[] _ReservedUnused; //3
131    
132 william 186 /// <summary>
133     /// Version
134     /// </summary>
135 william 94 public Int32 Version { get { return _Version; } set { _Version = value; } }
136 william 186 /// <summary>
137     /// TotalSize
138     /// </summary>
139 william 94 public Int32 TotalSize { get { return _TotalSize; } set { _TotalSize = value; } }
140 william 186 /// <summary>
141     /// CRC
142     /// </summary>
143 william 94 public Int32 CRC { get { return _CRC; } set { _CRC = value; } }
144 william 186 /// <summary>
145     /// SectionArrayOffset
146     /// </summary>
147 william 94 public Int32 SectionArrayOffset { get { return _SectionArrayOffset; } set { _SectionArrayOffset = value; } }
148 william 186 /// <summary>
149     /// SectionArrayCount
150     /// </summary>
151 william 94 public Int32 SectionArrayCount { get { return _SectionArrayCount; } set { _SectionArrayCount = value; } }
152 william 97 #if HAVE_GRN_REFERENCE
153 william 94 public granny_reference RootObjectTypeDefinition { get { return _RootObjectTypeDefinition; } set { _RootObjectTypeDefinition = value; } }
154     public granny_reference RootObject { get { return _RootObject; } set { _RootObject = value; } }
155 william 97 #endif
156 william 186 /// <summary>
157     /// TypeTag
158     /// </summary>
159 william 94 public Int32 TypeTag { get { return _TypeTag; } set { _TypeTag = value; } }
160 william 186 /// <summary>
161     /// ExtraTags[4]
162     /// </summary>
163 william 94 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 william 186 /// <summary>
165     /// StringDatabaseCRC
166     /// </summary>
167 william 94 public Int32 StringDatabaseCRC { get { return _StringDatabaseCRC; } set { _StringDatabaseCRC = value; } }
168 william 186 /// <summary>
169     /// ReservedUnused[3]
170     /// </summary>
171 william 94 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