DWFXMLSerializer.h

Go to the documentation of this file.
00001 //
00002 //  Copyright (c) 1996-2006 by Autodesk, Inc.
00003 //
00004 //  By using this code, you are agreeing to the terms and conditions of
00005 //  the License Agreement included in the documentation for this code.
00006 //
00007 //  AUTODESK MAKES NO WARRANTIES, EXPRESS OR IMPLIED, AS TO THE CORRECTNESS
00008 //  OF THIS CODE OR ANY DERIVATIVE WORKS WHICH INCORPORATE IT. AUTODESK
00009 //  PROVIDES THE CODE ON AN "AS-IS" BASIS AND EXPLICITLY DISCLAIMS ANY
00010 //  LIABILITY, INCLUDING CONSEQUENTIAL AND INCIDENTAL DAMAGES FOR ERRORS,
00011 //  OMISSIONS, AND OTHER PROBLEMS IN THE CODE.
00012 //
00013 //  Use, duplication, or disclosure by the U.S. Government is subject to
00014 //  restrictions set forth in FAR 52.227-19 (Commercial Computer Software
00015 //  Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) (Rights in Technical
00016 //  Data and Computer Software), as applicable.
00017 //
00018 
00019 
00020 #ifndef _DWFTK_DWFXMLSERIALIZER_H
00021 #define _DWFTK_DWFXMLSERIALIZER_H
00022 
00023 
00028 
00029 
00030 
00031 #include "dwfcore/STL.h"
00032 #include "dwfcore/UUID.h"
00033 #include "dwfcore/InputStream.h"
00034 #include "dwfcore/BufferOutputStream.h"
00035 #include "dwfcore/XMLEncodingOutputStream.h"
00036 #include "dwfcore/UTF8EncodingOutputStream.h"
00037 using namespace DWFCore;
00038 
00039 //#include "dwf/Toolkit.h"
00040 //#include "dwf/package/XML.h"
00041 
00042     //
00043     //
00044     //
00045 #ifndef DWFCORE_XMLSERIALIZER_WRITE_BUFFER_BYTES
00046 #define DWFCORE_XMLSERIALIZER_WRITE_BUFFER_BYTES      16384
00047 #endif
00048 
00049     //
00050     //
00051     //
00052 #ifndef DWFCORE_XMLSERIALIZER_ENCODING_BUFFER_BYTES
00053 #define DWFCORE_XMLSERIALIZER_ENCODING_BUFFER_BYTES   4096
00054 #endif
00055 
00056 
00057 namespace DWFCore
00058 {
00059 
00065 class DWFXMLSerializer : public DWFCoreMemory
00066 {
00067 
00068 public:
00069 
00073     typedef enum
00074     {
00075         eElementOpen = 0x00010000
00076 
00077     } teFlags;
00078 
00079 public:
00080 
00088     _DWFCORE_API
00089     DWFXMLSerializer( DWFUUID& rUUID )
00090         throw();
00091 
00097     _DWFCORE_API
00098     virtual ~DWFXMLSerializer()
00099         throw();
00100 
00109     _DWFCORE_API
00110     void attach( DWFOutputStream& rStream )
00111         throw( DWFException );
00112 
00118     _DWFCORE_API
00119     void detach()
00120         throw( DWFException );
00121 
00136     _DWFCORE_API
00137     const DWFString& nextUUID( bool bSquash )
00138         throw();
00139 
00145     _DWFCORE_API
00146     void emitXMLHeader()
00147         throw( DWFException );
00155     _DWFCORE_API
00156     void startElement( const DWFString& zName, const DWFString& zNamespace = /*NOXLATE*/L"" )
00157         throw( DWFException );
00158 
00167     _DWFCORE_API
00168     void addAttribute( const DWFString& zName, const DWFString& zValue, const DWFString& zNamespace = /*NOXLATE*/L"" )
00169         throw( DWFException );
00170 
00180     _DWFCORE_API
00181     void addAttribute( const DWFString& zName, int nValue, const DWFString& zNamespace = /*NOXLATE*/L"" )
00182         throw( DWFException );
00183 
00194     _DWFCORE_API
00195     void addAttribute( const DWFString& zName, const int* anValues, size_t nCount, const DWFString& zNamespace = /*NOXLATE*/L"" )
00196         throw( DWFException );
00197 
00207     _DWFCORE_API
00208     void addAttribute( const DWFString& zName, const float& fValue, const DWFString& zNamespace = /*NOXLATE*/L"" )
00209         throw( DWFException );
00210 
00221     _DWFCORE_API
00222     void addAttribute( const DWFString& zName, const float* anValues, size_t nCount, const DWFString& zNamespace = /*NOXLATE*/L"" )
00223         throw( DWFException );
00224 
00234     _DWFCORE_API
00235     void addAttribute( const DWFString& zName, const double& dValue, const DWFString& zNamespace = /*NOXLATE*/L"" )
00236         throw( DWFException );
00237 
00248     _DWFCORE_API
00249     void addAttribute( const DWFString& zName, const double* anValues, size_t nCount, const DWFString& zNamespace = /*NOXLATE*/L"" )
00250         throw( DWFException );
00251 
00258     _DWFCORE_API
00259     void addCData( const DWFString& zCData )
00260         throw( DWFException );
00261 
00276     _DWFCORE_API
00277     void insertXMLStream( DWFInputStream* pInputStream, bool bCloseCurrentElement=true )
00278         throw( DWFException );
00279 
00285     _DWFCORE_API
00286     void endElement()
00287         throw( DWFException );
00288 
00289 protected:
00290 
00291     class XMLOutputStream 
00292         : public DWFBufferOutputStream
00293     {
00294     public:
00295 
00296         XMLOutputStream( DWFOutputStream& rOutputStream )
00297             throw();
00298 
00299         virtual ~XMLOutputStream()
00300             throw();
00301 
00302         //
00303         // use this method for publishing the xml data
00304         // it will be encoded correctly
00305         //
00306         size_t writeXML( const void*   pBuffer,
00307                          size_t        nBytesToWrite )
00308             throw( DWFException );
00309 
00310         //
00311         // stream interface - called back into for
00312         // writing to buffer
00313         //
00314         size_t write( const void*   pBuffer,
00315                       size_t        nBytesToWrite )
00316             throw( DWFException );
00317 
00318         //
00319         // toggles XML encoding - certain characters "<", ">", etc
00320         // shouldn't be XML encoded as they are written to the stream
00321         //
00322         void encode( bool bXML = true )
00323         {
00324             _bXML = bXML;
00325         }
00326 
00327     private:
00328         bool                        _bXML;
00329         DWFXMLEncodingOutputStream  _oXMLStream;
00330         DWFUTF8EncodingOutputStream _oUTF8Stream;
00331     };
00332 
00333 protected:
00334 
00335     XMLOutputStream*        _pStream;
00336 
00337 private:
00338 
00339     DWFUUID&                _rUUID;
00340 
00341     bool                            _bLastElementOpen;
00342     const DWFString*                _pLastElement;
00343 
00344     // TODO:  Do something like this in core
00345     //_DWFTK_STD_VECTOR(DWFString)    _oDepthChart;
00346     std::vector<DWFString>          _oDepthChart;
00347 
00348     wchar_t*                        _zBuffer;
00349     size_t                          _nBufferSize;
00350 
00351 private:
00352 
00353     //
00354     // Unimplemented methods
00355     //
00356 
00357     DWFXMLSerializer( const DWFXMLSerializer& );
00358     DWFXMLSerializer& operator=( const DWFXMLSerializer& );
00359 };
00360 
00361 }
00362 
00363 #endif
00364 

Generated on Tue Jan 6 22:39:28 2009 for Autodesk DWF Core Library by  doxygen 1.4.5