Alphabetical Class Index   Class Hierarchy   Compound Members   File Members   File List  

HStreamFileToolkit.h
00001 // Copyright (c) 1998-2014 by Tech Soft 3D, Inc.
00002 //
00003 // The information contained herein is confidential and proprietary to Tech Soft 3D, Inc.,
00004 // and considered a trade secret as defined under civil and criminal statutes.
00005 // Tech Soft 3D, Inc. shall pursue its civil and criminal remedies in the event of
00006 // unauthorized use or misappropriation of its trade secrets.  Use of this information
00007 // by anyone other than authorized employees of Tech Soft 3D, Inc. is granted only under
00008 // a written non-disclosure agreement, expressly prescribing the scope and manner of such use.
00009 
00010 #ifndef HBINFILETK_TOOLKIT
00011 #define HBINFILETK_TOOLKIT
00012 
00013 
00014 #ifndef HSTREAM_READONLY
00015 
00016 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00017 
00018 class Internal_Key_Array {
00019     friend class HStreamFileToolkit;
00020     friend class Internal_Pending_Tag;
00021     friend class Internal_Segment_Processor;
00022     private:
00023         Internal_Key_Array() { m_data = 0; }
00024         ~Internal_Key_Array() { delete [] m_data; }
00025 
00026         int m_count;
00027         HC_KEY *m_data;
00028 };
00029 
00030 class Internal_Pending_Tag {
00031     friend class HStreamFileToolkit;
00032     friend class Internal_Segment_Processor;
00033     friend class HTK_Referenced_Segment;
00034     friend class HTK_Reference;
00035     friend class HTK_Texture;
00036     friend class HTK_Named_Style_Def;
00037     private:
00038         Internal_Pending_Tag() { m_next = 0; m_array = 0; }
00039         ~Internal_Pending_Tag() { delete m_array; }
00040 
00041         Internal_Pending_Tag *  m_next;
00042         HC_KEY                  m_key;    //m_key set to tk.m_last_keys[0], just for the purposes of matching tag requests
00043         int                     m_variant;
00044         Internal_Key_Array *    m_array;  //set to null unless we are associating multiple keys with a single tag call.
00045 };
00046 
00047 
00048 class Internal_Texture_List {
00049     friend class HStreamFileToolkit;
00050     friend class HTK_Image;
00051     private:
00052         Internal_Texture_List *     m_next;
00053         char *                      m_name;
00054         char *                      m_image;
00055         HC_KEY                      m_image_key;
00056         bool                        m_do_write_image;
00057 
00058     public:
00059         Internal_Texture_List (char const * name, char const * image, HC_KEY key = -1);
00060         ~Internal_Texture_List();
00061 };
00062 
00063 
00065 class HBINFILETK_API HStreamFileToolkit; //forward declaration
00066 
00067 // special output-only pseudo-object
00068 class HBINFILETK_API2 Internal_Segment_Processor : public BBaseOpcodeHandler {
00069     protected:
00070         char *                  m_name;             
00071         HC_KEY                  m_key;              
00072         bool                    m_top_level;        
00073         HC_KEY                  m_root;             
00074         BBaseOpcodeHandler *    m_current_object;   
00075         BBaseOpcodeHandler *    m_must_delete;      
00076         HC_KEY                  m_item_key;         
00077         int                     m_saved_count;      
00078         HC_KEY *                m_saved_keys;       
00079         HC_KEY                  m_renumbered;       
00080         unsigned char           m_renumbered_scope; 
00081         int                     m_priority;         
00082         bool                    m_has_priority;     
00083         int                     m_start_offset;     
00084         bool                    m_searching;        
00085         unsigned char           m_use_polypolylines;        
00086         unsigned char           m_polylines_already_handled;  
00087         bool                    m_geometry_attributes;  
00088         bool                    m_geometry_open;    
00089         BBaseOpcodeHandler *    m_deferred;         
00090         int                     m_search_pass;      
00091         bool                    m_look_for_bounds;  
00093         void    save_keys (HStreamFileToolkit & tk);
00094         void    restore_keys (HStreamFileToolkit & tk);
00095 
00096     public:
00097         Internal_Segment_Processor (ID_Key key = -1, char const * name = 0);
00098         ~Internal_Segment_Processor ();
00099 
00100         TK_Status   Read (BStreamFileToolkit & tk);
00101         TK_Status   Write (BStreamFileToolkit & tk);
00102         TK_Status   Interpret (BStreamFileToolkit & tk, ID_Key key, int variant = 0);
00103         TK_Status   Interpret (BStreamFileToolkit & tk, ID_Key key, char const * special);
00104         void        Reset ();
00105         TK_Status   Clone (BStreamFileToolkit & tk, BBaseOpcodeHandler **) const;
00106 
00107         void        SetRoot (HC_KEY root)           { m_root = root;    }
00108         HC_KEY      GetRoot () const                { return m_root;    }
00109 };
00110 
00111 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
00112 
00113 #endif //HSTREAM_READONLY
00114 
00115 
00116 
00117 
00118 
00120 
00138 class HBINFILETK_API2 HStreamFileToolkit : public BStreamFileToolkit {
00139     friend class Internal_Segment_Processor;
00140     friend class HTK_Open_Segment;
00141     friend class HTK_Referenced_Segment;
00142     friend class HTK_Reference;
00143     friend class HTK_Texture;
00144     friend class HTK_Image;
00145     friend class HTK_Named_Style_Def;
00146     private:
00147         int                             m_hoops_version;        /* Version of Hoops we are using */
00148         Internal_Segment_List *         m_unnamed_segments;     /* Segments which need to be renamed to unnamed when able */
00149 
00150         HC_KEY *                        m_excluded_segments;    /* keys of segments (if any) to skip during write */
00151         int                             m_excluded_count;       /* size of exclusion array */
00152 
00153 #ifndef HSTREAM_READONLY
00154         Internal_Segment_Processor *    m_segment_processor;    /* Handler for top segment & revisited segments */
00155         Internal_Pending_Tag *          m_pending_tags;         /* List of items to have tags attached. Tags should come absolutely last (even after user data), so tagging postponed to the end.  It is a list to allow for recursion if we ever need it */
00156         Internal_Texture_List *         m_texture_list;         /* Textures being processed */
00157         bool                            m_non_segment_revisits; /* Does the revisit list contain something other than segments? */
00158         int                             m_revisit_offset;       /* File offset of start of current revisit object (including compression if appropriate) */
00159         BBaseOpcodeHandler *            m_thumbnail;            /* handler for a thumbnail (if any) to write */
00160         int                             m_local_attributes;     /* flag presence of geometry-level attributes (used in GenerateOne) */
00161         BBaseOpcodeHandler *            m_must_delete;          /* pointer to any temporary handler to discard when done */
00162         char *                          m_prepend_root;         /* a string to prepend on rooted segments */
00163         int                             m_revisit_state;        /* state of progress in revisit loop */
00164 
00165         bool issorted_revisit(Internal_Revisit_Item **array, int count);
00166         void qsort_revisit(Internal_Revisit_Item ** first, Internal_Revisit_Item ** last) { qsort_revisit (first, last, 0); }
00167         void qsort_revisit(Internal_Revisit_Item **, Internal_Revisit_Item **, int);
00168         TK_Status sort_revisit();
00169 
00170         TK_Status find_textures();
00171 
00172         
00173         enum Revisit {
00174             Nothing,
00175             Working,
00176             Force
00177         };
00178 #endif
00179 
00180     public:
00184         HStreamFileToolkit ();
00185 
00186         ~HStreamFileToolkit ();
00187         // clean out current state
00188 
00194         void        Restart ();
00195 
00196         // normal processing functions
00197 
00216         TK_Status   GenerateBuffer (char * b, int s, int & f, char const * start_segment = 0);
00217 
00218 
00232         TK_Status   GenerateOneItemBuffer (char * b, int s, int & f, HC_KEY item);
00233 
00234 
00244         unsigned POINTER_SIZED_INT   CountObjects (char const * start_segment = 0);
00245 
00246 
00247         void    ActivateContext (ID_Key key);
00248         void    DeactivateContext (ID_Key key);
00249         void    NewFileContext (ID_Key key);
00250 
00251 
00258         int         GetHoopsVersion()       { if (m_hoops_version == 0) validate_hoops_version();   return m_hoops_version; }
00259 
00266         TK_Status StringToHandler (char const *type, BBaseOpcodeHandler **handler);
00267 
00274         TK_Status StringToOpcode (char const *type, unsigned char *opcode_out);
00275 
00276 
00284         void        SetThumbnail (BBaseOpcodeHandler * handler);
00285 
00296         void        SetThumbnail (int format, int width, int height, unsigned char const * data);
00297 
00302         TK_Status   Write_Stream_File ();
00303 
00309         void        AddExcludedSegments (int count, HC_KEY const * keys);
00314         void        AddExcludedSegment (HC_KEY key) { AddExcludedSegments (1, &key); }
00320         bool        SegmentIsExcluded (HC_KEY key) const;
00324         void        ClearExcludedSegments ();
00329         int         GetExcludedSegmentCount () const    { return m_excluded_count;          }
00334         HC_KEY const *  GetExcludedSegments () const    { return m_excluded_segments;       }
00335 
00340         void SetPrependRootSegment(const char * segment);
00345         const char * GetPrependRootSegment() { return m_prepend_root; }
00346 
00347 
00351         bool    MatchPreviousExRef () const;
00352 
00353         char    const                       **m_search_strings;
00354 
00355     protected:
00357         void            validate_hoops_version();
00359         void            add_unnamed_segment (HC_KEY key);
00361         void            read_completed ();
00363         void            empty_lists ();
00365         TK_Status       tag (int variant);
00367         unsigned HLONG   count_segment_objects (HC_KEY key, char const * start_segment = 0);
00368 
00369 };
00370 
00371 
00372 #endif //HBINFILETK_TOOLKIT