XSIParser.h

Go to the documentation of this file.
00001 //***************************************************************************************
00002 // File supervisor: Crosswalk team
00014 //***************************************************************************************
00015 
00016 //***************************************************************************************
00017 // Defines
00018 //***************************************************************************************
00019 #ifndef __CXSIParser_H__
00020 #define __CXSIParser_H__
00021 
00022 
00023 //***************************************************************************************
00024 // Includes
00025 //***************************************************************************************
00026 #include <SIBCUtil.h>
00027 #include <SIBCString.h>
00028 
00029 #include "dotXSITemplate.h"
00030 #include "CXSIFilter.h"
00031 
00032 namespace xercesc_2_7
00033 {
00034     class SAX2XMLReader;
00035 }
00036 class CCOLLADATemplate;
00037 
00042 #define FORMAT_TEXT     0   
00043 #define FORMAT_BINARY   1   
00044 #define FORMAT_COLLADA  2   
00046 #define OPEN_READ       0   
00047 #define OPEN_WRITE      1   
00053 //***************************************************************************************
00054 // Typedefs
00055 //***************************************************************************************
00056 class CdotXSITemplate;
00057 class CdotXSITemplates;
00058 
00059 typedef struct
00060 {
00061     SI_Int      nLen;
00062     SI_Char    *pLabel;
00063 } TdotXSIDictEntry;
00064 
00065 class CXSIParser;
00066 
00067 typedef SI_Void (*SI_READ_CALLBACK_FNC) ( CXSIParser* );
00068 
00071 class XSIEXPORT CXSIReturn
00072 {
00073     public:
00074         void            *m_pPointer;
00075         CSIBCString     m_Parameter;
00076         int             m_Flags;
00077 };
00078 
00079 
00082 class XSIEXPORT CdotXSIDict
00083 {
00084 public :
00087     CdotXSIDict();
00090     ~CdotXSIDict();
00094     SI_Void     Init( SI_Int i_nCount );
00098     SI_Void     Add( SI_Char *i_pLabel );
00102     SI_Int      GetCount();
00107     SI_Void     Find( SI_Int i_nInd, SI_Char **o_pLabel );
00112     SI_Int      Find( SI_Char *i_pLabel );
00116     SI_Void     Read( _SI_FILE i_pFptr );
00120     SI_Void     Write( _SI_FILE i_pFptr );
00121 
00122 private :
00123     SI_Int              m_nTotalCount;
00124     SI_Int              m_nCount;
00125     TdotXSIDictEntry   *m_Dict;
00126 };
00127 
00130 class XSIEXPORT CXSIParser
00131 {
00132 public:
00133     CXSIParser();                                   
00134     ~CXSIParser();                                  
00135 
00140     SI_Error    Open(const CSIBCString &in_filename);
00145     SI_Bool     EndOfFile();                        // end of file ?
00149     SI_Error    Close();                            // Closes a file
00150 
00154     CSIBCString &FileName() { return m_sFilename; }
00155 
00159     SI_Int      GetNbSupportedTemplates();
00164     SI_Char     *GetSupportedTemplate(SI_Int in_lIndex);
00165 
00169     SI_Char     *GetNextTokenAsCharPtr();
00173     SI_Char     *GetNextTokenAsString();
00177     SI_Float    GetNextTokenAsFloat();
00181     SI_Int      GetNextTokenAsInteger();
00191     SI_Error    GetNextTokensAsFloatArray(  SI_Int numFloats,
00192                                             SI_Int fileStepCount,   //Step = number of sequential floats to read first,
00193                                             SI_Int fileSkipCount,   //Skip = number of tokens to skip before reading the next sequence of floats
00194                                             SI_Int arrayStepCount,  //Step = number of sequential floats to write to first
00195                                             SI_Int arraySkipCount,  //Skip = number of array indices to skip before writing the next sequence of floats
00196                                             SI_Float *i_pArray );   //Get the next series of tokens
00197 
00207     SI_Error    GetNextTokensAsIntegerArray(    SI_Int numInts,
00208                                                 SI_Int fileStepCount,   //Step = number of sequential ints to read first,
00209                                                 SI_Int fileSkipCount,   //Skip = number of tokens to skip before reading the next sequence of ints
00210                                                 SI_Int arrayStepCount,  //Step = number of sequential ints to write to first
00211                                                 SI_Int arraySkipCount,  //Skip = number of array indices to skip before writing the next sequence of ints
00212                                                 SI_Int *i_pArray );     //Get the next series of tokens
00213 
00223     SI_Error    GetNextTokensAsUnsignedShortArray(  SI_Int numUShorts,
00224                                                 SI_Int fileStepCount,   //Step = number of sequential unsigned shorts to read first,
00225                                                 SI_Int fileSkipCount,   //Skip = number of tokens to skip before reading the next sequence of unsigned shorts
00226                                                 SI_Int arrayStepCount,  //Step = number of sequential unsigned shorts to write to first
00227                                                 SI_Int arraySkipCount,  //Skip = number of array indices to skip before writing the next sequence of unsigned shorts
00228                                                 SI_UShort *i_pArray );  //Get the next series of tokens
00229 
00233     SI_Char     *GetCurrentTokenAsCharPtr();
00237     SI_Float    GetCurrentTokenAsFloat();
00238 
00242     SI_Int      GetCurrentTokenAsInteger();
00243 
00249     SI_Error    GetNextPairAsFloat( SI_Float &fX, SI_Float &fY );
00250 
00256     SI_Error    GetNextPairAsInt( SI_Int &nX, SI_Int &nY );
00257 
00264     SI_Error    GetNextTrippletAsFloat( SI_Float &fX, SI_Float &fY, SI_Float &fZ );
00265 
00272     SI_Error    GetNextTrippletAsInt( SI_Int &nX, SI_Int &nY, SI_Int &nZ );
00273 
00277     SI_Void     SetOpenMode( SI_Int i_nMode );
00282     SI_Int      GetOpenMode() { return m_nOpenMode; }
00283 
00284     // dotXSIFile support
00285 
00291     SI_Int              CheckNextToken( CSIBCString *i_pReadString );
00295     SI_Long              GetdotXSIFileVersionMajor() { return m_dotXSIFileVersionMajor; }
00299     SI_Long              GetdotXSIFileVersionMinor() { return m_dotXSIFileVersionMinor; }
00304     SI_Int              GetdotXSIFormat() { return m_dotXSIFormat; }                      //@mfunc SI_Int | CXSIParser | GetdotXSIFormat | Gets
00310     SI_Void             SetdotXSIFormat( SI_Int dotXSIFormat ) { m_dotXSIFormat = dotXSIFormat; } //@mfunc SI_Void | CXSIParser | SetdotXSIFormat | Sets the dotXSI file Formation.
00311                                                                                                   // @parm SI_Int | dotXSIFormat | dotXSI format flag.
00315     SI_Int              GetdotXSISystemFlags() { return m_dotXSISystemFlags; }                  //@mfunc SI_Int | CXSIParser | GetdotXSISystemFlags | Gets the dotXSI System Flags.
00319     SI_Void             SetdotXSISystemFlags( SI_Int dotXSISystemFlags ) { m_dotXSISystemFlags = dotXSISystemFlags; }   //@mfunc SI_Void | CXSIParser | SetdotXSISystemFlags | Sets the dotXSI System Flags.
00320                                                                                                     // @parm SI_Int | dotXSIFormat | dotXSI format flag.
00323     SI_Int              SetdotXSIFileVersion( SI_Int, SI_Int );
00324 
00329     SI_Int              GetdotXSINumFileVersion();
00333     SI_Error            GetdotXSIFileVersion( int, int* , int*  );
00334 
00337     SI_Error            Read();
00338 
00341     SI_Error            Write();
00342 
00348     SI_Bool             ReadTemplate( CSIBCString *i_sTemplateName, CdotXSITemplate *i_pParent );
00354     SI_Void             WriteTemplate( CdotXSITemplates *dotXSITemplates, SI_Int i_nInd, SI_Int i_nLevel );
00358     CdotXSITemplates   *dotXSITemplate() { return m_dotXSITemplates; }  //@mfunc CdotXSITemplates* | CXSIParser | dotXSITemplate | Checks for dotXSI templates.
00362     CdotXSITemplates   *dotXSISupported() { return m_dotXSISupported; } //@mfunc CdotXSITemplates* | CXSIParser | ditXSISupported | Checks for dotXSI support.
00366     SI_Int              GetString();
00372     SI_Error            AddEscapeChar ( const SI_Char *in_pStr, SI_Char *out_pStr );                        //@mfunc adds an escape character in front of invalid ones (ie. \" )
00373 
00374     // Read utility functions
00386     SI_Error ReadGenericParameters( CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nNbParam );
00393     SI_Error ReadParameterValue( SI_TinyVariant *o_vValue, SI_Int i_nLastInt );
00394 
00402     SI_Error ReadCOLLADAParameterValue( SI_TinyVariant *o_vValue, char **in_pStream );
00403 
00404 
00413     SI_Error ReadIntegerArray( CdotXSITemplate *i_pNewTemplate, SI_Int i_nNbVertices, SI_Char *i_sName );
00414 
00422     SI_Error ReadFloatArray( CdotXSITemplate *i_pNewTemplate, SI_Int i_nNbVertices, SI_Char *i_sName );
00423 
00431     SI_Error ReadDoubleArray( CdotXSITemplate *i_pNewTemplate, SI_Int i_nNbVertices, SI_Char *i_sName );
00432 
00433     // Writes utility functions
00437     SI_Void WriteTabs( SI_Int i_nLevel );
00443     SI_Void WriteGenericParameters( CdotXSITemplate *i_pCurrentTemplate, SI_Int i_nNbParams, SI_Int i_nLevel );
00450     SI_Void WriteParameterValue( SI_TinyVariant *i_vValue, SI_Int i_nLevel, SI_Int in_nFlag = 0 );
00456     SI_Void RegisterdotXSINativeTemplates( SI_Long i_lMajor, SI_Long i_lMinor, SI_Int i_lFormat );
00460     SI_Void CleardotXSINativeTemplates();
00464     CdotXSITemplates* GetdotXSINativeTemplates();
00465 
00466     //
00467     // New centralized IO functions
00468     //
00473     SI_Int          FTK_Eof ();
00479     SI_Int          FTK_Open (SI_Char* in_szName, _SI_FILE_MODE in_Mode );
00483     SI_Int          FTK_Close ();
00490     SI_Long         FTK_Read (void *out_pBuffer, SI_Long size, SI_Long count);
00497     SI_Int          FTK_Write (void *in_pBuffer, SI_Long size, SI_Long count);
00502     SI_Int          FTK_Printf (SI_Char* in_szData );
00512     SI_Int          FTK_Seek (SI_Long in_lCount, SI_Int in_iMode );
00516     SI_Long         FTK_Tell ();
00520     SI_Int          FTK_FGetc ();
00524     SI_Int          FTK_Getc ();
00525 
00526     //
00527     // Warning callback
00528     //
00532     SI_Void         SetWarningCallback ( SI_WARNING_CALLBACK_FNC in_pfncCallback );
00537     SI_Void         FTK_Warning ( SI_Char *in_szWarning, SI_Int in_iWarningLevel );
00538 
00542     SI_Error        GetLastError() { return m_nLastError; }
00543 
00544     //
00545     // read callback
00546     //
00550     SI_Void                 SetReadCallback(SI_READ_CALLBACK_FNC in_pCallback);
00554     SI_READ_CALLBACK_FNC    GetReadCallback();
00555 
00558     SI_Void ClearSkipTable();
00559 
00562     SI_Void SkipTemplate ( CSIBCString );
00563 
00564       // -----------------------------------------------------------------------
00565     //  Implementations of the SAX DocumentHandler interface
00566     // -----------------------------------------------------------------------
00567     void endDocument();
00568 
00569     void endElement( const void* const uri,
00570                      const void* const localname,
00571                      const void* const qname);
00572 
00573     void characters(const void* const chars, const unsigned int length);
00574 
00575     void ignorableWhitespace
00576     (
00577         const   void* const    chars
00578         , const unsigned int    length
00579     );
00580 
00581     void processingInstruction
00582     (
00583         const   void* const    target
00584         , const void* const    data
00585     );
00586 
00587     void startDocument();
00588 
00589     void startElement(  const   void* const    uri,
00590                         const   void* const    localname,
00591                         const   void* const    qname,
00592                         const   void*       attributes);
00593 
00594     SI_Char* GetErrors() { return m_csError.GetText (); }
00595 
00596 
00597     // -----------------------------------------------------------------------
00598     //  Implementations of the SAX ErrorHandler interface
00599     // -----------------------------------------------------------------------
00600     void warning(const void* exception);
00601     void error(const void* exception);
00602     void fatalError(const void* exception);
00603 
00604     CdotXSITemplate*    ResolveTemplateURL ( const SI_Char* in_szLibrary, const SI_Char* in_URL );
00605 
00606 
00607 protected:
00608     SI_Error    ParseToken();                               // Parse content for next token
00609     SI_Error    ParseCOLLADAToken(char **in_pStream);       // Parse COLLADA content for next token
00610 
00611     SI_Int      CheckFileType();                            // check first few bytes for the file type
00612 
00613 private:
00614 
00615     SI_Error            ReadCOLLADA();
00616     SI_Error            WriteCOLLADA();
00617     SI_Void             WriteCOLLADATemplate( CdotXSITemplates *dotXSITemplates, SI_Int i_nInd, SI_Int i_nLevel );
00618 
00619     enum
00620     {
00621         BUFFER_SIZE = 1024,
00622         FILE_BUFFER_SIZE = 16384
00623     };
00624 
00625     CSIBCString m_sFilename;                        // File name
00626     SI_Char     *m_Buffer;                          // File read buffer
00627     SI_Int      m_BufferSize;
00628     SI_Char     *m_pCurrentToken;                   // Current token
00629     SI_Int      m_nOpenMode;                        // 0 = READ, 1 = WRITE
00630     SI_Error    m_nLastError;                       // Holds the last error that occurred during parsing.
00631 
00632     SI_Bool     IsInvalidParameterValue();          // Checks the current token, to see if it might not be a valid parameter.
00633     SI_Error    IncrementParseSpot();
00634     SI_Error    GetNextByte(SI_Byte *in_pRead);
00635     void        CreateFilter ();
00636     SI_Error    ReadDotXSIHeader();
00637     CXSIFilter* CreateFilterFromID ( SI_Char* in_szID );
00638 
00639     // dotXSIFile support
00640     CdotXSITemplates   *m_dotXSITemplates;
00641     CdotXSITemplates   *m_dotXSISupported;
00642     CdotXSITemplates   *m_dotXSIUnsupported;
00643 
00644     SI_Long             m_dotXSIFileVersionMajor;
00645     SI_Long             m_dotXSIFileVersionMinor;
00646     SI_Int              m_dotXSIFormat;                 // TEXT | BINARY
00647     SI_Int              m_dotXSISystemFlags;
00648 
00649     CdotXSIDict         m_dotXSIDict;
00650     CdotXSITemplates    m_dotXSINativeTemplates;
00651     CSIAccumString      m_szAccumBuffer;
00652     SI_Long             m_lFilePtr;
00653 
00654     //
00655     // IO Filter
00656     //
00657 
00658     CXSIFilter          *m_pParserFilter;
00659     SI_Int              m_iDataExported;
00660 
00661     //
00662     // Warning reporting callback
00663     //
00664     SI_WARNING_CALLBACK_FNC m_pfncWarningCallback;
00665 
00666     // read callback
00667     SI_READ_CALLBACK_FNC m_pReadCallback;
00668 
00669     //
00670     // COLLADA Specific
00671     //
00672     xercesc_2_7::SAX2XMLReader      *m_pXMLParser;
00673     CSIBCString         m_XMLBuffer;
00674     CSIBCString         m_csError;
00675     CCOLLADATemplate    *m_pParentTemplate;
00676     CdotXSITemplate*    RecurseResolveURL ( CdotXSITemplate* in_pTemplate, const SI_Char* libID, const SI_Char* in_URL );
00677 
00678     CSIBCArray<CSIBCString> m_SkipTable;
00679     SI_Int                  m_iIsInsideExtra;
00680     bool                    m_bNoTyping;
00681 };
00682 
00683 
00684 //***************************************************************************************
00685 // Global Functions
00686 //***************************************************************************************
00694 extern SI_Bool IsSeparator( SI_Char i_Char );
00695 
00696 /* \@}
00697 */
00698 
00699 
00710 SI_Error dotXSICB_ReadGeneric( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00717 SI_Error dotXSICB_ReadCluster( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00724 SI_Error dotXSICB_ReadConstraint( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00731 SI_Error dotXSICB_ReadCustomPSet( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00738 SI_Error dotXSICB_ReadEnvelope( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00745 SI_Error dotXSICB_ReadFCurve( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00752 SI_Error dotXSICB_ReadFileInfo( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00759 SI_Error dotXSICB_ReadIKRoot( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00766 SI_Error dotXSICB_ReadImageClip( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00773 SI_Error dotXSICB_ReadLight( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00780 SI_Error dotXSICB_ReadNurbsSurface( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00787 SI_Error dotXSICB_ReadNurbsCurve( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00794 SI_Error dotXSICB_ReadPatchSurface( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00801 SI_Error dotXSICB_ReadPolygonList( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00808 SI_Error dotXSICB_ReadScene( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00815 SI_Error dotXSICB_ReadShape( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00822 SI_Error dotXSICB_ReadTriangleList( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00829 SI_Error dotXSICB_ReadTriStrip( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate );
00830 
00838 SI_Error dotXSICB_WriteGeneric( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nLevel );
00846 SI_Error dotXSICB_WriteCluster( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nLevel );
00854 SI_Error dotXSICB_WriteConstraint( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nLevel );
00862 SI_Error dotXSICB_WriteCustomPSet( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nLevel );
00870 SI_Error dotXSICB_WriteEnvelope( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nLevel );
00878 SI_Error dotXSICB_WriteFCurve( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nLevel );
00886 SI_Error dotXSICB_WriteFileInfo( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nLevel );
00894 SI_Error dotXSICB_WriteIKRoot( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nLevel );
00902 SI_Error dotXSICB_WriteImageClip( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nLevel );
00910 SI_Error dotXSICB_WriteNurbsSurface( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nLevel );
00918 SI_Error dotXSICB_WriteNurbsCurve( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nLevel );
00926 SI_Error dotXSICB_WritePatchSurface( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nLevel );
00934 SI_Error dotXSICB_WritePolygonList( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nLevel );
00942 SI_Error dotXSICB_WriteShape( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nLevel );
00950 SI_Error dotXSICB_WriteTriangleList( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nLevel );
00958 SI_Error dotXSICB_WriteTriStrip( CXSIParser *i_pParser, CdotXSITemplate *i_pCurrentTemplate, CdotXSITemplate *i_pNewTemplate, SI_Int i_nLevel );
00959 
00960 /* \@}
00961 */
00962 
00963 #endif // CXSIParser