Alphabetical Class Index   Class Hierarchy   Compound Members   File Members   File List  

HStreamFileToolkit.h

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 // $Id: ca2174b9b8556a842db9943940a65ffa4c833a18 $
00013 //
00014 
00015 #ifndef HBINFILETK_TOOLKIT
00016 #define HBINFILETK_TOOLKIT
00017 
00018 
00019 #ifndef HSTREAM_READONLY
00020 
00021 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00022 
00023 class Internal_Key_Array {
00024     friend class HStreamFileToolkit;
00025     friend class Internal_Pending_Tag;
00026     friend class Internal_Segment_Processor;
00027     private:
00028         Internal_Key_Array() { m_data = 0; }
00029         ~Internal_Key_Array() { delete [] m_data; }
00030 
00031         int m_count;
00032         HC_KEY *m_data;
00033 };
00034 
00035 class Internal_Pending_Tag {
00036     friend class HStreamFileToolkit;
00037     friend class Internal_Segment_Processor;
00038     friend class HTK_Referenced_Segment;
00039     friend class HTK_Reference;
00040     friend class HTK_Texture;
00041     friend class HTK_Named_Style_Def;
00042     private:
00043         Internal_Pending_Tag() { m_next = 0; m_array = 0; }
00044         ~Internal_Pending_Tag() { delete m_array; }
00045 
00046         Internal_Pending_Tag *  m_next;
00047         HC_KEY                  m_key;    //m_key set to tk.m_last_keys[0], just for the purposes of matching tag requests
00048         int                     m_variant;
00049         Internal_Key_Array *    m_array;  //set to null unless we are associating multiple keys with a single tag call.
00050 };
00051 
00052 
00053 class Internal_Texture_List {
00054     friend class HStreamFileToolkit;
00055     friend class HTK_Image;
00056     private:
00057         Internal_Texture_List *     m_next;
00058         char *                      m_name;
00059         char *                      m_image;
00060         HC_KEY                      m_image_key;
00061         bool                        m_do_write_image;
00062 
00063     public:
00064         Internal_Texture_List (char const * name, char const * image, HC_KEY key = -1);
00065         ~Internal_Texture_List();
00066 };
00067 
00068 
00070 class HBINFILETK_API HStreamFileToolkit; //forward declaration
00071 
00072 // special output-only pseudo-object
00073 class HBINFILETK_API2 Internal_Segment_Processor : public BBaseOpcodeHandler {
00074     protected:
00075         char *                  m_name;             
00076         HC_KEY                  m_key;              
00077         bool                    m_top_level;        
00078         HC_KEY                  m_root;             
00079         BBaseOpcodeHandler *    m_current_object;   
00080         BBaseOpcodeHandler *    m_must_delete;      
00081         HC_KEY                  m_item_key;         
00082         int                     m_saved_count;      
00083         HC_KEY *                m_saved_keys;       
00084         HC_KEY                  m_renumbered;       
00085         unsigned char           m_renumbered_scope; 
00086         long                    m_priority;         
00087         int                     m_start_offset;     
00088         bool                    m_searching;        
00089         bool                    m_use_polypolylines;        
00090         bool                    m_polylines_already_handled;  
00091         bool                    m_geometry_attributes;  
00092         bool                    m_geometry_open;    
00093         BBaseOpcodeHandler *    m_deferred;         
00094         int                     m_search_pass;      
00096         void    save_keys (HStreamFileToolkit & tk) alter;
00097         void    restore_keys (HStreamFileToolkit & tk) alter;
00098 
00099     public:
00100         Internal_Segment_Processor (ID_Key key = -1, char const * name = 0);
00101         ~Internal_Segment_Processor ();
00102 
00103         TK_Status   Read (BStreamFileToolkit & tk) alter;
00104         TK_Status   Write (BStreamFileToolkit & tk) alter;
00105         TK_Status   Interpret (BStreamFileToolkit & tk, ID_Key key, int variant = 0) alter;
00106         TK_Status   Interpret (BStreamFileToolkit & tk, ID_Key key, char const * special) alter;
00107         void        Reset () alter;
00108         TK_Status   Clone (BStreamFileToolkit & tk, BBaseOpcodeHandler **) const;
00109 
00110         void        SetRoot (HC_KEY root) alter     { m_root = root;    }
00111         HC_KEY      GetRoot () const                { return m_root;    }
00112 };
00113 
00114 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
00115 
00116 #endif //HSTREAM_READONLY
00117 
00118 
00119 
00120 
00121 
00123 
00141 class HBINFILETK_API2 HStreamFileToolkit : public BStreamFileToolkit {
00142     friend class Internal_Segment_Processor;
00143     friend class HTK_Open_Segment;
00144     friend class HTK_Referenced_Segment;
00145     friend class HTK_Reference;
00146     friend class HTK_Texture;
00147     friend class HTK_Image;
00148     friend class HTK_Named_Style_Def;
00149     private:
00150         int                             m_hoops_version;        /* Version of Hoops we are using */
00151         Internal_Segment_List *         m_unnamed_segments;     /* Segments which need to be renamed to unnamed when able */
00152 
00153         HC_KEY *                        m_excluded_segments;    /* keys of segments (if any) to skip during write */
00154         int                             m_excluded_count;       /* size of exclusion array */
00155 #ifndef HSTREAM_READONLY
00156         Internal_Segment_Processor *    m_segment_processor;    /* Handler for top segment & revisited segments */
00157         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 */
00158         Internal_Texture_List *         m_texture_list;         /* Textures being processed */
00159         bool                            m_non_segment_revisits; /* Does the revisit list contain something other than segments? */
00160         int                             m_revisit_offset;       /* File offset of start of current revisit object (including compression if appropriate) */
00161         BBaseOpcodeHandler *            m_thumbnail;            /* handler for a thumbnail (if any) to write */
00162         int                             m_local_attributes;     /* flag presence of geometry-level attributes (used in GenerateOne) */
00163         BBaseOpcodeHandler *            m_must_delete;          /* pointer to any temporary handler to discard when done */
00164         char *                          m_prepend_root;         /* a string to prepend on rooted segments */
00165         int                             m_revisit_state;        /* state of progress in revisit loop */
00166 
00167         bool issorted_revisit(Internal_Revisit_Item **array, int count);
00168         void qsort_revisit(Internal_Revisit_Item ** first, Internal_Revisit_Item ** last) { qsort_revisit (first, last, 0); }
00169         void qsort_revisit(Internal_Revisit_Item **, Internal_Revisit_Item **, int);
00170         TK_Status sort_revisit();
00171 
00172         TK_Status find_textures();
00173 
00174         
00175         enum Revisit {
00176             Nothing,
00177             Working,
00178             Force
00179         };
00180 #endif
00181 
00182     public:
00186         HStreamFileToolkit ();
00187 
00188         ~HStreamFileToolkit ();
00189         // clean out current state
00190 
00196         void        Restart () alter;
00197 
00198         // normal processing functions
00199 
00218         TK_Status   GenerateBuffer (char * b, int s, int alter & f, char const * start_segment = 0) alter;
00219 
00220 
00234         TK_Status   GenerateOneItemBuffer (char * b, int s, int alter & f, HC_KEY item) alter;
00235 
00236 
00246         unsigned POINTER_SIZED_INT   CountObjects (char const * start_segment = 0) alter;
00247 
00248 
00249         void    ActivateContext (ID_Key key);
00250         void    DeactivateContext (ID_Key key);
00251         void    NewFileContext (ID_Key key);
00252 
00253 
00260         int         GetHoopsVersion()       { if (m_hoops_version == 0) validate_hoops_version();   return m_hoops_version; }
00261 
00268         TK_Status StringToHandler (char const *type, BBaseOpcodeHandler **handler);
00269 
00276         TK_Status StringToOpcode (char const *type, unsigned char *opcode_out);
00277 
00278 
00286         void        SetThumbnail (BBaseOpcodeHandler * handler) alter;
00287 
00298         void        SetThumbnail (int format, int width, int height, unsigned char const * data) alter;
00299 
00304         TK_Status   Write_Stream_File ();
00305 
00311         void        AddExcludedSegments (int count, HC_KEY const * keys) alter;
00316         void        AddExcludedSegment (HC_KEY key) alter   { AddExcludedSegments (1, &key);    }
00322         bool        SegmentIsExcluded (HC_KEY key) const;
00326         void        ClearExcludedSegments () alter;
00331         int         GetExcludedSegmentCount () const    { return m_excluded_count;          }
00336         HC_KEY const *  GetExcludedSegments () const    { return m_excluded_segments;       }
00337 
00342         void SetPrependRootSegment(const char * segment);
00347         const char * GetPrependRootSegment() { return m_prepend_root; }
00348 
00349 
00353         bool    MatchPreviousExRef () const;
00354 
00355     protected:
00357         void            validate_hoops_version();
00359         void            add_unnamed_segment (HC_KEY key) alter;
00361         void            read_completed () alter;
00363         void            empty_lists () alter;
00365         TK_Status       tag (int variant) alter;
00367         unsigned HLONG   count_segment_objects (HC_KEY key, char const * start_segment = 0) alter;
00368 };
00369 
00370 
00371 #endif //HBINFILETK_TOOLKIT