15 #ifndef BBINFILETK_TOOLKIT
16 #define BBINFILETK_TOOLKIT
19 # define __wchar_t wchar_t
26 #if defined(WIN64) || defined(_M_X64) || defined(_WIN64)
27 # define HLONG __int64
39 void *
operator new (
size_t size);
40 void operator delete (
void * p);
46 #ifndef DOXYGEN_SHOULD_SKIP_THIS
52 class BBINFILETK_API2 Internal_Data_Accumulator {
54 char * m_pending_buffer;
55 int m_pending_buffer_allocated;
56 char * m_pending_position;
66 struct z_stream_s * m_z_stream;
72 Internal_Data_Accumulator () : m_pending_buffer (0), m_pending_buffer_allocated (0),
73 m_pending_position (0), m_pending_size (0),
74 m_failed_size (0), m_generated (0),
75 m_z_stream (0), m_compressed (false), m_writing (false) {}
76 ~Internal_Data_Accumulator ();
78 void set_data (
char * b,
int s)
alter { m_buffer_data = b; m_original_size = m_buffer_size = s; }
82 TK_Status read (
char alter * b,
int s) alter;
83 TK_Status write (
char const * b,
int s) alter;
86 int get_original_buffer_size(){
return m_original_size; }
88 void restart ()
alter;
90 int unused ()
const {
return m_buffer_size; }
91 int generated ()
const {
return m_generated; }
96 TK_Status stop_decompression (
bool force) alter;
97 bool compressed ()
const {
return m_compressed; }
99 TK_Status error (
char const * msg = 0)
const;
107 struct IT_Index_Key_Extra {
108 int m_variants[8][2];
113 class BBINFILETK_API2 Internal_Translator {
120 struct Index_Key_Pair {
123 IT_Index_Key_Extra *m_extra;
127 Bounds_Valid = 0x0001,
141 Internal_Translator () : m_size (0), m_used (0), m_pairs (0) { memset (m_blocks, 0, 1024*
sizeof(
void *)); }
142 ~Internal_Translator ();
150 int alter & offset,
int alter & length,
int alter & index) const;
152 int used ()
const {
return m_used; }
159 return key_variant_offset (key, variant, offset, length, index);
163 return key_variant_offset (key, variant, offset, length, index);
169 class BBINFILETK_API2 Internal_Key_Record {
180 Internal_Key_Record () { memset (m_blocks, 0, 1024*
sizeof(
void *)); }
181 ~Internal_Key_Record ();
195 Internal_Segment_List * m_next;
199 Internal_Segment_List (
ID_Key k) : m_next (0), m_key (k) {}
201 ID_Key key ()
const {
return m_key; }
206 Internal_Revisit_Item * m_next;
212 bool m_force_context;
218 Internal_ExRef_List * m_next;
219 Internal_ExRef_List * m_caller;
221 __wchar_t * m_actual;
225 Internal_ExRef_List (
char const * ref,
ID_Key context, Internal_ExRef_List * caller);
226 Internal_ExRef_List (__wchar_t
const * ref,
ID_Key context, Internal_ExRef_List * caller);
228 Internal_ExRef_List (
unsigned short const * ref,
ID_Key context, Internal_ExRef_List * caller);
230 ~Internal_ExRef_List ();
232 __wchar_t
const * Reference ()
const {
return m_ref; }
233 __wchar_t
const * Actual ()
const {
return m_actual; }
234 ID_Key Context ()
const {
return m_context; }
235 Internal_ExRef_List * Caller ()
const {
return m_caller; }
236 void SetActual (__wchar_t
const * actual)
alter;
238 void SetActual (
unsigned short const * actual)
alter;
245 Recorded_Instance * m_next;
251 float m_local_basis[16];
252 int m_basis_indices[4];
253 float m_arbitrary_point[3];
254 int m_arbitrary_index;
257 unsigned char m_opcode;
263 Recorded_Instance (
ID_Key key,
int variant,
unsigned char op,
int val1,
int val2,
int val3)
264 : m_next (0), m_key (key), m_variant (variant), m_basis_valid (false), m_opcode (op) {
265 m_values[0] = val1; m_values[1] = val2; m_values[2] = val3;
271 bool basis_valid ()
const {
return m_basis_valid; }
272 bool generate_basis (
int count,
float const * points)
alter;
275 class Internal_Segment_Processor;
288 typedef bool (*TK_Progress_Callback) (
unsigned HLONG so_far,
unsigned HLONG expected,
void * user_data);
335 friend class Internal_Segment_Processor;
343 #ifndef DOXYGEN_SHOULD_SKIP_THIS
345 Internal_Data_Accumulator m_accumulator;
346 Internal_Translator m_translator;
351 int m_postwalk_count;
355 Internal_Segment_List * m_active_segments;
356 Internal_Key_Record m_visited_items;
359 int m_last_keys_used;
360 int m_last_keys_allocated;
361 Internal_Revisit_Item * m_revisit;
362 Internal_Revisit_Item * m_revisit_working;
368 unsigned int m_offset;
372 int m_num_normal_bits;
373 int m_num_vertex_bits;
374 int m_num_parameter_bits;
375 int m_num_color_bits;
376 int m_num_index_bits;
378 int m_target_version;
379 bool m_header_comment_seen;
383 unsigned int m_logging_options;
384 mutable unsigned int m_log_line_length;
385 unsigned int m_opcode_sequence;
386 unsigned int m_objects_written;
387 TK_Progress_Callback m_progress_callback;
388 void * m_progress_value;
391 int m_dictionary_format;
392 int m_dictionary_options;
393 int m_dictionary_size;
394 int m_dictionary_offset;
395 Recorded_Instance * m_instance_hash[256];
398 int m_pause_table_size;
399 unsigned short m_num_pauses;
400 float * m_world_bounding;
401 Internal_ExRef_List * m_external_references;
402 Internal_ExRef_List * m_external_ref_tail;
403 Internal_ExRef_List * m_previous_exrefs;
404 bool m_suppress_errors;
406 __wchar_t ** m_file_names;
407 int * m_file_indices;
409 int m_files_allocated;
410 __wchar_t * m_current_filename;
412 float m_quantization_error;
414 int m_save_write_flags;
415 __wchar_t * m_wfilename;
416 bool m_geometry_open;
425 bool issorted_revisit(Internal_Revisit_Item **array,
int count);
431 void qsort_revisit(Internal_Revisit_Item **, Internal_Revisit_Item **);
434 virtual void read_completed ()
alter;
436 bool add_exref (Internal_ExRef_List * exref);
458 #ifndef BSTREAM_DISABLE_ASCII
483 static int ParseVersion (
char const * block);
526 TK_Status PrepareBuffer(
char * b,
int s) alter;
529 int CurrentBufferLength() {
return m_accumulator.get_original_buffer_size() -
530 m_accumulator.unused();}
603 virtual void Restart ()
alter;
629 {
return m_translator.add_pair (index, key); }
640 {
return m_translator.add_variant (key, variant, value1, value2); }
649 {
return m_translator.add_bounds (key, bounds); }
659 {
return m_translator.key_variant_offset (key, variant, offset); }
670 {
return m_translator.key_variant_offset (key, variant, offset, length); }
682 int alter & offset,
int alter & length, __wchar_t
const *
alter & filename)
const;
685 int alter & offset,
int alter & length,
unsigned short const *
alter & filename)
const;
694 {
return m_translator.key_bounds (key, bounds); }
713 void SetFilename (
char const * name)
alter;
720 void SetFilename (__wchar_t
const * name)
alter;
722 void SetFilename (
unsigned short const * name)
alter;
736 void SetNewFile (
char const * name)
alter;
743 void SetNewFile (__wchar_t
const * name)
alter;
745 void SetNewFile (
unsigned short const * name)
alter;
751 __wchar_t
const *
GetCurrentFile ()
const {
return (__wchar_t
const*)m_current_filename; }
779 virtual TK_Status OpenFile (
char const * name,
bool write =
false)
alter;
788 virtual TK_Status OpenFile (__wchar_t
const * name,
bool write =
false)
alter;
790 virtual TK_Status OpenFile (
unsigned short const * name,
bool write =
false)
alter;
817 virtual
TK_Status WriteBuffer (
char alter * buffer,
int size) alter;
828 virtual
TK_Status PositionFile (
int offset) alter;
838 virtual
TK_Status GetFileSize (
unsigned HLONG & size) alter;
852 virtual
TK_Status LocateDictionary () alter;
866 int GetFlags ()
const {
return GetWriteFlags(); }
917 void SetReadVersion (
int version) { m_file_version = version; m_header_comment_seen =
true; }
928 unsigned int GetFileOffset ()
const {
return m_offset; }
937 virtual TK_Status Error(
char const * msg = 0)
const;
942 void SetLogFile (
char const * filename = 0)
alter;
945 bool GetLogging ()
const {
return m_logging; }
953 {
return m_logging_options & mask; }
956 { m_logging_options = options; }
962 TK_Status OpenLogFile (
char const * filename,
char const * mode)
alter;
965 void LogEntry (
char const *
string)
const;
968 void LogEntry (__wchar_t
const *
string)
const;
970 void LogEntry (
unsigned short const *
string)
const;
973 void CloseLogFile ()
alter;
976 unsigned int NextOpcodeSequence ()
alter {
return ++m_opcode_sequence; }
1006 void ClearLastKey ()
alter;
1016 { m_dictionary_format = format; m_dictionary_options = options; }
1052 void RecordPause (
int offset)
alter;
1070 else m_pause_table[0] = offset; }
1072 int GetFirstPause ()
const {
return (m_num_pauses > 0) ? m_pause_table[0] : 0; }
1083 void SetWorldBounding (
float const *bbox);
1090 void SetWorldBoundingBySphere (
float const *pt,
float radius);
1102 bool AddExternalReference (
char const * ref,
ID_Key context)
alter;
1109 bool AddExternalReference (__wchar_t
const * ref,
ID_Key context)
alter;
1111 bool AddExternalReference (
unsigned short const * ref,
ID_Key context)
alter;
1116 bool NextExternalReference ()
alter;
1120 __wchar_t const *GetExternalReference ()
const {
1121 return (m_external_references != 0) ? (__wchar_t
const*)m_external_references->Reference() : 0;
1127 return (m_external_references != 0) ? m_external_references->m_context : -1;
1146 ID_Key CurrentSegment ()
alter {
return (m_active_segments != 0) ? m_active_segments->key() : -1; }
1156 void ReportQuantizationError(
int bits_per_sample,
float const *bounding,
int num_dimensions = 3);
1166 if (m_geometry_open)
1167 return Error (
"recursive geometry open");
1168 m_geometry_open =
true;
1175 if (!m_geometry_open)
1176 return Error (
"no geometry open");
1177 m_geometry_open =
false;
1186 ID_Key RevisitKey ()
const {
return m_revisit_working ? m_revisit_working->m_key : -1; }
1187 ID_Key RevisitOwner ()
const {
return m_revisit_working ? m_revisit_working->m_owner : -1; }
1191 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1195 TK_Status write (
char const * b,
int n)
alter {
return m_accumulator.write (b, n); }
1205 ID_Key context_key ()
const {
return m_context_key; }
1209 if(m_last_keys_used == 1)
1210 return m_last_keys[0];
1217 bool find_item (
ID_Key key)
const;
1224 int pass ()
const {
return m_pass; }
1227 TK_Status revisit (
unsigned char opcode,
float priority,
int lod=0)
alter;
1231 int val1,
int val2 = 0,
int val3 = 0)
alter;
1234 bool find_instance (
BBaseOpcodeHandler *
object,
int val1,
int val2 = 0,
int val3 = 0) const;
1237 int position ()
const {
return m_position; }
1238 void set_position (
int pos)
alter { m_position = pos; }
1239 void mark_position ()
alter { set_position (GeneratedSoFar()); }
1251 TK_Status start_compression ()
alter {
return m_accumulator.start_compression(); }
1252 TK_Status stop_compression ()
alter {
return m_accumulator.stop_compression(
true); }
1253 TK_Status start_decompression ()
alter {
return m_accumulator.start_decompression(); }
1254 TK_Status stop_decompression (
bool force =
false)
alter {
return m_accumulator.stop_decompression(force); }
1255 virtual void empty_lists ()
alter;
1263 #ifndef BSTREAM_DISABLE_ASCII
1269 int n_tabs = m_tk->GetTabs();
1270 m_tk->SetTabs(++n_tabs);
1275 int n_tabs = m_tk->GetTabs();
1276 m_tk->SetTabs(--n_tabs);
1287 int cur_tabs = m_tk->GetTabs();
1288 if(cur_tabs >= n_tabs)
1291 m_tk->SetTabs(cur_tabs-n_tabs);
1302 int cur_tabs = m_tk->GetTabs();
1303 m_tk->SetTabs(cur_tabs+m_tabs);
1311 #endif //BSTREAM_DISABLE_ASCII
1313 #endif //BBINFILETK_TOOLKIT
Definition: BStreamFileToolkit.h:1264
ID_Key last_key(BStreamFileToolkit &tk) const
obsolete
Definition: BOpcodeHandler.h:640
void add_segment(BStreamFileToolkit &tk, ID_Key key) alter
for internal use only
Definition: BOpcodeHandler.h:634
Handles the TKE_Shell opcode.
Definition: BOpcodeShell.h:31
void decrease_nesting(BStreamFileToolkit &tk, int amount=1) alter
for internal use only
Definition: BOpcodeHandler.h:651
#define TK_DEFAULT_BUFFER_SIZE
default amount of the internal memory buffer used for file processing
Definition: BStream.h:173
void adjust_written(BStreamFileToolkit &tk, int count) alter
for internal use only
Definition: BOpcodeHandler.h:647
#define alter
complementary to const, indicates we thought about it instead of a forgotten "const" ...
Definition: BStream.h:225
void set_last_key(BStreamFileToolkit &tk, ID_Key key) alter
sets the given key as "most recent" on the toolkit for the purposes of associating keys with indices ...
Definition: BOpcodeHandler.h:638
Handles the TKE_Tag opcode.
Definition: BOpcodeHandler.h:1537
Definition: BStreamFileToolkit.h:37
Definition: BOpcodeHandler.h:865
Handles the TKE_Repeat_Object opcode.
Definition: BOpcodeHandler.h:1379
void increase_nesting(BStreamFileToolkit &tk, int amount=1) alter
for internal use only
Definition: BOpcodeHandler.h:649
Handles the TKE_Dictionary opcode.
Definition: BOpcodeHandler.h:1566
Definition: BStream.h:238
int m_stage
The writing stage.
Definition: BOpcodeHandler.h:62
The BBaseOpcodeHandler abstract class is used as a base for derived classes which manage logical piec...
Definition: BOpcodeHandler.h:60
TK_Status
Codes which can be either passed to various toolkit functions, or indicate the result of a toolkit fu...
Definition: BStream.h:237
dictionary entries include bounding volume info
Definition: BStream.h:282
#define ID_Key
Definition: BStream.h:219
Handles the TKE_Start_Compression and TKE_Stop_Compression opcodes.
Definition: BOpcodeHandler.h:1068
Definition: BStreamFileToolkit.h:1282
ID_Key remove_segment(BStreamFileToolkit &tk) alter
for internal use only
Definition: BOpcodeHandler.h:636
Provides HOOPS/3dGS-specific handling of the TKE_Reference opcode.
Definition: HOpcodeHandler.h:123