10 #ifndef BBINFILETK_TOOLKIT
11 #define BBINFILETK_TOOLKIT
14 # define __wchar_t wchar_t
21 #if defined(WIN64) || defined(_M_X64) || defined(_WIN64)
22 # define HLONG __int64
27 #include "BStreamMemory.h"
36 void *
operator new (
size_t size);
37 void operator delete (
void * p);
43 #ifndef DOXYGEN_SHOULD_SKIP_THIS
49 class BBINFILETK_API2 Internal_Data_Accumulator
57 char * m_pending_buffer;
58 int m_pending_buffer_allocated;
59 char * m_pending_position;
69 struct z_stream_s * m_z_stream;
75 Internal_Data_Accumulator () : m_pending_buffer (0), m_pending_buffer_allocated (0),
76 m_pending_position (0), m_pending_size (0),
77 m_failed_size (0), m_generated (0),
78 m_z_stream (0), m_compressed (false), m_writing (false) {}
79 ~Internal_Data_Accumulator ();
81 void set_data (
char * b,
int s) { m_buffer_data = b; m_original_size = m_buffer_size = s; }
89 int get_original_buffer_size ()
const {
return m_original_size; }
93 int unused ()
const {
return m_buffer_size; }
94 int generated ()
const {
return m_generated; }
99 TK_Status stop_decompression (
bool force);
100 bool compressed ()
const {
return m_compressed; }
102 TK_Status error (
char const * msg = 0)
const;
110 struct IT_Index_Key_Extra {
111 int m_variants[8][2];
116 class BBINFILETK_API2 Internal_Translator
117 #ifdef HPS_CORE_BUILD
129 struct Index_Key_Pair {
132 IT_Index_Key_Extra *m_extra;
136 Bounds_Valid = 0x0001,
150 Internal_Translator () : m_size (0), m_used (0), m_pairs (0) { memset (m_blocks, 0, 1024*
sizeof(
void *)); }
151 ~Internal_Translator ();
154 TK_Status add_variant (
ID_Key key,
int variant,
int value1,
int value2 = 0);
159 int & offset,
int & length,
int & index)
const;
161 int used ()
const {
return m_used; }
166 TK_Status key_variant_offset (
ID_Key key,
int variant,
int & offset)
const {
168 return key_variant_offset (key, variant, offset, length, index);
170 TK_Status key_variant_offset (
ID_Key key,
int variant,
int & offset,
int & length)
const {
172 return key_variant_offset (key, variant, offset, length, index);
178 class BBINFILETK_API2 Internal_Key_Record
179 #ifdef HPS_CORE_BUILD
195 Internal_Key_Record () { memset (m_blocks, 0, 1024*
sizeof(
void *)); }
196 ~Internal_Key_Record ();
208 class Internal_Segment_List
209 #ifdef HPS_CORE_BUILD
216 Internal_Segment_List * m_next;
220 Internal_Segment_List (
ID_Key k) : m_next (0), m_key (k) {}
222 ID_Key key ()
const {
return m_key; }
225 class Internal_Revisit_Item
226 #ifdef HPS_CORE_BUILD
233 Internal_Revisit_Item * m_next;
239 bool m_force_context;
243 class Internal_ExRef_List
244 #ifdef HPS_CORE_BUILD
251 Internal_ExRef_List * m_next;
252 Internal_ExRef_List * m_caller;
258 Internal_ExRef_List (
char const * ref,
ID_Key context, Internal_ExRef_List * caller);
259 Internal_ExRef_List (__wchar_t
const * ref,
ID_Key context, Internal_ExRef_List * caller);
261 Internal_ExRef_List (
unsigned short const * ref,
ID_Key context, Internal_ExRef_List * caller);
263 ~Internal_ExRef_List ();
265 wchar_t const * Reference ()
const {
return m_ref; }
266 wchar_t const * Actual ()
const {
return m_actual; }
267 ID_Key Context ()
const {
return m_context; }
268 Internal_ExRef_List * Caller ()
const {
return m_caller; }
269 void SetActual (__wchar_t
const * actual);
271 void SetActual (
unsigned short const * actual);
276 class BBINFILETK_API Recorded_Instance
277 #ifdef HPS_CORE_BUILD
284 Recorded_Instance * m_next;
290 float m_local_basis[16];
291 int m_basis_indices[4];
292 float m_arbitrary_point[3];
293 int m_arbitrary_index;
296 unsigned char m_opcode;
302 Recorded_Instance (
ID_Key key,
int variant,
unsigned char op,
int val1,
int val2,
int val3)
303 : m_next (0), m_key (key), m_variant (variant), m_basis_valid (false), m_opcode (op) {
304 m_values[0] = val1; m_values[1] = val2; m_values[2] = val3;
310 bool basis_valid ()
const {
return m_basis_valid; }
311 bool generate_basis (
int count,
float const points[]);
314 class Internal_Segment_Processor;
327 typedef bool (*TK_Progress_Callback) (
unsigned HLONG so_far,
unsigned HLONG expected,
void * user_data);
368 #ifdef HPS_CORE_BUILD
380 friend class Internal_Segment_Processor;
388 #ifndef DOXYGEN_SHOULD_SKIP_THIS
390 Internal_Data_Accumulator m_accumulator;
391 Internal_Translator m_translator;
396 int m_postwalk_count;
400 Internal_Segment_List * m_active_segments;
401 Internal_Key_Record m_visited_items;
404 int m_last_keys_used;
405 int m_last_keys_allocated;
406 Internal_Revisit_Item * m_revisit;
407 Internal_Revisit_Item * m_revisit_working;
413 unsigned int m_offset;
417 int m_num_normal_bits;
418 int m_num_vertex_bits;
419 int m_num_parameter_bits;
420 int m_num_color_bits;
421 int m_num_index_bits;
423 int m_target_version;
424 bool m_header_comment_seen;
428 unsigned int m_logging_options;
429 mutable unsigned int m_log_line_length;
430 unsigned int m_opcode_sequence;
431 unsigned int m_objects_written;
432 TK_Progress_Callback m_progress_callback;
433 void * m_progress_value;
436 int m_dictionary_format;
437 int m_dictionary_options;
438 int m_dictionary_size;
439 int m_dictionary_offset;
440 Recorded_Instance * m_instance_hash[256];
443 int m_pause_table_size;
444 unsigned short m_num_pauses;
445 float * m_world_bounding;
446 Internal_ExRef_List * m_external_references;
447 Internal_ExRef_List * m_external_ref_tail;
448 Internal_ExRef_List * m_previous_exrefs;
449 bool m_suppress_errors;
451 wchar_t ** m_file_names;
452 int * m_file_indices;
454 int m_files_allocated;
455 wchar_t * m_current_filename;
457 float m_quantization_error;
459 int m_save_write_flags;
460 wchar_t * m_wfilename;
461 bool m_geometry_open;
470 bool issorted_revisit(Internal_Revisit_Item *array[],
int count);
476 void qsort_revisit(Internal_Revisit_Item **, Internal_Revisit_Item **);
479 virtual void read_completed ();
481 bool add_exref (Internal_ExRef_List * exref);
503 #ifndef BSTREAM_DISABLE_ASCII
528 static int ParseVersion (
char const * block);
571 TK_Status PrepareBuffer(
char * b,
int s);
575 m_accumulator.unused();}
648 virtual void Restart ();
674 {
return m_translator.add_pair (index, key); }
685 {
return m_translator.add_variant (key, variant, value1, value2); }
694 {
return m_translator.add_bounds (key, bounds); }
704 {
return m_translator.key_variant_offset (key, variant, offset); }
715 {
return m_translator.key_variant_offset (key, variant, offset, length); }
727 int & offset,
int & length, __wchar_t
const *& filename)
const;
730 int & offset,
int & length,
unsigned short const *& filename)
const;
739 {
return m_translator.key_bounds (key, bounds); }
758 void SetFilename (
char const * name);
765 void SetFilename (__wchar_t
const * name);
767 void SetFilename (
unsigned short const * name);
781 void SetNewFile (
char const * name);
788 void SetNewFile (__wchar_t
const * name);
790 void SetNewFile (
unsigned short const * name);
796 __wchar_t
const *
GetCurrentFile ()
const {
return (__wchar_t
const *)m_current_filename; }
801 void GetCurrentFile (__wchar_t
const *& filename)
const { filename = (__wchar_t
const *)m_current_filename; }
803 void GetCurrentFile (
unsigned short const *& filename)
const { filename = (
unsigned short const *)m_current_filename; }
815 TK_Status SelectFile (
char const * name);
823 TK_Status SelectFile (__wchar_t
const * name);
825 TK_Status SelectFile (
unsigned short const * name);
835 virtual TK_Status OpenFile (
char const * name,
bool write =
false);
844 virtual TK_Status OpenFile (__wchar_t
const * name,
bool write =
false);
846 virtual TK_Status OpenFile (
unsigned short const * name,
bool write =
false);
863 virtual TK_Status ReadBuffer (
char * buffer,
int size,
int & amount_read);
873 virtual TK_Status WriteBuffer (
char * buffer,
int size);
884 virtual TK_Status PositionFile (
int offset);
894 virtual TK_Status GetFileSize (
unsigned HLONG & size);
923 void SetFlags (
int flags) { SetWriteFlags(flags); }
963 void SetNumColorBits (
int numbits) { m_num_color_bits = (numbits<=72) ? numbits : 72; }
965 void SetNumIndexBits (
int numbits) { m_num_index_bits = (numbits<=24) ? numbits : 24; }
973 void SetReadVersion (
int version) { m_file_version = version; m_header_comment_seen =
true; }
982 m_target_version = version;
988 unsigned int GetFileOffset ()
const {
return m_offset; }
997 virtual TK_Status Error(
char const * msg = 0)
const;
1002 void SetLogFile (
char const * filename = 0);
1013 {
return m_logging_options & mask; }
1016 { m_logging_options = options; }
1022 TK_Status OpenLogFile (
char const * filename,
char const * mode);
1025 void LogEntry (
char const *
string)
const;
1028 void LogEntry (__wchar_t
const *
string)
const;
1030 void LogEntry (
unsigned short const *
string)
const;
1033 void CloseLogFile ();
1062 void SetLastKey (
ID_Key key);
1066 void ClearLastKey ();
1076 { m_dictionary_format = format; m_dictionary_options = options; }
1112 void RecordPause (
int offset);
1129 void SetFirstPause (
int offset) {
if (GetPauseCount() == 0) RecordPause (offset);
1130 else m_pause_table[0] = offset; }
1132 int GetFirstPause ()
const {
return (m_num_pauses > 0) ? m_pause_table[0] : 0; }
1143 void SetWorldBounding (
float const bbox[]);
1150 void SetWorldBoundingBySphere (
float const pt[],
float radius);
1162 bool AddExternalReference (
char const * ref,
ID_Key context);
1169 bool AddExternalReference (__wchar_t
const * ref,
ID_Key context);
1171 bool AddExternalReference (
unsigned short const * ref,
ID_Key context);
1176 bool NextExternalReference ();
1181 return (m_external_references != 0) ? (
wchar_t const*)m_external_references->Reference() : 0;
1187 exref = (m_external_references != 0) ? (__wchar_t
const *)m_external_references->Reference() : 0;
1190 void GetExternalReference (
unsigned short const *& exref)
const {
1191 exref = (m_external_references != 0) ? (
unsigned short const *)m_external_references->Reference() : 0;
1199 return (m_external_references != 0) ? m_external_references->m_context : -1;
1210 void AddSegment (
ID_Key key);
1228 void ReportQuantizationError(
int bits_per_sample,
float const *bounding,
int num_dimensions = 3);
1238 if (m_geometry_open)
1239 return Error (
"recursive geometry open");
1240 m_geometry_open =
true;
1247 if (!m_geometry_open)
1248 return Error (
"no geometry open");
1249 m_geometry_open =
false;
1258 ID_Key RevisitKey ()
const {
return m_revisit_working ? m_revisit_working->m_key : -1; }
1259 ID_Key RevisitOwner ()
const {
return m_revisit_working ? m_revisit_working->m_owner : -1; }
1263 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1265 virtual void FileDone() { ; };
1268 TK_Status read (
char * b,
int n) {
return m_accumulator.read (b, n); }
1269 TK_Status write (
char const * b,
int n) {
return m_accumulator.write (b, n); }
1270 TK_Status lookat (
char & b) {
return m_accumulator.lookat (b); }
1279 ID_Key context_key ()
const {
return m_context_key; }
1280 void set_context_key (
ID_Key key);
1283 if(m_last_keys_used == 1)
1284 return m_last_keys[0];
1290 void remember_item (
ID_Key key);
1291 bool find_item (
ID_Key key)
const;
1298 int pass ()
const {
return m_pass; }
1301 TK_Status revisit (
unsigned char opcode,
float priority,
int lod=0);
1305 int val1,
int val2 = 0,
int val3 = 0);
1308 bool find_instance (
BBaseOpcodeHandler *
object,
int val1,
int val2 = 0,
int val3 = 0)
const;
1311 int position ()
const {
return m_position; }
1312 void set_position (
int pos) { m_position = pos; }
1313 void mark_position () { set_position (GeneratedSoFar()); }
1325 TK_Status start_compression () {
return m_accumulator.start_compression(); }
1326 TK_Status stop_compression () {
return m_accumulator.stop_compression(
true); }
1327 TK_Status start_decompression () {
return m_accumulator.start_decompression(); }
1328 TK_Status stop_decompression (
bool force =
false) {
return m_accumulator.stop_decompression(force); }
1329 virtual void empty_lists ();
1337 #ifndef BSTREAM_DISABLE_ASCII
1343 int n_tabs = m_tk->GetTabs();
1344 m_tk->SetTabs(++n_tabs);
1349 int n_tabs = m_tk->GetTabs();
1350 m_tk->SetTabs(--n_tabs);
1361 int cur_tabs = m_tk->GetTabs();
1362 if(cur_tabs >= n_tabs)
1365 m_tk->SetTabs(cur_tabs-n_tabs);
1376 int cur_tabs = m_tk->GetTabs();
1377 m_tk->SetTabs(cur_tabs+m_tabs);
1385 #endif //BSTREAM_DISABLE_ASCII
1387 #endif //BBINFILETK_TOOLKIT
Definition: BStreamFileToolkit.h:1338
ID_Key last_key(BStreamFileToolkit &tk) const
obsolete
Definition: BOpcodeHandler.h:638
Handles the TKE_Shell opcode.
Definition: BOpcodeShell.h:25
#define TK_DEFAULT_BUFFER_SIZE
default amount of the internal memory buffer used for file processing
Definition: BStream.h:183
void increase_nesting(BStreamFileToolkit &tk, int amount=1)
for internal use only
Definition: BOpcodeHandler.h:647
void decrease_nesting(BStreamFileToolkit &tk, int amount=1)
for internal use only
Definition: BOpcodeHandler.h:649
Handles the TKE_Tag opcode.
Definition: BOpcodeHandler.h:1923
Definition: BStreamFileToolkit.h:34
#define TK_File_Format_Version
Definition: BStream.h:70
Definition: BOpcodeHandler.h:964
ID_Key remove_segment(BStreamFileToolkit &tk)
for internal use only
Definition: BOpcodeHandler.h:634
Handles the TKE_Repeat_Object opcode.
Definition: BOpcodeHandler.h:1765
Handles the TKE_Dictionary opcode.
Definition: BOpcodeHandler.h:1952
Definition: BStream.h:255
void add_segment(BStreamFileToolkit &tk, ID_Key key)
for internal use only
Definition: BOpcodeHandler.h:632
int m_stage
The writing stage.
Definition: BOpcodeHandler.h:61
void set_last_key(BStreamFileToolkit &tk, ID_Key key)
sets the given key as "most recent" on the toolkit for the purposes of associating keys with indices ...
Definition: BOpcodeHandler.h:636
The BBaseOpcodeHandler abstract class is used as a base for derived classes which manage logical piec...
Definition: BOpcodeHandler.h:53
TK_Status
Codes which can be either passed to various toolkit functions, or indicate the result of a toolkit fu...
Definition: BStream.h:254
dictionary entries include bounding volume info
Definition: BStream.h:303
#define ID_Key
Definition: BStream.h:230
Handles the TKE_Start_Compression and TKE_Stop_Compression opcodes.
Definition: BOpcodeHandler.h:1169
Definition: BStreamFileToolkit.h:1356
void adjust_written(BStreamFileToolkit &tk, int count)
for internal use only
Definition: BOpcodeHandler.h:645
Provides HOOPS/3dGS-specific handling of the TKE_Reference opcode.
Definition: HOpcodeHandler.h:118