Alphabetical Class Index   Class Hierarchy   Compound Members   File Members   File List  

BStreamFileToolkit.h
1 // Copyright (c) 1998-2014 by Tech Soft 3D, Inc.
2 //
3 // The information contained herein is confidential and proprietary to Tech Soft 3D, Inc.,
4 // and considered a trade secret as defined under civil and criminal statutes.
5 // Tech Soft 3D, Inc. shall pursue its civil and criminal remedies in the event of
6 // unauthorized use or misappropriation of its trade secrets. Use of this information
7 // by anyone other than authorized employees of Tech Soft 3D, Inc. is granted only under
8 // a written non-disclosure agreement, expressly prescribing the scope and manner of such use.
9 
10 #ifndef BBINFILETK_TOOLKIT
11 #define BBINFILETK_TOOLKIT
12 
13 #ifndef _MSC_VER
14 # define __wchar_t wchar_t
15 #else
16 # ifdef _DEBUG
17 # include <crtdbg.h>
18 # endif
19 #endif
20 
21 #if defined(WIN64) || defined(_M_X64) || defined(_WIN64)
22 # define HLONG __int64
23 #else
24 # define HLONG long
25 #endif
26 
27 #include "BStreamMemory.h"
28 
34 class BBINFILETK_API2 BControlledMemoryObject {
35  public:
36  void * operator new (size_t size);
37  void operator delete (void * p);
38 };
39 
40 class BBaseOpcodeHandler;
41 
42 
43 #ifndef DOXYGEN_SHOULD_SKIP_THIS
44 
45 /*
46  Buffers data so basic handlers can deal with simple Get/Put calls of basic data types (and arrays of those types).
47  Handles both reading and writing, ZLIB compressed or uncompressed.
48 */
49 class BBINFILETK_API2 Internal_Data_Accumulator
50 #ifdef HPS_CORE_BUILD
51  : public CMO
52 #else
54 #endif
55 {
56  private:
57  char * m_pending_buffer; /*< The whole burrito. */
58  int m_pending_buffer_allocated; /*< How big the buffer is (so we know when to reallocate) */
59  char * m_pending_position; /*< Start of actual data to be processed.*/
60  int m_pending_size; /*< Size of actual data. */
61 
62  char * m_buffer_data; /*< The buffer shown to the user (i.e. passed to GenerateBuffer or ParseBuffer) */
63  int m_buffer_size; /*< The size of the user's buffer */
64 
65  int m_failed_size; /*< When a read fails because of insufficient data, how much space would have been required for success? */
66 
67  int m_generated; /*< How much has been written into the user's buffer (after considering compression). */
68 
69  struct z_stream_s * m_z_stream; /*< The control structure for ZLIB */
70  bool m_compressed; /*< are we in compressed mode? */
71  bool m_writing; /*< are we compressing or decompressing? */
72  int m_original_size; /*< size of buffer originally passed in */
73 
74  public:
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 ();
80 
81  void set_data (char * b, int s) { m_buffer_data = b; m_original_size = m_buffer_size = s; }
82  void save ();
83  TK_Status consume ();
84 
85  TK_Status read (char * b, int s);
86  TK_Status write (char const * b, int s);
87  TK_Status lookat (char & b);
88 
89  int get_original_buffer_size(){return m_original_size; }
90 
91  void restart ();
92  void clean ();
93  int unused () const { return m_buffer_size; }
94  int generated () const { return m_generated; }
95 
96  TK_Status start_compression ();
97  TK_Status stop_compression (bool flush);
98  TK_Status start_decompression ();
99  TK_Status stop_decompression (bool force);
100  bool compressed () const { return m_compressed; }
101 
102  TK_Status error (char const * msg = 0) const;
103 };
104 
105 
106 /*
107  Provides index <-> key translation, plus storage of additional item-specific data, such as
108  file offset and size and bounding volume.
109 */
110 struct IT_Index_Key_Extra {
111  int m_variants[8][2];
112  int m_options;
113  float m_bounds[6];
114 };
115 
116 class BBINFILETK_API2 Internal_Translator
117 #ifdef HPS_CORE_BUILD
118  : public CMO
119 #else
120  : public BControlledMemoryObject
121 #endif
122 {
123  friend class TK_Dictionary; // note, dictionary writer tied closely to this implementation
124  private:
125  // array -- index to key is trivial
126  int m_size;
127  int m_used;
128 
129  struct Index_Key_Pair {
130  int m_index;
131  ID_Key m_key;
132  IT_Index_Key_Extra *m_extra;
133  } * m_pairs;
134 
135  enum Options {
136  Bounds_Valid = 0x0001,
137 
138  Extended = 0x0080 // reserved
139  };
140 
141  // hash of key to locate potential indices for key to index lookup
142  struct Hash_Block {
143  Hash_Block * m_next;
144  int m_used;
145  int m_indices[32];
146  } * m_blocks[1024];
147 
148 
149  public:
150  Internal_Translator () : m_size (0), m_used (0), m_pairs (0) { memset (m_blocks, 0, 1024*sizeof(void *)); }
151  ~Internal_Translator ();
152 
153  TK_Status add_pair (int index, ID_Key key);
154  TK_Status add_variant (ID_Key key, int variant, int value1, int value2 = 0);
155  TK_Status add_bounds (ID_Key key, float const * bounds);
156  TK_Status index_to_key (int index, ID_Key & key) const;
157  TK_Status key_to_index (ID_Key key, int & index) const;
158  TK_Status key_variant_offset (ID_Key key, int variant,
159  int & offset, int & length, int & index) const;
160  TK_Status key_bounds (ID_Key key, float * bounds) const;
161  int used () const { return m_used; }
162 
163  void clean ();
164 
165  // older forms:
166  TK_Status key_variant_offset (ID_Key key, int variant, int & offset) const {
167  int length, index;
168  return key_variant_offset (key, variant, offset, length, index);
169  }
170  TK_Status key_variant_offset (ID_Key key, int variant, int & offset, int & length) const {
171  int index;
172  return key_variant_offset (key, variant, offset, length, index);
173  }
174 
175 };
176 
177 
178 class BBINFILETK_API2 Internal_Key_Record
179 #ifdef HPS_CORE_BUILD
180  : public CMO
181 #else
182  : public BControlledMemoryObject
183 #endif
184 {
185  private:
186  // hash of key to list of recorded segments
187  struct Hash_Block {
188  Hash_Block * m_next;
189  int m_used;
190  ID_Key m_keys[32];
191  } * m_blocks[1024];
192 
193 
194  public:
195  Internal_Key_Record () { memset (m_blocks, 0, 1024*sizeof(void *)); }
196  ~Internal_Key_Record ();
197 
198  TK_Status add_key (ID_Key key);
199  TK_Status find_key (ID_Key key) const;
200 
201  void clean ();
202 };
203 
204 
205 
206 // control memory on these objects, not sure who might be creating/destroying them
207 
208 class Internal_Segment_List
209 #ifdef HPS_CORE_BUILD
210  : public CMO
211 #else
212  : public BControlledMemoryObject
213 #endif
214 {
215  public:
216  Internal_Segment_List * m_next;
217  ID_Key m_key;
218 
219  public:
220  Internal_Segment_List (ID_Key k) : m_next (0), m_key (k) {}
221 
222  ID_Key key () const { return m_key; }
223 };
224 
225 class Internal_Revisit_Item
226 #ifdef HPS_CORE_BUILD
227  : public CMO
228 #else
229  : public BControlledMemoryObject
230 #endif
231 {
232  public:
233  Internal_Revisit_Item * m_next;
234  ID_Key m_key;
235  ID_Key m_owner;
236  int m_lod;
237  float m_priority;
238  char m_opcode;
239  bool m_force_context;
240 };
241 
242 
243 class Internal_ExRef_List
244 #ifdef HPS_CORE_BUILD
245  : public CMO
246 #else
247  : public BControlledMemoryObject
248 #endif
249 {
250  public:
251  Internal_ExRef_List * m_next;
252  Internal_ExRef_List * m_caller;
253  wchar_t * m_ref;
254  wchar_t * m_actual;
255  ID_Key m_context;
256 
257  public:
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);
260 #ifdef _MSC_VER
261  Internal_ExRef_List (unsigned short const * ref, ID_Key context, Internal_ExRef_List * caller);
262 #endif
263  ~Internal_ExRef_List ();
264 
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);
270 #ifdef _MSC_VER
271  void SetActual (unsigned short const * actual);
272 #endif
273 };
274 
275 
276 class BBINFILETK_API Recorded_Instance
277 #ifdef HPS_CORE_BUILD
278  : public CMO
279 #else
280  : public BControlledMemoryObject
281 #endif
282 {
283  public:
284  Recorded_Instance * m_next;
285 
286  ID_Key m_key;
287  int m_variant;
288  int m_values[3];
289 
290  float m_local_basis[16]; // matrix from our basis to identity
291  int m_basis_indices[4];
292  float m_arbitrary_point[3];
293  int m_arbitrary_index;
294  bool m_basis_valid;
295 
296  unsigned char m_opcode;
297 
298 #ifdef _DEBUG
299  int m_times_used;
300 #endif
301 
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;
305 #ifdef _DEBUG
306  m_times_used = 0;
307 #endif
308  }
309 
310  bool basis_valid () const { return m_basis_valid; }
311  bool generate_basis (int count, float const * points);
312 };
313 
314 class Internal_Segment_Processor;
315 
316 /*
317  Callback which can be used for reporting progress during writing/reading.
318  During writing:
319  so_far is number of "objects" written, expected is the number the toolkit will likely write.
320  Note: the toolkit won't know about objects in pre/post-walk handlers or extra objects due to
321  overloading the default classes, so "so_far" may exceed "expected"
322  During reading:
323  so_far is the number of bytes processed, expected is the file size.
324  user_data allows the application to pass any necessary values through.
325  returns a flag which indicates whether the processing should continue.
326 */
327 typedef bool (*TK_Progress_Callback) (unsigned HLONG so_far, unsigned HLONG expected, void * user_data);
328 
329 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
330 
331 
332 
334 
367 class BBINFILETK_API2 BStreamFileToolkit
368 #ifdef HPS_CORE_BUILD
369  : public CMO
370 #else
371  : public BControlledMemoryObject
372 #endif
373 {
374  friend class BBaseOpcodeHandler;
375  friend class TK_Default;
376  friend class TK_Comment;
377  friend class TK_Header;
378  friend class TK_Compression;
379  friend class TK_Dictionary;
380  friend class Internal_Segment_Processor;
381  friend class TK_Shell;
382 
383  friend class TK_Tag;
384  friend class TK_Instance;
385  friend class HTK_Reference;
386  protected:
387 
388 #ifndef DOXYGEN_SHOULD_SKIP_THIS
389 
390  Internal_Data_Accumulator m_accumulator;
391  Internal_Translator m_translator;
393  BBaseOpcodeHandler * m_objects[256];
394  BBaseOpcodeHandler * m_default_object;
395  int m_prewalk_count;
396  int m_postwalk_count;
397  BBaseOpcodeHandler ** m_prewalk;
398  BBaseOpcodeHandler ** m_postwalk;
399  BBaseOpcodeHandler * m_current_object;
400  Internal_Segment_List * m_active_segments;
401  Internal_Key_Record m_visited_items;
402  ID_Key m_context_key;
403  ID_Key * m_last_keys;
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;
408  int m_stage;
409  int m_substage;
410  int m_pass;
411  int m_tag_count;
412  int m_position;
413  unsigned int m_offset;
414  int m_unused;
415  int m_write_flags;
416  int m_read_flags;
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;
422  int m_file_version;
423  int m_target_version;
424  bool m_header_comment_seen;
425  char * m_log_file;
426  FILE * m_log_fp;
427  bool m_logging;
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;
434  int m_buffer_limit;
435  int m_nesting_level;
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];
441  int m_jpeg_quality;
442  int * m_pause_table;
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;
453  int m_file_count;
454  int m_files_allocated;
455  wchar_t * m_current_filename;
456  int m_index_base;
457  float m_quantization_error;
459  int m_save_write_flags;
460  wchar_t * m_wfilename;
461  bool m_geometry_open;
463  bool m_is_ascii;
464  int m_num_tabs;
466  /* Internal use.
467  * A quick utility to verify that an array is in fact sorted.
468  * FOR DEBUGGING ONLY
469  */
470  bool issorted_revisit(Internal_Revisit_Item **array, int count);
471 
476  void qsort_revisit(Internal_Revisit_Item **, Internal_Revisit_Item **);
477  TK_Status sort_revisit();
478 
479  virtual void read_completed ();
480 
481  bool add_exref (Internal_ExRef_List * exref);
482 
483 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
484 
485 
486  protected:
487 
489  void * m_file;
490 
491  public:
492 
497  virtual ~BStreamFileToolkit ();
498 
502  static bool SupportsAsciiMode() {
503 #ifndef BSTREAM_DISABLE_ASCII
504  return true;
505 #else
506  return false;
507 #endif
508  }
509 
513  TK_Status SetAsciiMode(bool whether);
514 
518  bool GetAsciiMode();
519 
520  void SetTabs(int);
521  int GetTabs();
522 
528  static int ParseVersion (char const * block);
529 
563  TK_Status ParseBuffer (char const * b, int s, TK_Status mode = TK_Normal);
564 
565 
571  TK_Status PrepareBuffer(char * b, int s);
572 
574  int CurrentBufferLength() {return m_accumulator.get_original_buffer_size() -
575  m_accumulator.unused();}
576 
582  virtual void ActivateContext (ID_Key key) { (void)key; }
583 
589  virtual void DeactivateContext (ID_Key key) { (void)key; }
590 
598  virtual void NewFileContext (ID_Key key) { (void)key; }
599 
605  int GeneratedSoFar () const { return m_accumulator.generated(); }
606 
611  unsigned int ObjectsSoFar () const { return m_objects_written; }
612 
619  void SetOpcodeHandler (int which, BBaseOpcodeHandler * handler);
620 
628  void SetPrewalkHandler (BBaseOpcodeHandler * handler);
629 
630 
638  void SetPostwalkHandler (BBaseOpcodeHandler * handler);
639 
641  BBaseOpcodeHandler * GetOpcodeHandler (int which) const { return m_objects[which]; }
642 
648  virtual void Restart ();
649 
650  // access to index <-> key tranlation
657  TK_Status IndexToKey (int index, ID_Key & key) const;
658 
665  TK_Status KeyToIndex (ID_Key key, int & index) const;
666 
674  { return m_translator.add_pair (index, key); }
675 
684  TK_Status AddVariant (ID_Key key, int variant, int value1, int value2 = -1)
685  { return m_translator.add_variant (key, variant, value1, value2); }
686 
693  TK_Status AddBounds (ID_Key key, float const * bounds)
694  { return m_translator.add_bounds (key, bounds); }
695 
703  TK_Status GetOffset (ID_Key key, int variant, int & offset) const
704  { return m_translator.key_variant_offset (key, variant, offset); }
705 
714  TK_Status GetOffset (ID_Key key, int variant, int & offset, int & length) const
715  { return m_translator.key_variant_offset (key, variant, offset, length); }
716 
726  TK_Status GetOffset (ID_Key key, int variant,
727  int & offset, int & length, __wchar_t const *& filename) const;
728 #ifdef _MSC_VER
729  TK_Status GetOffset (ID_Key key, int variant,
730  int & offset, int & length, unsigned short const *& filename) const;
731 #endif
732 
738  TK_Status GetBounds (ID_Key key, float * bounds) const
739  { return m_translator.key_bounds (key, bounds); }
740 
745  int NextTagIndex () { return m_tag_count++; }
750  int PeekTagIndex () const { return m_tag_count; }
751 
757 #ifndef SWIG
758  void SetFilename (char const * name);
759 #endif
760 
765  void SetFilename (__wchar_t const * name);
766 #ifdef _MSC_VER
767  void SetFilename (unsigned short const * name);
768 #endif
769 
773  TK_Status Read_Stream_File ();
774 
780 #ifndef SWIG
781  void SetNewFile (char const * name);
782 #endif
783 
788  void SetNewFile (__wchar_t const * name);
789 #ifdef _MSC_VER
790  void SetNewFile (unsigned short const * name);
791 #endif
792 
796  wchar_t const * GetCurrentFile () const { return (wchar_t const*)m_current_filename; }
803 #ifndef SWIG
804  TK_Status SelectFile (char const * name);
805 #endif
806 
812  TK_Status SelectFile (__wchar_t const * name);
813 #ifdef _MSC_VER
814  TK_Status SelectFile (unsigned short const * name);
815 #endif
816 
823 #ifndef SWIG
824  virtual TK_Status OpenFile (char const * name, bool write = false);
825 #endif
826 
833  virtual TK_Status OpenFile (__wchar_t const * name, bool write = false);
834 #ifdef _MSC_VER
835  virtual TK_Status OpenFile (unsigned short const * name, bool write = false);
836 #endif
837 
841  virtual TK_Status CloseFile ();
842 
852  virtual TK_Status ReadBuffer (char * buffer, int size, int & amount_read);
853 
862  virtual TK_Status WriteBuffer (char * buffer, int size);
863 
873  virtual TK_Status PositionFile (int offset);
874 
883  virtual TK_Status GetFileSize (unsigned HLONG & size);
884 
885 
897  virtual TK_Status LocateDictionary ();
898 
909  virtual TK_Status LocateEntity (ID_Key key, int variant);
910 
911  int GetFlags () const { return GetWriteFlags(); }
912  void SetFlags (int flags) { SetWriteFlags(flags); }
916  void SetWriteFlags (int flags) { m_write_flags = flags; }
922  int GetWriteFlags (int mask = ~0) const { return m_write_flags & mask; }
923 
925  void SetReadFlags (int flags) { m_read_flags = flags; }
931  int GetReadFlags (int mask = ~0) const { return m_read_flags & mask; }
932 
933 
934  int GetNumNormalBits () const { return m_num_normal_bits; }
940  void SetNumNormalBits (int numbits) { m_num_normal_bits = (numbits<=72) ? numbits : 72; }
941 
942  int GetNumVertexBits () const { return m_num_vertex_bits; }
944  void SetNumVertexBits (int numbits) { m_num_vertex_bits = (numbits<=72) ? numbits : 72; }
945  int GetNumParameterBits () const { return m_num_parameter_bits; }
950  void SetNumParameterBits (int numbits) { m_num_parameter_bits = (numbits<=72) ? numbits : 72; }
951  int GetNumColorBits () const { return m_num_color_bits; }
952  void SetNumColorBits (int numbits) { m_num_color_bits = (numbits<=72) ? numbits : 72; }
953  int GetNumIndexBits () const { return m_num_index_bits; }
954  void SetNumIndexBits (int numbits) { m_num_index_bits = (numbits<=24) ? numbits : 24; }
957  void SetJpegQuality (int quality = 75) { m_jpeg_quality = quality; }
959  int GetJpegQuality () const { return m_jpeg_quality; }
960 
961  int GetVersion () const { return m_file_version; }
962  void SetReadVersion (int version) { m_file_version = version; m_header_comment_seen = true; }
970  void SetTargetVersion (int version) { m_target_version = version; }
971  int GetTargetVersion () const { return m_target_version; }
973  unsigned int GetFileOffset () const { return m_offset; }
976  void SetFileOffset (unsigned int offset) { m_offset = offset; }
978  int Unused () const { return m_unused; }
982  virtual TK_Status Error(char const * msg = 0) const;
983 
985  char const *GetLogFile () const { return m_log_file; }
987  void SetLogFile (char const * filename = 0);
988 
990  bool GetLogging () const { return m_logging; }
994  void SetLogging (bool setting) { m_logging = setting; }
995 
997  unsigned int GetLoggingOptions (unsigned int mask = ~0) const
998  { return m_logging_options & mask; }
1000  void SetLoggingOptions (unsigned int options = ~0)
1001  { m_logging_options = options; }
1002 
1007  TK_Status OpenLogFile (char const * filename, char const * mode);
1009 #ifndef SWIG
1010  void LogEntry (char const * string) const;
1011 #endif
1012 
1013  void LogEntry (__wchar_t const * string) const;
1014 #ifdef _MSC_VER
1015  void LogEntry (unsigned short const * string) const;
1016 #endif
1017 
1018  void CloseLogFile ();
1019 
1021  unsigned int NextOpcodeSequence () { return ++m_opcode_sequence; }
1023  void SetOpcodeSequence (unsigned int seq=0) { m_opcode_sequence = seq; }
1024 
1026  bool HeaderCommentSeen() const { return m_header_comment_seen; }
1027 
1029  TK_Progress_Callback GetProgressCallback () const { return m_progress_callback; }
1031  void SetProgressCallback (TK_Progress_Callback cb = 0) { m_progress_callback = cb; }
1032 
1034  void * GetProgressValue () const { return m_progress_value; }
1036  void SetProgressValue (void * value) { m_progress_value = value; }
1037 
1039  int GetBufferLimit () const { return m_buffer_limit; }
1041  void SetBufferLimit (int limit) {
1042  m_buffer_limit = (0 < limit && limit < TK_DEFAULT_BUFFER_SIZE) ?
1043  limit : TK_DEFAULT_BUFFER_SIZE;
1044  }
1045 
1047  void SetLastKey (ID_Key key);
1049  TK_Status AppendLastKey (ID_Key key);
1051  void ClearLastKey ();
1053  TK_Status GetLastKey (ID_Key &key) const;
1054 
1060  void SetDictionaryFormat (int format = 3, int options = TK_Dictionary_Bounding_Volumes)
1061  { m_dictionary_format = format; m_dictionary_options = options; }
1066  int GetDictionaryFormat () const { return m_dictionary_format; }
1071  int GetDictionaryOptions () const { return m_dictionary_options; }
1076  void SetDictionaryOffset (int offset) { m_dictionary_offset = offset; }
1081  int GetDictionaryOffset () const { return m_dictionary_offset; }
1086  void SetDictionarySize (int size) { m_dictionary_size = size; }
1091  int GetDictionarySize () const { return m_dictionary_size; }
1092 
1097  void RecordPause (int offset);
1101  void ClearPauses () { m_num_pauses = 0; }
1106  int GetPauseCount () const { return m_num_pauses; }
1111  int const * GetPauseTable () const { return m_pause_table; }
1112 
1114  void SetFirstPause (int offset) { if (GetPauseCount() == 0) RecordPause (offset);
1115  else m_pause_table[0] = offset; }
1117  int GetFirstPause () const { return (m_num_pauses > 0) ? m_pause_table[0] : 0; }
1118 
1122  int GetPosition () const { return m_position; }
1123 
1128  void SetWorldBounding (float const *bbox);
1129 
1135  void SetWorldBoundingBySphere (float const *pt, float radius);
1136 
1138  float const * GetWorldBounding () const { return m_world_bounding; }
1139 
1140 
1146 #ifndef SWIG
1147  bool AddExternalReference (char const * ref, ID_Key context);
1148 #endif
1149 
1154  bool AddExternalReference (__wchar_t const * ref, ID_Key context);
1155 #ifdef _MSC_VER
1156  bool AddExternalReference (unsigned short const * ref, ID_Key context);
1157 #endif
1158 
1161  bool NextExternalReference ();
1165  wchar_t const * GetExternalReference () const {
1166  return (m_external_references != 0) ? (wchar_t const*)m_external_references->Reference() : 0;
1167  }
1172  return (m_external_references != 0) ? m_external_references->m_context : -1;
1173  }
1174 
1178  virtual bool MatchPreviousExRef () const { return false; }
1179 
1183  void AddSegment (ID_Key key);
1187  ID_Key RemoveSegment ();
1191  ID_Key CurrentSegment () { return (m_active_segments != 0) ? m_active_segments->key() : -1; }
1193  void ResetQuantizationError() { m_quantization_error = 0; }
1197  void ReportQuantizationError(float error) { if (error > m_quantization_error) m_quantization_error = error; };
1201  void ReportQuantizationError(int bits_per_sample, float const *bounding, int num_dimensions = 3);
1205  float GetQuantizationError() const { return m_quantization_error; }
1206 
1211  if (m_geometry_open)
1212  return Error ("recursive geometry open");
1213  m_geometry_open = true;
1214  return TK_Normal;
1215  }
1220  if (!m_geometry_open)
1221  return Error ("no geometry open");
1222  m_geometry_open = false;
1223  return TK_Normal;
1224  }
1225 
1229  bool GeometryIsOpen () const { return m_geometry_open; }
1230 
1231  ID_Key RevisitKey () const { return m_revisit_working ? m_revisit_working->m_key : -1; }
1232  ID_Key RevisitOwner () const { return m_revisit_working ? m_revisit_working->m_owner : -1; }
1233 
1234  protected:
1235 
1236 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1237 
1238  // normal data access for objects
1239  TK_Status read (char * b, int n) { return m_accumulator.read (b, n); }
1240  TK_Status write (char const * b, int n) { return m_accumulator.write (b, n); }
1241  TK_Status lookat (char & b) { return m_accumulator.lookat (b); }
1242 
1243  // used by segment handlers to make sure we know which segment should be "open"
1244  void add_segment (ID_Key key) { AddSegment (key); }
1245  ID_Key remove_segment () { return RemoveSegment(); }
1246 
1247  // used by renumber key, maybe by lookup functions (to be implemented...)
1249  void set_last_key (ID_Key key) { SetLastKey(key); }
1250  ID_Key context_key () const { return m_context_key; }
1251  void set_context_key (ID_Key key);
1253  ID_Key last_key () const {
1254  if(m_last_keys_used == 1)
1255  return m_last_keys[0];
1256  else
1257  return -1;
1258  }
1259 
1260  // keep track of visited segments (for things like include)
1261  void remember_item (ID_Key key);
1262  bool find_item (ID_Key key) const;
1263 
1265  BBaseOpcodeHandler * opcode_handler (int index) const { return m_objects[index]; }
1266 
1267  void adjust_written (int count) { m_objects_written += count; }
1268 
1269  int pass () const { return m_pass; }
1270 
1272  TK_Status revisit (unsigned char opcode, float priority, int lod=0);
1273 
1275  void record_instance (ID_Key key, int variant, BBaseOpcodeHandler const * object,
1276  int val1, int val2 = 0, int val3 = 0);
1277 
1279  bool find_instance (BBaseOpcodeHandler * object, int val1, int val2 = 0, int val3 = 0) const;
1280 
1282  int position () const { return m_position; }
1283  void set_position (int pos) { m_position = pos; }
1284  void mark_position () { set_position (GeneratedSoFar()); }
1285 
1290  virtual TK_Status tag (int variant);
1291 
1292  void increase_nesting (int amount = 1) { m_nesting_level += amount; }
1293  void decrease_nesting (int amount = 1) { m_nesting_level -= amount; }
1294 
1295  // utility
1296  TK_Status start_compression () { return m_accumulator.start_compression(); }
1297  TK_Status stop_compression () { return m_accumulator.stop_compression(true); }
1298  TK_Status start_decompression () { return m_accumulator.start_decompression(); }
1299  TK_Status stop_decompression (bool force = false) { return m_accumulator.stop_decompression(force); }
1300  virtual void empty_lists ();
1301 
1302 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
1303 
1304 };
1305 
1306 //TODO Documentation
1307 
1308 #ifndef BSTREAM_DISABLE_ASCII
1309 class PutTab
1310 {
1311 public:
1312  PutTab(BStreamFileToolkit* tk) : m_tk(tk)
1313  {
1314  int n_tabs = m_tk->GetTabs();
1315  m_tk->SetTabs(++n_tabs);
1316  }
1317 
1318  ~PutTab()
1319  {
1320  int n_tabs = m_tk->GetTabs();
1321  m_tk->SetTabs(--n_tabs);
1322  }
1323 
1324 private:
1325  BStreamFileToolkit* m_tk;
1326 };
1327 class Outdent
1328 {
1329 public:
1330  Outdent(BStreamFileToolkit* tk, int n_tabs = 1) : m_tk(tk)
1331  {
1332  int cur_tabs = m_tk->GetTabs();
1333  if(cur_tabs >= n_tabs)
1334  {
1335  m_tabs = n_tabs;
1336  m_tk->SetTabs(cur_tabs-n_tabs);
1337  }
1338  else
1339  {
1340  m_tabs = cur_tabs;
1341  m_tk->SetTabs(0);
1342  }
1343  }
1344 
1345  ~Outdent()
1346  {
1347  int cur_tabs = m_tk->GetTabs();
1348  m_tk->SetTabs(cur_tabs+m_tabs);
1349  }
1350 
1351 private:
1352  BStreamFileToolkit* m_tk;
1353  int m_tabs;
1354 };
1355 
1356 #endif //BSTREAM_DISABLE_ASCII
1357 
1358 #endif //BBINFILETK_TOOLKIT
Definition: BStreamFileToolkit.h:1309
Handles the TKE_Shell opcode.
Definition: BOpcodeShell.h:25
char const * GetLogFile() const
Definition: BStreamFileToolkit.h:985
bool GetLogging() const
Definition: BStreamFileToolkit.h:990
int GetFlags() const
Definition: BStreamFileToolkit.h:911
unsigned int NextOpcodeSequence()
Definition: BStreamFileToolkit.h:1021
#define TK_DEFAULT_BUFFER_SIZE
default amount of the internal memory buffer used for file processing
Definition: BStream.h:172
int GetDictionarySize() const
Definition: BStreamFileToolkit.h:1091
virtual void NewFileContext(ID_Key key)
Definition: BStreamFileToolkit.h:598
void SetJpegQuality(int quality=75)
Definition: BStreamFileToolkit.h:957
int GetBufferLimit() const
Definition: BStreamFileToolkit.h:1039
int GetNumColorBits() const
Definition: BStreamFileToolkit.h:951
TK_Progress_Callback GetProgressCallback() const
Definition: BStreamFileToolkit.h:1029
Handles the TKE_Comment opcode.
Definition: BOpcodeHandler.h:1060
The BStreamFileToolkit class provides support for importing/exporting HOOPS Stream File information...
Definition: BStreamFileToolkit.h:367
TK_Status CloseGeometry()
Definition: BStreamFileToolkit.h:1219
void SetReadVersion(int version)
Definition: BStreamFileToolkit.h:962
TK_Status AddBounds(ID_Key key, float const *bounds)
Definition: BStreamFileToolkit.h:693
Handles the TKE_Tag opcode.
Definition: BOpcodeHandler.h:1907
Definition: BStreamFileToolkit.h:34
void SetOpcodeSequence(unsigned int seq=0)
Definition: BStreamFileToolkit.h:1023
void SetTargetVersion(int version)
Definition: BStreamFileToolkit.h:970
void SetReadFlags(int flags)
Definition: BStreamFileToolkit.h:925
void SetFlags(int flags)
Definition: BStreamFileToolkit.h:912
int NextTagIndex()
Definition: BStreamFileToolkit.h:745
wchar_t const * GetCurrentFile() const
Definition: BStreamFileToolkit.h:796
void SetFirstPause(int offset)
Definition: BStreamFileToolkit.h:1114
void SetBufferLimit(int limit)
Definition: BStreamFileToolkit.h:1041
void SetLoggingOptions(unsigned int options=~0)
Definition: BStreamFileToolkit.h:1000
void * m_file
Definition: BStreamFileToolkit.h:489
void SetLogging(bool setting)
Definition: BStreamFileToolkit.h:994
Definition: BOpcodeHandler.h:951
static bool SupportsAsciiMode()
Definition: BStreamFileToolkit.h:502
int const * GetPauseTable() const
Definition: BStreamFileToolkit.h:1111
int GetFirstPause() const
Definition: BStreamFileToolkit.h:1117
int GetWriteFlags(int mask=~0) const
Definition: BStreamFileToolkit.h:922
int GetTargetVersion() const
Definition: BStreamFileToolkit.h:971
wchar_t const * GetExternalReference() const
Definition: BStreamFileToolkit.h:1165
Handles the TKE_Repeat_Object opcode.
Definition: BOpcodeHandler.h:1749
int Unused() const
Definition: BStreamFileToolkit.h:978
int GetPosition() const
Definition: BStreamFileToolkit.h:1122
TK_Status GetOffset(ID_Key key, int variant, int &offset, int &length) const
Definition: BStreamFileToolkit.h:714
int GetDictionaryOptions() const
Definition: BStreamFileToolkit.h:1071
int GetReadFlags(int mask=~0) const
Definition: BStreamFileToolkit.h:931
void SetFileOffset(unsigned int offset)
Sets the file offset, a displacement to be added to positions used in the dictionary (for example...
Definition: BStreamFileToolkit.h:976
TK_Status AddVariant(ID_Key key, int variant, int value1, int value2=-1)
Definition: BStreamFileToolkit.h:684
Handles the TKE_Dictionary opcode.
Definition: BOpcodeHandler.h:1936
Definition: BStream.h:243
BBaseOpcodeHandler * GetOpcodeHandler(int which) const
Definition: BStreamFileToolkit.h:641
float GetQuantizationError() const
Definition: BStreamFileToolkit.h:1205
float const * GetWorldBounding() const
Definition: BStreamFileToolkit.h:1138
void SetNumColorBits(int numbits)
Definition: BStreamFileToolkit.h:952
void ReportQuantizationError(float error)
Definition: BStreamFileToolkit.h:1197
TK_Status GetOffset(ID_Key key, int variant, int &offset) const
Definition: BStreamFileToolkit.h:703
ID_Key GetExternalReferenceContext() const
Definition: BStreamFileToolkit.h:1171
int GetDictionaryOffset() const
Definition: BStreamFileToolkit.h:1081
TK_Status OpenGeometry()
Definition: BStreamFileToolkit.h:1210
void ResetQuantizationError()
Definition: BStreamFileToolkit.h:1193
void SetDictionarySize(int size)
Definition: BStreamFileToolkit.h:1086
int CurrentBufferLength()
Definition: BStreamFileToolkit.h:574
int PeekTagIndex() const
Definition: BStreamFileToolkit.h:750
TK_Status AddIndexKeyPair(int index, ID_Key key)
Definition: BStreamFileToolkit.h:673
unsigned int GetLoggingOptions(unsigned int mask=~0) const
Definition: BStreamFileToolkit.h:997
bool GeometryIsOpen() const
Definition: BStreamFileToolkit.h:1229
The BBaseOpcodeHandler abstract class is used as a base for derived classes which manage logical piec...
Definition: BOpcodeHandler.h:53
void SetNumNormalBits(int numbits)
Definition: BStreamFileToolkit.h:940
TK_Status
Codes which can be either passed to various toolkit functions, or indicate the result of a toolkit fu...
Definition: BStream.h:242
bool HeaderCommentSeen() const
Definition: BStreamFileToolkit.h:1026
void SetWriteFlags(int flags)
Definition: BStreamFileToolkit.h:916
int GetNumVertexBits() const
Definition: BStreamFileToolkit.h:942
int GetNumParameterBits() const
Definition: BStreamFileToolkit.h:945
void SetDictionaryOffset(int offset)
Definition: BStreamFileToolkit.h:1076
dictionary entries include bounding volume info
Definition: BStream.h:291
int GetPauseCount() const
Definition: BStreamFileToolkit.h:1106
void SetNumParameterBits(int numbits)
Definition: BStreamFileToolkit.h:950
unsigned int ObjectsSoFar() const
Definition: BStreamFileToolkit.h:611
#define ID_Key
Definition: BStream.h:218
TK_Status GetBounds(ID_Key key, float *bounds) const
Definition: BStreamFileToolkit.h:738
int GeneratedSoFar() const
Definition: BStreamFileToolkit.h:605
Utility class for managing HSF header information.
Definition: BOpcodeHandler.h:993
void SetProgressCallback(TK_Progress_Callback cb=0)
Definition: BStreamFileToolkit.h:1031
int GetNumIndexBits() const
Definition: BStreamFileToolkit.h:953
void SetNumVertexBits(int numbits)
Definition: BStreamFileToolkit.h:944
Handles the TKE_Start_Compression and TKE_Stop_Compression opcodes.
Definition: BOpcodeHandler.h:1156
void SetDictionaryFormat(int format=3, int options=TK_Dictionary_Bounding_Volumes)
Definition: BStreamFileToolkit.h:1060
void SetNumIndexBits(int numbits)
Definition: BStreamFileToolkit.h:954
virtual void DeactivateContext(ID_Key key)
Definition: BStreamFileToolkit.h:589
Definition: BStreamFileToolkit.h:1327
int GetDictionaryFormat() const
Definition: BStreamFileToolkit.h:1066
void SetProgressValue(void *value)
Definition: BStreamFileToolkit.h:1036
ID_Key CurrentSegment()
Definition: BStreamFileToolkit.h:1191
void ClearPauses()
Definition: BStreamFileToolkit.h:1101
void * GetProgressValue() const
Definition: BStreamFileToolkit.h:1034
int GetJpegQuality() const
Definition: BStreamFileToolkit.h:959
int GetNumNormalBits() const
Definition: BStreamFileToolkit.h:934
virtual bool MatchPreviousExRef() const
Definition: BStreamFileToolkit.h:1178
int GetVersion() const
Definition: BStreamFileToolkit.h:961
virtual void ActivateContext(ID_Key key)
Definition: BStreamFileToolkit.h:582