BStreamFileToolkit.h

Go to the documentation of this file.
00001 //
00002 // Copyright (c) 2000 by Tech Soft 3D, LLC.
00003 // The information contained herein is confidential and proprietary to
00004 // Tech Soft 3D, LLC., and considered a trade secret as defined under
00005 // civil and criminal statutes.  Tech Soft 3D shall pursue its civil
00006 // and criminal remedies in the event of unauthorized use or misappropriation
00007 // of its trade secrets.  Use of this information by anyone other than
00008 // authorized employees of Tech Soft 3D, LLC. is granted only under a
00009 // written non-disclosure agreement, expressly prescribing the scope and
00010 // manner of such use.
00011 //
00012 //
00013 //
00014 //  Copyright (c) 1996-2006 by Autodesk, Inc.
00015 //
00016 //  By using this code, you are agreeing to the terms and conditions of
00017 //  the License Agreement included in the documentation for this code.
00018 //
00019 //  AUTODESK MAKES NO WARRANTIES, EXPRESS OR IMPLIED,
00020 //  AS TO THE CORRECTNESS OF THIS CODE OR ANY DERIVATIVE
00021 //  WORKS WHICH INCORPORATE IT.
00022 //
00023 //  AUTODESK PROVIDES THE CODE ON AN "AS-IS" BASIS
00024 //  AND EXPLICITLY DISCLAIMS ANY LIABILITY, INCLUDING
00025 //  CONSEQUENTIAL AND INCIDENTAL DAMAGES FOR ERRORS,
00026 //  OMISSIONS, AND OTHER PROBLEMS IN THE CODE.
00027 //
00028 //  Use, duplication, or disclosure by the U.S. Government is subject to
00029 //  restrictions set forth in FAR 52.227-19 (Commercial Computer Software
00030 //  Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) (Rights in Technical
00031 //  Data and Computer Software), as applicable.
00032 //
00033 //
00034 // $Header: //DWF/Working_Area/Willie.Zhu/w3dtk/BStreamFileToolkit.h#1 $
00035 //
00036 
00037 #ifndef BBINFILETK_TOOLKIT
00038 #define BBINFILETK_TOOLKIT
00039 
00043 
00044 #include "dwfcore/InputStream.h"
00045 using namespace DWFCore;
00046 
00047 #include "dwf/Toolkit.h"
00048 
00049 
00055 class BBINFILETK_API2 BControlledMemoryObject {
00056     public:
00057         void * operator new (size_t size);  
00058         void   operator delete (void * p);  
00059 };
00060 
00061 class BBaseOpcodeHandler;
00062 
00063 
00064 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00065 
00066 /*
00067    Buffers data so basic handlers can deal with simple Get/Put calls of basic data types (and arrays of those types).
00068    Handles both reading and writing, ZLIB compressed or uncompressed.
00069 */
00070 class BBINFILETK_API2 Internal_Data_Accumulator {
00071     private:
00072         char *          m_pending_buffer;           /*< The whole burrito. */
00073         int             m_pending_buffer_allocated; /*< How big the buffer is (so we know when to reallocate) */
00074         char *          m_pending_position;         /*< Start of actual data to be processed.*/
00075         int             m_pending_size;             /*< Size of actual data. */
00076 
00077         char *          m_buffer_data;              /*< The buffer shown to the user (i.e. passed to GenerateBuffer or ParseBuffer) */
00078         int             m_buffer_size;              /*< The size of the user's buffer */
00079 
00080         int             m_failed_size;              /*< When a read fails because of insufficient data, how much space would have been required for success? */
00081 
00082         int             m_generated;                /*< How much has been written into the user's buffer (after considering compression).  */
00083 
00084         struct z_stream_s * m_z_stream;             /*< The control structure for ZLIB */
00085         bool            m_compressed;               /*< are we in compressed mode? */
00086         bool            m_writing;                  /*< are we compressing or decompressing? */
00087         int             m_original_size;            /*< size of buffer originally passed in */
00088 
00089     public:
00090         Internal_Data_Accumulator () : m_pending_buffer (0), m_pending_buffer_allocated (0),
00091                                        m_pending_position (0), m_pending_size (0),
00092                                        m_failed_size (0), m_generated (0),
00093                                        m_z_stream (0), m_compressed (false), m_writing (false) {}
00094         ~Internal_Data_Accumulator ();
00095 
00096         void        set_data (char * b, int s) alter { m_buffer_data = b; m_original_size = m_buffer_size = s; }
00097         void        save (void) alter;
00098         TK_Status   consume (void) alter;
00099 
00100         TK_Status   read (char alter * b, int s) alter;
00101         TK_Status   write (char const * b, int s) alter;
00102         TK_Status   lookat (char alter & b) alter;
00103 
00104         int         get_original_buffer_size(){return m_original_size; }
00105 
00106         void        restart (void) alter;
00107         void        clean (void) alter;
00108         int         unused (void) const     { return m_buffer_size; }
00109         int         generated (void) const  { return m_generated; }
00110 
00111         TK_Status   start_compression (void) alter;
00112         TK_Status   stop_compression (bool flush) alter;
00113         TK_Status   start_decompression (void) alter;
00114         TK_Status   stop_decompression (bool force) alter;
00115         bool        compressed (void) const { return m_compressed; }
00116 
00117         TK_Status   error (char const * msg = 0) const;
00118 };
00119 
00120 
00121 /*
00122     Provides index <-> key translation, plus storage of additional item-specific data, such as
00123     file offset and size and bounding volume.
00124 */
00125 struct IT_Index_Key_Extra {
00126     int     m_variants[8][2];
00127     int     m_options;
00128     float   m_bounds[6];
00129 };
00130 
00131 class BBINFILETK_API2 Internal_Translator {
00132     friend class TK_Dictionary; // note, dictionary writer tied closely to this implementation
00133     private:
00134         // array -- index to key is trivial
00135         int                     m_size;
00136         int                     m_used;
00137 
00138         struct Index_Key_Pair {
00139             int                 m_index;
00140             ID_Key              m_key;
00141             IT_Index_Key_Extra *m_extra;
00142         } *                     m_pairs;
00143 
00144         enum Options {
00145             Bounds_Valid    = 0x0001,
00146 
00147             Extended        = 0x0080    // reserved
00148         };
00149 
00150         // hash of key to locate potential indices for key to index lookup
00151         struct Hash_Block {
00152             Hash_Block *    m_next;
00153             int             m_used;
00154             int             m_indices[32];
00155         } *                     m_blocks[1024];
00156 
00157 
00158     public:
00159         Internal_Translator () : m_size (0), m_used (0), m_pairs (0) { memset (m_blocks, 0, 1024*sizeof(void *)); }
00160         ~Internal_Translator ();
00161 
00162         TK_Status   add_pair (int index, ID_Key key) alter;
00163         TK_Status   add_variant (ID_Key key, int variant, int value1, int value2 = 0) alter;
00164         TK_Status   add_bounds (ID_Key key, float const * bounds) alter;
00165         TK_Status   index_to_key (int index, ID_Key alter & key) const;
00166         TK_Status   key_to_index (ID_Key key, int alter & index) const;
00167         TK_Status   key_variant_offset (ID_Key key, int variant,
00168                                         int alter & offset, int alter & length, int alter & index) const;
00169         TK_Status   key_bounds (ID_Key key, float alter * bounds) const;
00170         int         used (void) const { return m_used; }
00171 
00172         void        clean (void) alter;
00173 
00174         // older forms:
00175         TK_Status   key_variant_offset (ID_Key key, int variant, int alter & offset) const {
00176                         auto        int                 length, index;
00177                         return key_variant_offset (key, variant, offset, length, index);
00178                     }
00179         TK_Status   key_variant_offset (ID_Key key, int variant, int alter & offset, int alter & length) const {
00180                         auto        int                 index;
00181                         return key_variant_offset (key, variant, offset, length, index);
00182                     }
00183 
00184 };
00185 
00186 
00187 class BBINFILETK_API2 Internal_Key_Record {
00188     private:
00189         // hash of key to list of recorded segments
00190         struct Hash_Block {
00191             Hash_Block *    m_next;
00192             int             m_used;
00193             ID_Key          m_keys[32];
00194         } *                     m_blocks[1024];
00195 
00196 
00197     public:
00198         Internal_Key_Record () { memset (m_blocks, 0, 1024*sizeof(void *)); }
00199         ~Internal_Key_Record ();
00200 
00201         TK_Status   add_key (ID_Key key) alter;
00202         TK_Status   find_key (ID_Key key) const;
00203 
00204         void        clean (void) alter;
00205 };
00206 
00207 
00208 
00209 // control memory on these objects, not sure who might be creating/destroying them
00210 
00211 class Internal_Segment_List : public BControlledMemoryObject {
00212     public:
00213         Internal_Segment_List *     m_next;
00214         ID_Key                      m_key;
00215 
00216     public:
00217         Internal_Segment_List (ID_Key k) : m_next (0), m_key (k) {}
00218 
00219         ID_Key  key (void) const { return m_key; }
00220 };
00221 
00222 class Internal_Revisit_Item : public BControlledMemoryObject {
00223     public:
00224         Internal_Revisit_Item * m_next;
00225         ID_Key                  m_key;
00226         ID_Key                  m_owner;
00227         int                     m_lod;
00228         float                   m_priority;
00229         char                    m_opcode;
00230 };
00231 
00232 
00233 class Internal_ExRef_List : public BControlledMemoryObject {
00234     public:
00235         Internal_ExRef_List *   m_next;
00236         char *                  m_ref;
00237         ID_Key                  m_context;
00238 
00239     public:
00240         Internal_ExRef_List (char const * ref, ID_Key context);
00241         ~Internal_ExRef_List ();
00242 
00243         char const *    Reference (void) const { return m_ref; }
00244         ID_Key          Context (void) const { return m_context; }
00245 };
00246 
00247 
00248 class BBINFILETK_API Recorded_Instance : public BControlledMemoryObject {
00249     public:
00250         Recorded_Instance *     m_next;
00251 
00252         ID_Key                  m_key;
00253         int                     m_variant;
00254         int                     m_values[3];
00255 
00256         float                   m_local_basis[16];      // matrix from our basis to identity
00257         int                     m_basis_indices[4];
00258         float                   m_arbitrary_point[3];
00259         int                     m_arbitrary_index;
00260         bool                    m_basis_valid;
00261 
00262         unsigned char           m_opcode;
00263 
00264 #ifdef _DEBUG
00265         int                     m_times_used;
00266 #endif
00267 
00268         Recorded_Instance (ID_Key key, int variant, unsigned char op, int val1, int val2, int val3)
00269             : m_next (0), m_key (key), m_variant (variant), m_basis_valid (false), m_opcode (op) {
00270             m_values[0] = val1;     m_values[1] = val2;     m_values[2] = val3;
00271 #ifdef _DEBUG
00272             m_times_used = 0;
00273 #endif
00274         }
00275 
00276         bool basis_valid (void) const { return m_basis_valid; }
00277         bool generate_basis (int count, float const * points) alter;
00278 };
00279 
00280 class Internal_Segment_Processor;
00281 
00282 /*
00283     Callback which can be used for reporting progress during writing/reading.
00284     During writing:
00285         so_far is number of "objects" written, expected is the number the toolkit will likely write.
00286         Note: the toolkit won't know about objects in pre/post-walk handlers or extra objects due to
00287             overloading the default classes, so "so_far" may exceed "expected"
00288     During reading:
00289         so_far is the number of bytes processed, expected is the file size.
00290     user_data allows the application to pass any necessary values through.
00291     returns a flag which indicates whether the processing should continue.
00292 */
00293 typedef bool (*TK_Progress_Callback) (unsigned long so_far, unsigned long expected, void * user_data);
00294 
00295 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
00296 
00297 
00298 
00300 
00333 class BBINFILETK_API2 BStreamFileToolkit : public BControlledMemoryObject {
00334     friend class BBaseOpcodeHandler;
00335     friend class TK_Default;
00336     friend class TK_Comment;
00337     friend class TK_Header;
00338     friend class TK_Compression;
00339     friend class TK_Dictionary;
00340     friend class Internal_Segment_Processor;
00341     friend class TK_Shell;
00342 
00343     friend class TK_Tag;
00344     friend class TK_Instance;
00345     protected:
00346 
00347 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00348 
00349         Internal_Data_Accumulator       m_accumulator;          
00350         Internal_Translator             m_translator;           
00352         BBaseOpcodeHandler *            m_objects[256];         
00353         BBaseOpcodeHandler *            m_default_object;       
00354         int                             m_prewalk_count;
00355         int                             m_postwalk_count;
00356         BBaseOpcodeHandler **           m_prewalk;              
00357         BBaseOpcodeHandler **           m_postwalk;             
00358         BBaseOpcodeHandler *            m_current_object;       
00359         Internal_Segment_List *         m_active_segments;      
00360         Internal_Key_Record             m_visited_items;                
00361         ID_Key                          m_context_key;          
00362         ID_Key *                        m_last_keys;            
00363         int                             m_last_keys_used;
00364         int                             m_last_keys_allocated;
00365         Internal_Revisit_Item *         m_revisit;              
00366         Internal_Revisit_Item *         m_revisit_working;      
00367         int                             m_stage;                
00368         int                             m_substage;             
00369         int                             m_pass;                 
00370         int                             m_tag_count;            
00371         int                             m_position;             
00372         unsigned int                    m_offset;               
00373         int                             m_unused;               
00374         int                             m_write_flags;          
00375         int                             m_read_flags;           
00376         int                             m_num_normal_bits;      
00377         int                             m_num_vertex_bits;      
00378         int                             m_num_parameter_bits;   
00379         int                             m_num_color_bits;       
00380         int                             m_num_index_bits;       
00381         int                             m_file_version;         
00382         int                             m_target_version;       
00383         bool                            m_header_comment_seen;  
00384         char *                          m_log_file;             
00385         FILE *                          m_log_fp;               
00386         bool                            m_logging;              
00387         unsigned int                    m_logging_options;      
00388         unsigned int                    m_log_line_length;      
00389         unsigned int                    m_opcode_sequence;      
00390         unsigned int                    m_objects_written;      
00391         TK_Progress_Callback            m_progress_callback;    
00392         void *                          m_progress_value;       
00393         int                             m_buffer_limit;         
00394         int                             m_nesting_level;        
00395         int                             m_dictionary_format;    
00396         int                             m_dictionary_options;   
00397         int                             m_dictionary_size;      
00398         int                             m_dictionary_offset;    
00399         Recorded_Instance *             m_instance_hash[256];   
00400         int                             m_jpeg_quality;         
00401         int *                           m_pause_table;          
00402         int                             m_pause_table_size;     
00403         unsigned short                  m_num_pauses;           
00404         float *                         m_world_bounding;       
00405         Internal_ExRef_List *           m_external_references;  
00406         Internal_ExRef_List *           m_external_ref_tail;    
00408         char **                         m_file_names;           
00409         int *                           m_file_indices;         
00410         int                             m_file_count;           
00411         int                             m_files_allocated;      
00412         char *                          m_current_filename;     
00413         int                             m_index_base;           
00414         float                           m_quantization_error;   
00416         int                             m_save_write_flags;     
00417         char *                          m_filename;             
00418         unsigned short *                m_wfilename;            
00419                 bool                                                    m_geometry_open;                
00421                 bool                                                    m_is_ascii;                             
00422                 int                                                             m_num_tabs;             
00424                 /* Internal use.
00425          * A quick utility to verify that an array is in fact sorted.  
00426          * FOR DEBUGGING ONLY
00427          */
00428         bool issorted_revisit(Internal_Revisit_Item **array, int count);
00429 
00434         void qsort_revisit(Internal_Revisit_Item **, Internal_Revisit_Item **);
00435         TK_Status sort_revisit();
00436 
00437         virtual void read_completed () alter;
00438 
00439 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
00440 
00441 
00442     protected:
00443 
00445         void *                          m_file;
00446         DWFInputStream*                 _pInputStream;
00447 
00448     public:
00449 
00453         BStreamFileToolkit (void);
00454         virtual ~BStreamFileToolkit ();
00455 
00459                 static bool SupportsAsciiMode(void) {
00460 #ifndef BSTREAM_DISABLE_ASCII
00461                         return true;
00462 #else
00463                         return false;
00464 #endif
00465                 }
00466 
00470                 TK_Status       SetAsciiMode(bool whether);
00471 
00475                 bool            GetAsciiMode();
00476 
00477                 void           SetTabs(int);
00478                 int            GetTabs();  
00479 
00485         int   ParseVersion (char const * block) const;
00486 
00522         TK_Status   ParseBuffer (char const * b, int s, TK_Status mode = TK_Normal) alter;
00523  
00524 
00530         TK_Status   PrepareBuffer(char * b, int s) alter;
00531 
00533         int         CurrentBufferLength() {return m_accumulator.get_original_buffer_size() -
00534                                                   m_accumulator.unused();}
00535 
00541         virtual void    ActivateContext (ID_Key key) { (void)key; }
00542 
00548         virtual void    DeactivateContext (ID_Key key) { (void)key; }
00549 
00557         virtual void    NewFileContext (ID_Key key) { (void)key; }
00558 
00564         int             GeneratedSoFar (void) const { return m_accumulator.generated(); }
00565 
00570         unsigned int    ObjectsSoFar (void) const { return m_objects_written; }
00571 
00578         void        SetOpcodeHandler (int which, BBaseOpcodeHandler * handler) alter;
00579 
00587         void        SetPrewalkHandler (BBaseOpcodeHandler * handler) alter;
00588 
00589 
00597         void        SetPostwalkHandler (BBaseOpcodeHandler * handler) alter;
00598 
00600         BBaseOpcodeHandler *    GetOpcodeHandler (int which) const { return m_objects[which]; }
00601 
00607         virtual void    Restart (void) alter;
00608 
00609         // access to index <-> key tranlation
00616         TK_Status   IndexToKey (int index, ID_Key alter & key) const;
00617 
00624         TK_Status   KeyToIndex (ID_Key key, int alter & index) const;
00625 
00632         TK_Status   AddIndexKeyPair (int index, ID_Key key) alter
00633                                         { return m_translator.add_pair (index, key); }
00634 
00643         TK_Status   AddVariant (ID_Key key, int variant, int value1, int value2 = -1) alter
00644                                         { return m_translator.add_variant (key, variant, value1, value2);   }
00645 
00652         TK_Status   AddBounds (ID_Key key, float const * bounds) alter
00653                                         { return m_translator.add_bounds (key, bounds);                     }
00654 
00662         TK_Status   GetOffset (ID_Key key, int variant, int alter & offset) const
00663                                         { return m_translator.key_variant_offset (key, variant, offset);            }
00664 
00673         TK_Status   GetOffset (ID_Key key, int variant, int alter & offset, int alter & length) const
00674                                         { return m_translator.key_variant_offset (key, variant, offset, length);    }
00675 
00685         TK_Status   GetOffset (ID_Key key, int variant,
00686                                int alter & offset, int alter & length, char const * alter & filename) const;
00687 
00694         TK_Status   GetBounds (ID_Key key, float alter * bounds) const
00695                                         { return m_translator.key_bounds (key, bounds);                             }
00696 
00701         int         NextTagIndex (void) alter   { return m_tag_count++; }
00706         int         PeekTagIndex (void) const   { return m_tag_count; }
00707 
00713         void        SetFilename (char const * name) alter;
00719         void        SetFilename (unsigned short const * name) alter;
00720 
00725                 TK_Status       Read_Stream_File (void);
00726 
00732         void            SetNewFile (char const * name) alter;
00737         char const *    GetCurrentFile (void) const    { return m_current_filename; }
00744         TK_Status       SelectFile (char const * name) alter;
00745 
00753         virtual TK_Status   OpenFile (char const * name, bool write = false) alter;
00761         virtual TK_Status   OpenFile (unsigned short const * name, bool write = false) alter;
00762 
00763         //
00764         // Lets the toolkit read directly from a stream rather than assuming
00765         // a disk file will be the source of the data feed.
00766         //
00767         virtual TK_Status   OpenStream( DWFInputStream& rReadStream ) alter;
00768         virtual TK_Status   CloseStream() alter;
00769 
00774         virtual TK_Status   CloseFile (void) alter;
00775 
00785         virtual TK_Status   ReadBuffer (char alter * buffer, int size, int alter & amount_read) alter;
00786 
00795         virtual TK_Status   WriteBuffer (char alter * buffer, int size) alter;
00796 
00806         virtual TK_Status   PositionFile (int offset) alter;
00807 
00816         virtual TK_Status   GetFileSize (unsigned long & size) alter;
00817 
00818 
00830         virtual TK_Status   LocateDictionary (void) alter;
00831 
00842         virtual TK_Status   LocateEntity (ID_Key key, int variant) alter;
00843         
00844         int         GetFlags (void) const       { return GetWriteFlags(); }     
00845         void        SetFlags (int flags) alter  { SetWriteFlags(flags); }       
00849         void        SetWriteFlags (int flags) alter     { m_write_flags = flags; } 
00855         int         GetWriteFlags (int mask = ~0) const { return m_write_flags & mask; }
00856                 
00858         void        SetReadFlags (int flags) alter      { m_read_flags = flags; }  
00864         int         GetReadFlags (int mask = ~0) const  { return m_read_flags & mask; }
00865 
00866 
00867         int         GetNumNormalBits (void) const { return m_num_normal_bits; } 
00873         void        SetNumNormalBits (int numbits) alter  { m_num_normal_bits = (numbits<=72) ? numbits : 72; } 
00874 
00875         int         GetNumVertexBits (void) const { return m_num_vertex_bits; } 
00877         void        SetNumVertexBits (int numbits) alter  { m_num_vertex_bits = (numbits<=72) ? numbits : 72; }      
00878         int         GetNumParameterBits (void) const { return m_num_parameter_bits; } 
00883         void        SetNumParameterBits (int numbits) alter  { m_num_parameter_bits = (numbits<=72) ? numbits : 72; }   
00884         int         GetNumColorBits (void) const { return m_num_color_bits; } 
00885         void        SetNumColorBits (int numbits) alter  { m_num_color_bits = (numbits<=72) ? numbits : 72; }        
00886         int         GetNumIndexBits (void) const { return m_num_index_bits; } 
00887         void        SetNumIndexBits (int numbits) alter  { m_num_index_bits = (numbits<=24) ? numbits : 24; }        
00890         void        SetJpegQuality (int quality = 75) alter     { m_jpeg_quality = quality; }
00892         int         GetJpegQuality (void) const                 { return m_jpeg_quality;    }
00893 
00894         int         GetVersion (void) const     { return m_file_version; }  
00896         void        SetTargetVersion (int version) alter     { m_target_version = version; }  
00897         int         GetTargetVersion (void) const     { return m_target_version; }  
00899 
00900         unsigned int    GetFileOffset (void) const                  { return m_offset;      }
00902         void            SetFileOffset (unsigned int offset) alter   { m_offset = offset;    }
00904         int             Unused (void) const                     { return m_unused; }
00908         virtual TK_Status   Error(char const * msg = 0) const;
00909 
00911         char const *GetLogFile (void) const                     { return m_log_file;    }
00913         void        SetLogFile (char const * filename = 0) alter;
00914 
00916         bool        GetLogging (void) const                     { return m_logging;     }
00920         void        SetLogging (bool setting) alter             { m_logging = setting;  }
00921 
00923         unsigned int    GetLoggingOptions (unsigned int mask = ~0) const
00924                                                                 { return m_logging_options & mask; }
00926         void        SetLoggingOptions (unsigned int options = ~0) alter
00927                                                                 { m_logging_options = options;  }
00928 
00933         TK_Status   OpenLogFile (char const * filename, char const * mode) alter;
00935         void        LogEntry (char const * string) alter;
00937         void        LogEntry (unsigned short const * string) alter;
00939         void        CloseLogFile (void) alter;
00940 
00942         unsigned int    NextOpcodeSequence (void) alter                 { return ++m_opcode_sequence;   }
00944         void            SetOpcodeSequence (unsigned int seq=0) alter    { m_opcode_sequence = seq;      }
00945 
00947         bool        HeaderCommentSeen(void) const                       { return m_header_comment_seen; }
00948 
00950         TK_Progress_Callback    GetProgressCallback (void) const        { return m_progress_callback;   }
00952         void    SetProgressCallback (TK_Progress_Callback cb = 0) alter { m_progress_callback = cb;     }
00953 
00955         void *      GetProgressValue (void) const                       { return m_progress_value;      }
00957         void        SetProgressValue (void * value) alter               { m_progress_value = value;     }
00958 
00960         int         GetBufferLimit (void) const                         { return m_buffer_limit;      }
00962         void        SetBufferLimit (int limit) alter    {
00963                             m_buffer_limit = (0 < limit && limit < TK_DEFAULT_BUFFER_SIZE) ?
00964                                              limit : TK_DEFAULT_BUFFER_SIZE;
00965                         }
00966 
00968         void        SetLastKey (ID_Key key) alter;
00970         TK_Status   AppendLastKey (ID_Key key) alter;
00972         void        ClearLastKey () alter;
00974         TK_Status   GetLastKey (ID_Key &key) const;
00975 
00981         void        SetDictionaryFormat (int format = 3, int options = TK_Dictionary_Bounding_Volumes) alter
00982                                         { m_dictionary_format = format; m_dictionary_options = options; }
00987         int         GetDictionaryFormat (void) const    { return m_dictionary_format;     }
00992         int         GetDictionaryOptions (void) const   { return m_dictionary_options;    }
00997         void        SetDictionaryOffset (int offset) alter  { m_dictionary_offset = offset; }
01002         int         GetDictionaryOffset (void) const        { return m_dictionary_offset;   }
01007         void        SetDictionarySize (int size) alter      { m_dictionary_size = size;     }
01012         int         GetDictionarySize (void) const          { return m_dictionary_size;     }
01013 
01018         void        RecordPause (int offset) alter;
01022         void        ClearPauses (void) alter            { m_num_pauses = 0;     }
01027         int         GetPauseCount (void) const          { return m_num_pauses;  }
01032         int const * GetPauseTable (void) const          { return m_pause_table; }
01033 
01035         void        SetFirstPause (int offset) alter    { if (GetPauseCount() == 0) RecordPause (offset);
01036                                                           else m_pause_table[0] = offset;                   }
01038         int         GetFirstPause (void) const          { return (m_num_pauses > 0) ? m_pause_table[0] : 0; }
01039 
01043         int         GetPosition (void) const            { return m_position;        }
01044 
01049         void        SetWorldBounding( float const *bbox );
01050 
01056         void        SetWorldBoundingBySphere( float const *pt, float radius );
01057 
01059         float const * GetWorldBounding() const          { return m_world_bounding; }
01060 
01061 
01066         void        AddExternalReference (char const * ref, ID_Key context) alter;
01070         bool        NextExternalReference (void) alter;
01074         char const *GetExternalReference (void) const {
01075                             return  (m_external_references != 0) ? m_external_references->m_ref : 0;
01076                         }
01080         ID_Key      GetExternalReferenceContext (void) const {
01081                             return  (m_external_references != 0) ? m_external_references->m_context : 0;
01082                         }
01083 
01087         void        AddSegment (ID_Key key) alter;
01091         ID_Key      RemoveSegment (void) alter;
01095         ID_Key      CurrentSegment (void) alter { return (m_active_segments != 0) ? m_active_segments->key() : -1; }
01097         void ResetQuantizationError() { m_quantization_error = 0; }
01101         void ReportQuantizationError( float error ) { if (error > m_quantization_error) m_quantization_error = error; };
01105         void ReportQuantizationError( int bits_per_sample, float const *bounding, int num_dimensions = 3 );
01109         float GetQuantizationError() const { return m_quantization_error; }
01110 
01114                 TK_Status       OpenGeometry (void) alter       {
01115                                                 if (m_geometry_open)
01116                                                         return Error ("recursive geometry open");
01117                                                 m_geometry_open = true;
01118                                                 return TK_Normal;
01119                                         }
01123                 TK_Status       CloseGeometry (void) alter      {
01124                                                 if (!m_geometry_open)
01125                                                         return Error ("no geometry open");
01126                                                 m_geometry_open = false;
01127                                                 return TK_Normal;
01128                                         }
01129 
01133                 bool            GeometryIsOpen (void) const             { return m_geometry_open;       }
01134 
01135 
01136     protected:
01137 
01138 #ifndef DOXYGEN_SHOULD_SKIP_THIS
01139 
01140         // normal data access for objects
01141         TK_Status   read (char alter * b, int n) alter      { return m_accumulator.read (b, n); }
01142         TK_Status   write (char const * b, int n) alter     { return m_accumulator.write (b, n); }
01143         TK_Status   lookat (char alter & b) alter           { return m_accumulator.lookat (b); }
01144 
01145         // used by segment handlers to make sure we know which segment should be "open"
01146         void        add_segment (ID_Key key) alter { AddSegment (key); }
01147         ID_Key      remove_segment (void) alter { return RemoveSegment(); }
01148 
01149         // used by renumber key, maybe by lookup functions (to be implemented...)
01151         void        set_last_key (ID_Key key) alter { SetLastKey( key ); } 
01152         ID_Key      context_key (void) const { return m_context_key; }
01153         void        set_context_key (ID_Key key) alter;
01155         ID_Key      last_key (void) const { 
01156             if( m_last_keys_used == 1 ) 
01157                 return m_last_keys[0];
01158             else 
01159                 return -1; 
01160         } 
01161 
01162         // keep track of visited segments (for things like include)
01163         void        remember_item (ID_Key key) alter;
01164         bool        find_item (ID_Key key) const;
01165 
01167         BBaseOpcodeHandler alter *  opcode_handler (int index) const { return m_objects[index]; }
01168 
01169         void        adjust_written (int count) alter    { m_objects_written += count; }
01170 
01171         int         pass (void) const { return m_pass; }
01172 
01174         TK_Status   revisit (unsigned char opcode, float priority, int lod=0) alter;
01175 
01177         void        record_instance (ID_Key key, int variant, BBaseOpcodeHandler const * object,
01178                                      int val1, int val2 = 0, int val3 = 0) alter;
01179 
01181         bool        find_instance (BBaseOpcodeHandler * object, int val1, int val2 = 0, int val3 = 0) const;
01182 
01184         int         position (void) const           { return m_position; }
01185         void        set_position (int pos) alter    { m_position = pos; }
01186         void        mark_position (void) alter      { set_position (GeneratedSoFar()); }
01187 
01192         virtual TK_Status   tag (int variant) alter;
01193 
01194         void        increase_nesting (int amount = 1) alter { m_nesting_level += amount; }
01195         void        decrease_nesting (int amount = 1) alter { m_nesting_level -= amount; }
01196 
01197         // utility
01198         TK_Status   start_compression (void) alter      { return m_accumulator.start_compression(); }
01199         TK_Status   stop_compression (void) alter       { return m_accumulator.stop_compression(true); }
01200         TK_Status   start_decompression (void) alter                { return m_accumulator.start_decompression(); }
01201         TK_Status   stop_decompression (bool force = false) alter   { return m_accumulator.stop_decompression(force); }
01202         virtual void    empty_lists (void) alter;
01203 
01204 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
01205 
01206 };
01207 
01208 //TODO Documentation 
01209 
01210 #ifndef BSTREAM_DISABLE_ASCII
01211 class PutTab
01212 {
01213 public:
01214         PutTab(BStreamFileToolkit* tk) : m_tk(tk)
01215         {
01216                 int n_tabs = m_tk->GetTabs();
01217                 m_tk->SetTabs(++n_tabs);
01218         }
01219 
01220         ~PutTab()
01221         {
01222                 int n_tabs = m_tk->GetTabs();
01223                 m_tk->SetTabs(--n_tabs);
01224         }
01225 
01226 private:
01227         BStreamFileToolkit* m_tk;
01228 };
01229 class Outdent
01230 {
01231 public:
01232         Outdent(BStreamFileToolkit* tk, int n_tabs = 1) : m_tk(tk)
01233         {
01234                 int cur_tabs = m_tk->GetTabs();
01235                 if( cur_tabs >= n_tabs )
01236                 {
01237                         m_tabs = n_tabs;
01238                         m_tk->SetTabs(cur_tabs-n_tabs);
01239                 }
01240                 else
01241                 {
01242                         m_tabs = cur_tabs;
01243                         m_tk->SetTabs(0);
01244                 }
01245         }
01246 
01247         ~Outdent()
01248         {
01249                 int cur_tabs = m_tk->GetTabs();
01250                 m_tk->SetTabs(cur_tabs+m_tabs);
01251         }
01252 
01253 private:
01254         BStreamFileToolkit* m_tk;
01255         int                                     m_tabs;
01256 };
01257 
01258 #endif //BSTREAM_DISABLE_ASCII
01259 
01260 #endif //BBINFILETK_TOOLKIT

Generated on Tue Jan 6 22:41:37 2009 for Autodesk DWF 3D Toolkit by  doxygen 1.4.5