Alphabetical Class Index   Class Hierarchy   Compound Members   File Members   File List  

BStreamFileToolkit.h
1 //
2 // Copyright (c) 2000 by Tech Soft 3D, LLC.
3 // The information contained herein is confidential and proprietary to
4 // Tech Soft 3D, LLC., and considered a trade secret as defined under
5 // civil and criminal statutes. Tech Soft 3D shall pursue its civil
6 // and criminal remedies in the event of unauthorized use or misappropriation
7 // of its trade secrets. Use of this information by anyone other than
8 // authorized employees of Tech Soft 3D, LLC. is granted only under a
9 // written non-disclosure agreement, expressly prescribing the scope and
10 // manner of such use.
11 //
12 // $Id: d06076a5a20de72afaff569c8097bbe87d2dd380 $
13 //
14 
15 #ifndef BBINFILETK_TOOLKIT
16 #define BBINFILETK_TOOLKIT
17 
18 #ifndef _MSC_VER
19 # define __wchar_t wchar_t
20 #else
21 # ifdef _DEBUG
22 # include <crtdbg.h>
23 # endif
24 #endif
25 
26 #if defined(WIN64) || defined(_M_X64) || defined(_WIN64)
27 # define HLONG __int64
28 #else
29 # define HLONG long
30 #endif
31 
37 class BBINFILETK_API2 BControlledMemoryObject {
38  public:
39  void * operator new (size_t size);
40  void operator delete (void * p);
41 };
42 
43 class BBaseOpcodeHandler;
44 
45 
46 #ifndef DOXYGEN_SHOULD_SKIP_THIS
47 
48 /*
49  Buffers data so basic handlers can deal with simple Get/Put calls of basic data types (and arrays of those types).
50  Handles both reading and writing, ZLIB compressed or uncompressed.
51 */
52 class BBINFILETK_API2 Internal_Data_Accumulator {
53  private:
54  char * m_pending_buffer; /*< The whole burrito. */
55  int m_pending_buffer_allocated; /*< How big the buffer is (so we know when to reallocate) */
56  char * m_pending_position; /*< Start of actual data to be processed.*/
57  int m_pending_size; /*< Size of actual data. */
58 
59  char * m_buffer_data; /*< The buffer shown to the user (i.e. passed to GenerateBuffer or ParseBuffer) */
60  int m_buffer_size; /*< The size of the user's buffer */
61 
62  int m_failed_size; /*< When a read fails because of insufficient data, how much space would have been required for success? */
63 
64  int m_generated; /*< How much has been written into the user's buffer (after considering compression). */
65 
66  struct z_stream_s * m_z_stream; /*< The control structure for ZLIB */
67  bool m_compressed; /*< are we in compressed mode? */
68  bool m_writing; /*< are we compressing or decompressing? */
69  int m_original_size; /*< size of buffer originally passed in */
70 
71  public:
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 ();
77 
78  void set_data (char * b, int s) alter { m_buffer_data = b; m_original_size = m_buffer_size = s; }
79  void save () alter;
80  TK_Status consume () alter;
81 
82  TK_Status read (char alter * b, int s) alter;
83  TK_Status write (char const * b, int s) alter;
84  TK_Status lookat (char alter & b) alter;
85 
86  int get_original_buffer_size(){return m_original_size; }
87 
88  void restart () alter;
89  void clean () alter;
90  int unused () const { return m_buffer_size; }
91  int generated () const { return m_generated; }
92 
93  TK_Status start_compression () alter;
94  TK_Status stop_compression (bool flush) alter;
95  TK_Status start_decompression () alter;
96  TK_Status stop_decompression (bool force) alter;
97  bool compressed () const { return m_compressed; }
98 
99  TK_Status error (char const * msg = 0) const;
100 };
101 
102 
103 /*
104  Provides index <-> key translation, plus storage of additional item-specific data, such as
105  file offset and size and bounding volume.
106 */
107 struct IT_Index_Key_Extra {
108  int m_variants[8][2];
109  int m_options;
110  float m_bounds[6];
111 };
112 
113 class BBINFILETK_API2 Internal_Translator {
114  friend class TK_Dictionary; // note, dictionary writer tied closely to this implementation
115  private:
116  // array -- index to key is trivial
117  int m_size;
118  int m_used;
119 
120  struct Index_Key_Pair {
121  int m_index;
122  ID_Key m_key;
123  IT_Index_Key_Extra *m_extra;
124  } * m_pairs;
125 
126  enum Options {
127  Bounds_Valid = 0x0001,
128 
129  Extended = 0x0080 // reserved
130  };
131 
132  // hash of key to locate potential indices for key to index lookup
133  struct Hash_Block {
134  Hash_Block * m_next;
135  int m_used;
136  int m_indices[32];
137  } * m_blocks[1024];
138 
139 
140  public:
141  Internal_Translator () : m_size (0), m_used (0), m_pairs (0) { memset (m_blocks, 0, 1024*sizeof(void *)); }
142  ~Internal_Translator ();
143 
144  TK_Status add_pair (int index, ID_Key key) alter;
145  TK_Status add_variant (ID_Key key, int variant, int value1, int value2 = 0) alter;
146  TK_Status add_bounds (ID_Key key, float const * bounds) alter;
147  TK_Status index_to_key (int index, ID_Key alter & key) const;
148  TK_Status key_to_index (ID_Key key, int alter & index) const;
149  TK_Status key_variant_offset (ID_Key key, int variant,
150  int alter & offset, int alter & length, int alter & index) const;
151  TK_Status key_bounds (ID_Key key, float alter * bounds) const;
152  int used () const { return m_used; }
153 
154  void clean () alter;
155 
156  // older forms:
157  TK_Status key_variant_offset (ID_Key key, int variant, int alter & offset) const {
158  int length, index;
159  return key_variant_offset (key, variant, offset, length, index);
160  }
161  TK_Status key_variant_offset (ID_Key key, int variant, int alter & offset, int alter & length) const {
162  int index;
163  return key_variant_offset (key, variant, offset, length, index);
164  }
165 
166 };
167 
168 
169 class BBINFILETK_API2 Internal_Key_Record {
170  private:
171  // hash of key to list of recorded segments
172  struct Hash_Block {
173  Hash_Block * m_next;
174  int m_used;
175  ID_Key m_keys[32];
176  } * m_blocks[1024];
177 
178 
179  public:
180  Internal_Key_Record () { memset (m_blocks, 0, 1024*sizeof(void *)); }
181  ~Internal_Key_Record ();
182 
183  TK_Status add_key (ID_Key key) alter;
184  TK_Status find_key (ID_Key key) const;
185 
186  void clean () alter;
187 };
188 
189 
190 
191 // control memory on these objects, not sure who might be creating/destroying them
192 
193 class Internal_Segment_List : public BControlledMemoryObject {
194  public:
195  Internal_Segment_List * m_next;
196  ID_Key m_key;
197 
198  public:
199  Internal_Segment_List (ID_Key k) : m_next (0), m_key (k) {}
200 
201  ID_Key key () const { return m_key; }
202 };
203 
204 class Internal_Revisit_Item : public BControlledMemoryObject {
205  public:
206  Internal_Revisit_Item * m_next;
207  ID_Key m_key;
208  ID_Key m_owner;
209  int m_lod;
210  float m_priority;
211  char m_opcode;
212  bool m_force_context;
213 };
214 
215 
216 class Internal_ExRef_List : public BControlledMemoryObject {
217  public:
218  Internal_ExRef_List * m_next;
219  Internal_ExRef_List * m_caller;
220  __wchar_t * m_ref;
221  __wchar_t * m_actual;
222  ID_Key m_context;
223 
224  public:
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);
227 #ifdef _MSC_VER
228  Internal_ExRef_List (unsigned short const * ref, ID_Key context, Internal_ExRef_List * caller);
229 #endif
230  ~Internal_ExRef_List ();
231 
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;
237 #ifdef _MSC_VER
238  void SetActual (unsigned short const * actual) alter;
239 #endif
240 };
241 
242 
243 class BBINFILETK_API Recorded_Instance : public BControlledMemoryObject {
244  public:
245  Recorded_Instance * m_next;
246 
247  ID_Key m_key;
248  int m_variant;
249  int m_values[3];
250 
251  float m_local_basis[16]; // matrix from our basis to identity
252  int m_basis_indices[4];
253  float m_arbitrary_point[3];
254  int m_arbitrary_index;
255  bool m_basis_valid;
256 
257  unsigned char m_opcode;
258 
259 #ifdef _DEBUG
260  int m_times_used;
261 #endif
262 
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;
266 #ifdef _DEBUG
267  m_times_used = 0;
268 #endif
269  }
270 
271  bool basis_valid () const { return m_basis_valid; }
272  bool generate_basis (int count, float const * points) alter;
273 };
274 
275 class Internal_Segment_Processor;
276 
277 /*
278  Callback which can be used for reporting progress during writing/reading.
279  During writing:
280  so_far is number of "objects" written, expected is the number the toolkit will likely write.
281  Note: the toolkit won't know about objects in pre/post-walk handlers or extra objects due to
282  overloading the default classes, so "so_far" may exceed "expected"
283  During reading:
284  so_far is the number of bytes processed, expected is the file size.
285  user_data allows the application to pass any necessary values through.
286  returns a flag which indicates whether the processing should continue.
287 */
288 typedef bool (*TK_Progress_Callback) (unsigned HLONG so_far, unsigned HLONG expected, void * user_data);
289 
290 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
291 
292 
293 
295 
328 class BBINFILETK_API2 BStreamFileToolkit : public BControlledMemoryObject {
329  friend class BBaseOpcodeHandler;
330  friend class TK_Default;
331  friend class TK_Comment;
332  friend class TK_Header;
333  friend class TK_Compression;
334  friend class TK_Dictionary;
335  friend class Internal_Segment_Processor;
336  friend class TK_Shell;
337 
338  friend class TK_Tag;
339  friend class TK_Instance;
340  friend class HTK_Reference;
341  protected:
342 
343 #ifndef DOXYGEN_SHOULD_SKIP_THIS
344 
345  Internal_Data_Accumulator m_accumulator;
346  Internal_Translator m_translator;
348  BBaseOpcodeHandler * m_objects[256];
349  BBaseOpcodeHandler * m_default_object;
350  int m_prewalk_count;
351  int m_postwalk_count;
352  BBaseOpcodeHandler ** m_prewalk;
353  BBaseOpcodeHandler ** m_postwalk;
354  BBaseOpcodeHandler * m_current_object;
355  Internal_Segment_List * m_active_segments;
356  Internal_Key_Record m_visited_items;
357  ID_Key m_context_key;
358  ID_Key * m_last_keys;
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;
363  int m_stage;
364  int m_substage;
365  int m_pass;
366  int m_tag_count;
367  int m_position;
368  unsigned int m_offset;
369  int m_unused;
370  int m_write_flags;
371  int m_read_flags;
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;
377  int m_file_version;
378  int m_target_version;
379  bool m_header_comment_seen;
380  char * m_log_file;
381  FILE * m_log_fp;
382  bool m_logging;
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;
389  int m_buffer_limit;
390  int m_nesting_level;
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];
396  int m_jpeg_quality;
397  int * m_pause_table;
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;
408  int m_file_count;
409  int m_files_allocated;
410  __wchar_t * m_current_filename;
411  int m_index_base;
412  float m_quantization_error;
414  int m_save_write_flags;
415  __wchar_t * m_wfilename;
416  bool m_geometry_open;
418  bool m_is_ascii;
419  int m_num_tabs;
421  /* Internal use.
422  * A quick utility to verify that an array is in fact sorted.
423  * FOR DEBUGGING ONLY
424  */
425  bool issorted_revisit(Internal_Revisit_Item **array, int count);
426 
431  void qsort_revisit(Internal_Revisit_Item **, Internal_Revisit_Item **);
432  TK_Status sort_revisit();
433 
434  virtual void read_completed () alter;
435 
436  bool add_exref (Internal_ExRef_List * exref);
437 
438 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
439 
440 
441  protected:
442 
444  void * m_file;
445 
446  public:
447 
452  virtual ~BStreamFileToolkit ();
453 
457  static bool SupportsAsciiMode() {
458 #ifndef BSTREAM_DISABLE_ASCII
459  return true;
460 #else
461  return false;
462 #endif
463  }
464 
468  TK_Status SetAsciiMode(bool whether);
469 
473  bool GetAsciiMode();
474 
475  void SetTabs(int);
476  int GetTabs();
477 
483  static int ParseVersion (char const * block);
484 
518  TK_Status ParseBuffer (char const * b, int s, TK_Status mode = TK_Normal) alter;
519 
520 
526  TK_Status PrepareBuffer(char * b, int s) alter;
527 
529  int CurrentBufferLength() {return m_accumulator.get_original_buffer_size() -
530  m_accumulator.unused();}
531 
537  virtual void ActivateContext (ID_Key key) { (void)key; }
538 
544  virtual void DeactivateContext (ID_Key key) { (void)key; }
545 
553  virtual void NewFileContext (ID_Key key) { (void)key; }
554 
560  int GeneratedSoFar () const { return m_accumulator.generated(); }
561 
566  unsigned int ObjectsSoFar () const { return m_objects_written; }
567 
574  void SetOpcodeHandler (int which, BBaseOpcodeHandler * handler) alter;
575 
583  void SetPrewalkHandler (BBaseOpcodeHandler * handler) alter;
584 
585 
593  void SetPostwalkHandler (BBaseOpcodeHandler * handler) alter;
594 
596  BBaseOpcodeHandler * GetOpcodeHandler (int which) const { return m_objects[which]; }
597 
603  virtual void Restart () alter;
604 
605  // access to index <-> key tranlation
612  TK_Status IndexToKey (int index, ID_Key alter & key) const;
613 
620  TK_Status KeyToIndex (ID_Key key, int alter & index) const;
621 
628  TK_Status AddIndexKeyPair (int index, ID_Key key) alter
629  { return m_translator.add_pair (index, key); }
630 
639  TK_Status AddVariant (ID_Key key, int variant, int value1, int value2 = -1) alter
640  { return m_translator.add_variant (key, variant, value1, value2); }
641 
648  TK_Status AddBounds (ID_Key key, float const * bounds) alter
649  { return m_translator.add_bounds (key, bounds); }
650 
658  TK_Status GetOffset (ID_Key key, int variant, int alter & offset) const
659  { return m_translator.key_variant_offset (key, variant, offset); }
660 
669  TK_Status GetOffset (ID_Key key, int variant, int alter & offset, int alter & length) const
670  { return m_translator.key_variant_offset (key, variant, offset, length); }
671 
681  TK_Status GetOffset (ID_Key key, int variant,
682  int alter & offset, int alter & length, __wchar_t const * alter & filename) const;
683 #ifdef _MSC_VER
684  TK_Status GetOffset (ID_Key key, int variant,
685  int alter & offset, int alter & length, unsigned short const * alter & filename) const;
686 #endif
687 
693  TK_Status GetBounds (ID_Key key, float alter * bounds) const
694  { return m_translator.key_bounds (key, bounds); }
695 
700  int NextTagIndex () alter { return m_tag_count++; }
705  int PeekTagIndex () const { return m_tag_count; }
706 
712 #ifndef SWIG
713  void SetFilename (char const * name) alter;
714 #endif
715 
720  void SetFilename (__wchar_t const * name) alter;
721 #ifdef _MSC_VER
722  void SetFilename (unsigned short const * name) alter;
723 #endif
724 
728  TK_Status Read_Stream_File ();
729 
735 #ifndef SWIG
736  void SetNewFile (char const * name) alter;
737 #endif
738 
743  void SetNewFile (__wchar_t const * name) alter;
744 #ifdef _MSC_VER
745  void SetNewFile (unsigned short const * name) alter;
746 #endif
747 
751  __wchar_t const * GetCurrentFile () const { return (__wchar_t const*)m_current_filename; }
758 #ifndef SWIG
759  TK_Status SelectFile (char const * name) alter;
760 #endif
761 
767  TK_Status SelectFile (__wchar_t const * name) alter;
768 #ifdef _MSC_VER
769  TK_Status SelectFile (unsigned short const * name) alter;
770 #endif
771 
778 #ifndef SWIG
779  virtual TK_Status OpenFile (char const * name, bool write = false) alter;
780 #endif
781 
788  virtual TK_Status OpenFile (__wchar_t const * name, bool write = false) alter;
789 #ifdef _MSC_VER
790  virtual TK_Status OpenFile (unsigned short const * name, bool write = false) alter;
791 #endif
792 
796  virtual TK_Status CloseFile () alter;
797 
807  virtual TK_Status ReadBuffer (char alter * buffer, int size, int alter & amount_read) alter;
808 
817  virtual TK_Status WriteBuffer (char alter * buffer, int size) alter;
818 
828  virtual TK_Status PositionFile (int offset) alter;
829 
838  virtual TK_Status GetFileSize (unsigned HLONG & size) alter;
839 
840 
852  virtual TK_Status LocateDictionary () alter;
853 
864  virtual TK_Status LocateEntity (ID_Key key, int variant) alter;
865 
866  int GetFlags () const { return GetWriteFlags(); }
867  void SetFlags (int flags) alter { SetWriteFlags(flags); }
871  void SetWriteFlags (int flags) alter { m_write_flags = flags; }
877  int GetWriteFlags (int mask = ~0) const { return m_write_flags & mask; }
878 
880  void SetReadFlags (int flags) alter { m_read_flags = flags; }
886  int GetReadFlags (int mask = ~0) const { return m_read_flags & mask; }
887 
888 
889  int GetNumNormalBits () const { return m_num_normal_bits; }
895  void SetNumNormalBits (int numbits) alter { m_num_normal_bits = (numbits<=72) ? numbits : 72; }
896 
897  int GetNumVertexBits () const { return m_num_vertex_bits; }
899  void SetNumVertexBits (int numbits) alter { m_num_vertex_bits = (numbits<=72) ? numbits : 72; }
900  int GetNumParameterBits () const { return m_num_parameter_bits; }
905  void SetNumParameterBits (int numbits) alter { m_num_parameter_bits = (numbits<=72) ? numbits : 72; }
906  int GetNumColorBits () const { return m_num_color_bits; }
907  void SetNumColorBits (int numbits) alter { m_num_color_bits = (numbits<=72) ? numbits : 72; }
908  int GetNumIndexBits () const { return m_num_index_bits; }
909  void SetNumIndexBits (int numbits) alter { m_num_index_bits = (numbits<=24) ? numbits : 24; }
912  void SetJpegQuality (int quality = 75) alter { m_jpeg_quality = quality; }
914  int GetJpegQuality () const { return m_jpeg_quality; }
915 
916  int GetVersion () const { return m_file_version; }
917  void SetReadVersion (int version) { m_file_version = version; m_header_comment_seen = true; }
925  void SetTargetVersion (int version) alter { m_target_version = version; }
926  int GetTargetVersion () const { return m_target_version; }
928  unsigned int GetFileOffset () const { return m_offset; }
931  void SetFileOffset (unsigned int offset) alter { m_offset = offset; }
933  int Unused () const { return m_unused; }
937  virtual TK_Status Error(char const * msg = 0) const;
938 
940  char const *GetLogFile () const { return m_log_file; }
942  void SetLogFile (char const * filename = 0) alter;
943 
945  bool GetLogging () const { return m_logging; }
949  void SetLogging (bool setting) alter { m_logging = setting; }
950 
952  unsigned int GetLoggingOptions (unsigned int mask = ~0) const
953  { return m_logging_options & mask; }
955  void SetLoggingOptions (unsigned int options = ~0) alter
956  { m_logging_options = options; }
957 
962  TK_Status OpenLogFile (char const * filename, char const * mode) alter;
964 #ifndef SWIG
965  void LogEntry (char const * string) const;
966 #endif
967 
968  void LogEntry (__wchar_t const * string) const;
969 #ifdef _MSC_VER
970  void LogEntry (unsigned short const * string) const;
971 #endif
972 
973  void CloseLogFile () alter;
974 
976  unsigned int NextOpcodeSequence () alter { return ++m_opcode_sequence; }
978  void SetOpcodeSequence (unsigned int seq=0) alter { m_opcode_sequence = seq; }
979 
981  bool HeaderCommentSeen() const { return m_header_comment_seen; }
982 
984  TK_Progress_Callback GetProgressCallback () const { return m_progress_callback; }
986  void SetProgressCallback (TK_Progress_Callback cb = 0) alter { m_progress_callback = cb; }
987 
989  void * GetProgressValue () const { return m_progress_value; }
991  void SetProgressValue (void * value) alter { m_progress_value = value; }
992 
994  int GetBufferLimit () const { return m_buffer_limit; }
996  void SetBufferLimit (int limit) alter {
997  m_buffer_limit = (0 < limit && limit < TK_DEFAULT_BUFFER_SIZE) ?
998  limit : TK_DEFAULT_BUFFER_SIZE;
999  }
1000 
1002  void SetLastKey (ID_Key key) alter;
1004  TK_Status AppendLastKey (ID_Key key) alter;
1006  void ClearLastKey () alter;
1008  TK_Status GetLastKey (ID_Key &key) const;
1009 
1015  void SetDictionaryFormat (int format = 3, int options = TK_Dictionary_Bounding_Volumes) alter
1016  { m_dictionary_format = format; m_dictionary_options = options; }
1021  int GetDictionaryFormat () const { return m_dictionary_format; }
1026  int GetDictionaryOptions () const { return m_dictionary_options; }
1031  void SetDictionaryOffset (int offset) alter { m_dictionary_offset = offset; }
1036  int GetDictionaryOffset () const { return m_dictionary_offset; }
1041  void SetDictionarySize (int size) alter { m_dictionary_size = size; }
1046  int GetDictionarySize () const { return m_dictionary_size; }
1047 
1052  void RecordPause (int offset) alter;
1056  void ClearPauses () alter { m_num_pauses = 0; }
1061  int GetPauseCount () const { return m_num_pauses; }
1066  int const * GetPauseTable () const { return m_pause_table; }
1067 
1069  void SetFirstPause (int offset) alter { if (GetPauseCount() == 0) RecordPause (offset);
1070  else m_pause_table[0] = offset; }
1072  int GetFirstPause () const { return (m_num_pauses > 0) ? m_pause_table[0] : 0; }
1073 
1077  int GetPosition () const { return m_position; }
1078 
1083  void SetWorldBounding (float const *bbox);
1084 
1090  void SetWorldBoundingBySphere (float const *pt, float radius);
1091 
1093  float const * GetWorldBounding () const { return m_world_bounding; }
1094 
1095 
1101 #ifndef SWIG
1102  bool AddExternalReference (char const * ref, ID_Key context) alter;
1103 #endif
1104 
1109  bool AddExternalReference (__wchar_t const * ref, ID_Key context) alter;
1110 #ifdef _MSC_VER
1111  bool AddExternalReference (unsigned short const * ref, ID_Key context) alter;
1112 #endif
1113 
1116  bool NextExternalReference () alter;
1120  __wchar_t const *GetExternalReference () const {
1121  return (m_external_references != 0) ? (__wchar_t const*)m_external_references->Reference() : 0;
1122  }
1127  return (m_external_references != 0) ? m_external_references->m_context : -1;
1128  }
1129 
1133  virtual bool MatchPreviousExRef () const { return false; }
1134 
1138  void AddSegment (ID_Key key) alter;
1142  ID_Key RemoveSegment () alter;
1146  ID_Key CurrentSegment () alter { return (m_active_segments != 0) ? m_active_segments->key() : -1; }
1148  void ResetQuantizationError() { m_quantization_error = 0; }
1152  void ReportQuantizationError(float error) { if (error > m_quantization_error) m_quantization_error = error; };
1156  void ReportQuantizationError(int bits_per_sample, float const *bounding, int num_dimensions = 3);
1160  float GetQuantizationError() const { return m_quantization_error; }
1161 
1166  if (m_geometry_open)
1167  return Error ("recursive geometry open");
1168  m_geometry_open = true;
1169  return TK_Normal;
1170  }
1175  if (!m_geometry_open)
1176  return Error ("no geometry open");
1177  m_geometry_open = false;
1178  return TK_Normal;
1179  }
1180 
1184  bool GeometryIsOpen () const { return m_geometry_open; }
1185 
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; }
1188 
1189  protected:
1190 
1191 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1192 
1193  // normal data access for objects
1194  TK_Status read (char alter * b, int n) alter { return m_accumulator.read (b, n); }
1195  TK_Status write (char const * b, int n) alter { return m_accumulator.write (b, n); }
1196  TK_Status lookat (char alter & b) alter { return m_accumulator.lookat (b); }
1197 
1198  // used by segment handlers to make sure we know which segment should be "open"
1199  void add_segment (ID_Key key) alter { AddSegment (key); }
1200  ID_Key remove_segment () alter { return RemoveSegment(); }
1201 
1202  // used by renumber key, maybe by lookup functions (to be implemented...)
1204  void set_last_key (ID_Key key) alter { SetLastKey(key); }
1205  ID_Key context_key () const { return m_context_key; }
1206  void set_context_key (ID_Key key) alter;
1208  ID_Key last_key () const {
1209  if(m_last_keys_used == 1)
1210  return m_last_keys[0];
1211  else
1212  return -1;
1213  }
1214 
1215  // keep track of visited segments (for things like include)
1216  void remember_item (ID_Key key) alter;
1217  bool find_item (ID_Key key) const;
1218 
1220  BBaseOpcodeHandler alter * opcode_handler (int index) const { return m_objects[index]; }
1221 
1222  void adjust_written (int count) alter { m_objects_written += count; }
1223 
1224  int pass () const { return m_pass; }
1225 
1227  TK_Status revisit (unsigned char opcode, float priority, int lod=0) alter;
1228 
1230  void record_instance (ID_Key key, int variant, BBaseOpcodeHandler const * object,
1231  int val1, int val2 = 0, int val3 = 0) alter;
1232 
1234  bool find_instance (BBaseOpcodeHandler * object, int val1, int val2 = 0, int val3 = 0) const;
1235 
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()); }
1240 
1245  virtual TK_Status tag (int variant) alter;
1246 
1247  void increase_nesting (int amount = 1) alter { m_nesting_level += amount; }
1248  void decrease_nesting (int amount = 1) alter { m_nesting_level -= amount; }
1249 
1250  // utility
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;
1256 
1257 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
1258 
1259 };
1260 
1261 //TODO Documentation
1262 
1263 #ifndef BSTREAM_DISABLE_ASCII
1264 class PutTab
1265 {
1266 public:
1267  PutTab(BStreamFileToolkit* tk) : m_tk(tk)
1268  {
1269  int n_tabs = m_tk->GetTabs();
1270  m_tk->SetTabs(++n_tabs);
1271  }
1272 
1273  ~PutTab()
1274  {
1275  int n_tabs = m_tk->GetTabs();
1276  m_tk->SetTabs(--n_tabs);
1277  }
1278 
1279 private:
1280  BStreamFileToolkit* m_tk;
1281 };
1282 class Outdent
1283 {
1284 public:
1285  Outdent(BStreamFileToolkit* tk, int n_tabs = 1) : m_tk(tk)
1286  {
1287  int cur_tabs = m_tk->GetTabs();
1288  if(cur_tabs >= n_tabs)
1289  {
1290  m_tabs = n_tabs;
1291  m_tk->SetTabs(cur_tabs-n_tabs);
1292  }
1293  else
1294  {
1295  m_tabs = cur_tabs;
1296  m_tk->SetTabs(0);
1297  }
1298  }
1299 
1300  ~Outdent()
1301  {
1302  int cur_tabs = m_tk->GetTabs();
1303  m_tk->SetTabs(cur_tabs+m_tabs);
1304  }
1305 
1306 private:
1307  BStreamFileToolkit* m_tk;
1308  int m_tabs;
1309 };
1310 
1311 #endif //BSTREAM_DISABLE_ASCII
1312 
1313 #endif //BBINFILETK_TOOLKIT
Definition: BStreamFileToolkit.h:1264
ID_Key last_key(BStreamFileToolkit &tk) const
obsolete
Definition: BOpcodeHandler.h:640
void SetDictionaryOffset(int offset) alter
Definition: BStreamFileToolkit.h:1031
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
char const * GetLogFile() const
Definition: BStreamFileToolkit.h:940
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
int GetDictionarySize() const
Definition: BStreamFileToolkit.h:1046
__wchar_t const * GetCurrentFile() const
Definition: BStreamFileToolkit.h:751
virtual void NewFileContext(ID_Key key)
Definition: BStreamFileToolkit.h:553
int GetBufferLimit() const
Definition: BStreamFileToolkit.h:994
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
int GetNumColorBits() const
Definition: BStreamFileToolkit.h:906
TK_Status AddBounds(ID_Key key, float const *bounds) alter
Definition: BStreamFileToolkit.h:648
void SetTargetVersion(int version) alter
Definition: BStreamFileToolkit.h:925
TK_Progress_Callback GetProgressCallback() const
Definition: BStreamFileToolkit.h:984
Handles the TKE_Comment opcode.
Definition: BOpcodeHandler.h:974
void SetOpcodeSequence(unsigned int seq=0) alter
Definition: BStreamFileToolkit.h:978
The BStreamFileToolkit class provides support for importing/exporting HOOPS Stream File information...
Definition: BStreamFileToolkit.h:328
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
int NextTagIndex() alter
Definition: BStreamFileToolkit.h:700
void SetReadVersion(int version)
Definition: BStreamFileToolkit.h:917
Handles the TKE_Tag opcode.
Definition: BOpcodeHandler.h:1537
Definition: BStreamFileToolkit.h:37
void SetFlags(int flags) alter
Definition: BStreamFileToolkit.h:867
void SetLoggingOptions(unsigned int options=~0) alter
Definition: BStreamFileToolkit.h:955
void * m_file
Definition: BStreamFileToolkit.h:444
TK_Status CloseGeometry() alter
Definition: BStreamFileToolkit.h:1174
Definition: BOpcodeHandler.h:865
static bool SupportsAsciiMode()
Definition: BStreamFileToolkit.h:457
void SetProgressValue(void *value) alter
Definition: BStreamFileToolkit.h:991
int const * GetPauseTable() const
Definition: BStreamFileToolkit.h:1066
void SetFirstPause(int offset) alter
Definition: BStreamFileToolkit.h:1069
int GetFirstPause() const
Definition: BStreamFileToolkit.h:1072
int GetWriteFlags(int mask=~0) const
Definition: BStreamFileToolkit.h:877
TK_Status GetOffset(ID_Key key, int variant, int alter &offset) const
Definition: BStreamFileToolkit.h:658
int GetTargetVersion() const
Definition: BStreamFileToolkit.h:926
Handles the TKE_Repeat_Object opcode.
Definition: BOpcodeHandler.h:1379
int Unused() const
Definition: BStreamFileToolkit.h:933
void increase_nesting(BStreamFileToolkit &tk, int amount=1) alter
for internal use only
Definition: BOpcodeHandler.h:649
int GetPosition() const
Definition: BStreamFileToolkit.h:1077
void ClearPauses() alter
Definition: BStreamFileToolkit.h:1056
void SetNumVertexBits(int numbits) alter
Definition: BStreamFileToolkit.h:899
int GetDictionaryOptions() const
Definition: BStreamFileToolkit.h:1026
void SetNumNormalBits(int numbits) alter
Definition: BStreamFileToolkit.h:895
int GetReadFlags(int mask=~0) const
Definition: BStreamFileToolkit.h:886
Handles the TKE_Dictionary opcode.
Definition: BOpcodeHandler.h:1566
TK_Status GetBounds(ID_Key key, float alter *bounds) const
Definition: BStreamFileToolkit.h:693
Definition: BStream.h:238
BBaseOpcodeHandler * GetOpcodeHandler(int which) const
Definition: BStreamFileToolkit.h:596
float GetQuantizationError() const
Definition: BStreamFileToolkit.h:1160
float const * GetWorldBounding() const
Definition: BStreamFileToolkit.h:1093
void ReportQuantizationError(float error)
Definition: BStreamFileToolkit.h:1152
void SetNumParameterBits(int numbits) alter
Definition: BStreamFileToolkit.h:905
ID_Key GetExternalReferenceContext() const
Definition: BStreamFileToolkit.h:1126
int m_stage
The writing stage.
Definition: BOpcodeHandler.h:62
int GetDictionaryOffset() const
Definition: BStreamFileToolkit.h:1036
void SetWriteFlags(int flags) alter
Definition: BStreamFileToolkit.h:871
void ResetQuantizationError()
Definition: BStreamFileToolkit.h:1148
int PeekTagIndex() const
Definition: BStreamFileToolkit.h:705
TK_Status OpenGeometry() alter
Definition: BStreamFileToolkit.h:1165
void SetProgressCallback(TK_Progress_Callback cb=0) alter
Definition: BStreamFileToolkit.h:986
unsigned int GetLoggingOptions(unsigned int mask=~0) const
Definition: BStreamFileToolkit.h:952
bool GeometryIsOpen() const
Definition: BStreamFileToolkit.h:1184
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
bool HeaderCommentSeen() const
Definition: BStreamFileToolkit.h:981
int GetNumVertexBits() const
Definition: BStreamFileToolkit.h:897
void SetFileOffset(unsigned int offset) alter
Sets the file offset, a displacement to be added to positions used in the dictionary (for example...
Definition: BStreamFileToolkit.h:931
int GetNumParameterBits() const
Definition: BStreamFileToolkit.h:900
dictionary entries include bounding volume info
Definition: BStream.h:282
int GetPauseCount() const
Definition: BStreamFileToolkit.h:1061
void SetReadFlags(int flags) alter
Definition: BStreamFileToolkit.h:880
unsigned int ObjectsSoFar() const
Definition: BStreamFileToolkit.h:566
#define ID_Key
Definition: BStream.h:219
int GeneratedSoFar() const
Definition: BStreamFileToolkit.h:560
Utility class for managing HSF header information.
Definition: BOpcodeHandler.h:907
void SetNumColorBits(int numbits) alter
Definition: BStreamFileToolkit.h:907
TK_Status AddVariant(ID_Key key, int variant, int value1, int value2=-1) alter
Definition: BStreamFileToolkit.h:639
int GetNumIndexBits() const
Definition: BStreamFileToolkit.h:908
Handles the TKE_Start_Compression and TKE_Stop_Compression opcodes.
Definition: BOpcodeHandler.h:1068
void SetDictionarySize(int size) alter
Definition: BStreamFileToolkit.h:1041
void SetBufferLimit(int limit) alter
Definition: BStreamFileToolkit.h:996
virtual void DeactivateContext(ID_Key key)
Definition: BStreamFileToolkit.h:544
Definition: BStreamFileToolkit.h:1282
int GetDictionaryFormat() const
Definition: BStreamFileToolkit.h:1021
ID_Key remove_segment(BStreamFileToolkit &tk) alter
for internal use only
Definition: BOpcodeHandler.h:636
void SetLogging(bool setting) alter
Definition: BStreamFileToolkit.h:949
void * GetProgressValue() const
Definition: BStreamFileToolkit.h:989
TK_Status GetOffset(ID_Key key, int variant, int alter &offset, int alter &length) const
Definition: BStreamFileToolkit.h:669
int GetJpegQuality() const
Definition: BStreamFileToolkit.h:914
int GetNumNormalBits() const
Definition: BStreamFileToolkit.h:889
Provides HOOPS/3dGS-specific handling of the TKE_Reference opcode.
Definition: HOpcodeHandler.h:123
virtual bool MatchPreviousExRef() const
Definition: BStreamFileToolkit.h:1133
void SetJpegQuality(int quality=75) alter
Definition: BStreamFileToolkit.h:912
int GetVersion() const
Definition: BStreamFileToolkit.h:916
virtual void ActivateContext(ID_Key key)
Definition: BStreamFileToolkit.h:537
void SetNumIndexBits(int numbits) alter
Definition: BStreamFileToolkit.h:909