static void Main() { // char[] mycharbuffer = new char [4096]; byte[] mybuffer = new byte[4096]; int size = 4096; const string filename = "testfile1.hsf"; // create a new file toolkit object BStreamFileToolkit mytoolkit = new BStreamFileToolkit(); // open a binary file for output // FileStream fs = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write); BinaryWriter binWriter = new BinaryWriter(File.Open(filename, FileMode.OpenOrCreate)); // tell the toolkit where to begin writing data; the size of the 'utility' buffer // can be anything; for this example, we use a 4k buffer mytoolkit.PrepareBuffer(mybuffer, size); // create a TK_Header object and export it's associated HSF objects, // which include the TKE_Comment and TKE_File_Info objects // TK_Header automatically formats the TKE_Comment to contain file version // information. BBaseOpcodeHandler header_handler = new TK_Header(); WriteObject(header_handler, mytoolkit, binWriter, mybuffer, size); header_handler.Dispose(); // export a TKE_Start_Compression object BBaseOpcodeHandler comp_handler = new TK_Compression((char)(TKE_Object_Types.TKE_Start_Compression)); WriteObject(comp_handler, mytoolkit, binWriter, mybuffer, size); comp_handler.Dispose(); // export a TKE_Open_Segment object (the TK_Open_Segment opcode handler // automatically supports this opcode, so it does not need to be passed // into the constructor TK_Open_Segment seghandler = new TK_Open_Segment(); seghandler.SetSegment("point"); WriteObject(seghandler, mytoolkit, binWriter, mybuffer, size); seghandler.Dispose(); // export a TKE_Marker object TK_Point pointhandler = new TK_Point((byte)(TKE_Object_Types.TKE_Marker)); pointhandler.SetPoint(0.0f, 0.0f, 0.0f); WriteObject(pointhandler, mytoolkit, binWriter, mybuffer, size); pointhandler.Dispose(); TK_Visibility vishandler = new TK_Visibility(); vishandler.SetGeometry((int)(TKO_Geometry_Bits.TKO_Geo_Marker | TKO_Geometry_Bits.TKO_Geo_Line)); vishandler.SetValue((int)(TKO_Geometry_Bits.TKO_Geo_Marker | TKO_Geometry_Bits.TKO_Geo_Line)); WriteObject(vishandler, mytoolkit, binWriter, mybuffer, size); vishandler.Dispose(); TK_Color_RGB colorhandler = new TK_Color_RGB(); colorhandler.SetGeometry((int)(TKO_Geometry_Bits.TKO_Geo_Marker | TKO_Geometry_Bits.TKO_Geo_Line)); colorhandler.SetRGB(0.0f, 0.0f, 1.0f); WriteObject(colorhandler, mytoolkit, binWriter, mybuffer, size); colorhandler.Dispose(); // export a TKE_Close_Segment object (the TK_Close_Segment opcode handler // automatically supports this opcode, so it does not need to be passed // into the constructor BBaseOpcodeHandler close_handler = new TK_Close_Segment(); WriteObject(close_handler, mytoolkit, binWriter, mybuffer, size); close_handler.Dispose(); // export a TKE_Stop_Compression object BBaseOpcodeHandler stopcomp_handler = new TK_Compression((char)(TKE_Object_Types.TKE_Stop_Compression)); WriteObject(stopcomp_handler, mytoolkit, binWriter, mybuffer, size); stopcomp_handler.Dispose(); // export a TKE_Termination object BBaseOpcodeHandler term_handler = new TK_Terminator((char)(TKE_Object_Types.TKE_Termination)); WriteObject(term_handler, mytoolkit, binWriter, mybuffer, size); term_handler.Dispose(); // ask the toolkit how much of the final buffer is filled int count = mytoolkit.CurrentBufferLength(); // write out the final buffer // fwrite(mybuffer, sizeof (char), count, flptr); binWriter.Write(mybuffer); // close the file binWriter.Close(); // clean up //binWriter.Dispose(); mytoolkit.Dispose(); return; }
public static HandleRef getCPtr(TK_Terminator obj) { return((obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr); }