module: binary-manager Synopsis: Support for assembling and dumping BINARY files Author: Tony Mann, Nosa Omo Copyright: Original Code is Copyright (c) 1995-2004 Functional Objects, Inc. All rights reserved. License: Functional Objects Library Public License Version 1.0 Dual-license: GNU Lesser General Public License Warranty: Distributed WITHOUT WARRANTY OF ANY KIND /// Class contains the data in a BINARY section. define open abstract class () constant slot section-name, init-keyword: name:; constant slot section-alignment :: = 4, init-keyword: alignment:; // default section alignment constant slot section-flags, init-keyword: flags:; slot section-data :: = make(), init-keyword: data:; slot raw-data-size :: = 0, init-keyword: raw-data-size:; // Fill pointer for raw data end class; /// The outermost class: the itself define open class () /// Now the real data // sections represented as a table constant slot sections :: = make(), init-keyword: sections:; end class; define open class () constant slot table-data :: = make(), init-keyword: table-data:; end class; define open generic binary-table-member? (table :: , key, #key model-object) => (boolean); define method binary-table-member? (binary-table :: , key, #key model-object) => (boolean :: ) element(binary-table.table-data, key, default: #f); end method; define open generic binary-element-add! (table :: , key, newval, #key model-object) => (val); define method binary-element-add! (binary-table :: , key, newval, #key model-object) => (newval) binary-table.table-data[key] := newval; end method; define open generic write-binary (stream :: , binary) => (); define method write-binary (stream :: , binary-file :: ) => () write-section-data (stream, binary-file); end method; define open generic write-binary-data (stream, binary) => (); define method write-binary-data (stream, binary-file :: ) => () write-data-section-data (stream, binary-file); end method; define open generic write-binary-section (stream :: , binary-file :: , section :: ) => (); define open generic write-section-data (stream :: , binary-file :: ) => (); define method write-section-data (stream :: , binary-file :: ) => () for (section :: in binary-file.sections.table-data) write-binary-section(stream, binary-file, section); end for; end method; define method write-data-section-data (stream :: , binary-file :: ) => () for (section :: in binary-file.sections.table-data) if (section.binary-data-section?) write-binary-section(stream, binary-file, section); end if; end for; end method; define open generic binary-data-section?(section :: ) => (data-section? :: );