MAK RTIspy API Documentation for HLA 1.3
spyXmlDocument.h
Go to the documentation of this file.
00001 /*********************************************************************
00002  ** Copyright (c) 2006 MaK Technologies, Inc.
00003  ** All rights reserved.
00004  *********************************************************************/
00005 /*******************************************************************************
00006  ** $RCSfile: spyXmlDocument.h,v $ $Revision: 1.10 $ $State: Exp $
00007  *******************************************************************************/
00008 #ifndef DtSpyXmlDocument_H_
00009 #define DtSpyXmlDocument_H_
00010 
00011 #include <rtiMsConfig.h>
00012 #include "spyXmlBlock.h"
00013 #include <mtl/env.h>
00014 #include <mtl/envXMLWriter.h>
00015 #include <vlutil/vlString.h>
00016 #include <vlutil/vlFilename.h>
00017 #include <iosfwd>
00018 
00019 class DtSpyXmlDocument;
00020 
00021 typedef DtBoost::shared_ptr<DtSpyXmlDocument> DtSpyXmlDocumentSP;
00022 typedef DtBoost::weak_ptr<DtSpyXmlDocument>   DtSpyXmlDocumentWP;
00023 
00024 
00025 class DT_DLL_WWW DtSpyXmlDocument
00026 {
00027 public:
00028 
00029    // Creates a simple XML document with a root container node with type root type
00030    // to which other nodes may be added (container is NOT a SpyXmlBlock)
00031    //
00032    // HACK!  need the disambiguateCtors parameter to ensure that implicit conversions do not choose
00033    // this ctor instead of the other versions.
00034    DtSpyXmlDocument( double disambiguateCtors,
00035       const MAKRti::DtString& rootType, bool useDtd,
00036       const MAKRti::DtFilename& dtdFilename = "" );
00037 
00038 
00039 
00040    // Create a new XML document from an existing XML string
00041    // HACK!  need the disambiguateCtors parameter to ensure that implicit conversions do not choose
00042    // this ctor instead of the templateFile version.
00043    DtSpyXmlDocument( const MAKRti::DtString& xmlString,
00044       const MAKRti::DtString& rootType,
00045       const MAKRti::DtString& rootName, double disambiguateCtors );
00046    
00047    // Create a new XML document from an existing block
00048    DtSpyXmlDocument( DtSpyXmlBlockSP root, bool useDtd, const MAKRti::DtFilename& dtdFilename = "" );
00049 
00050    // Create an XML document rooted at the specified node and build the block tree
00051    // The specified node must have a valid DtSpyXmlBlock representation
00052    // If rootName is not specified, then assume an unnamed block
00053    DtSpyXmlDocument( const MAKRti::DtFilename& templateFile, const MAKRti::DtString& rootType,
00054       const MAKRti::DtString& rootName = "", bool allowUnknownRootBlockType = false );
00055 
00056    virtual ~DtSpyXmlDocument();
00057 
00058    // Set/Get the document root
00059    // Note: setting the root on an existing document will wipe out the current 
00060    //       doc tree unless the caller has maintained a pointer to the old tree.
00061    inline DtSpyXmlBlockSP root() const;
00062    void setRoot( DtSpyXmlBlockSP root );
00063 
00064    // Output
00065    virtual const MAKRti::DtString& toString() const;
00066    virtual void writeXmlToFile( const MAKRti::DtFilename& xmlFile ) const;
00067    virtual std::ostream& print( std::ostream& ostr, bool formatedXML = true ) const;
00068 
00069 protected:
00070 
00071    // Do not allow copy/assignment since modification to copies would modify original
00072    DtSpyXmlDocument( const DtSpyXmlDocument& );
00073    DtSpyXmlDocument& operator=( const DtSpyXmlDocument& );
00074    
00075    // Build document starting from existing file
00076    // Non-virtual since this may be called from the constructor
00077    bool parseFile( const MAKRti::DtFilename& filename );   
00078 
00079    // Build document starting from existing XML string
00080    // Non-virtual since this may be called from the constructor
00081    bool parseString( const MAKRti::DtString& xmlString);
00082 
00083 
00084 protected:
00085    
00086    // Document is contained within the root block
00087    // NOTE: (modifications should be made to the DtSpyXmlBlockSP not directly through
00088    // the environment direct XML changes are temporary and not reflected in the C++ objects)
00089    DtSpyXmlBlockSP myRoot;
00090 
00091    // Dtd is optional and used only by root nodes
00092    bool            myUsingDtdValidation;
00093    MAKRti::DtFilename      myDtdFilename;
00094 
00095    // myEnvironment is mutable since it may change state as its tree is walked
00096    // and changes to myEnvironment are temporary unlike changes to the DtSpyXmlBlock
00097    mutable MAKRti::DtEnvironment myEnvironment;
00098 
00099    // myXml is mutable since it is used only as a cache
00100    mutable  MAKRti::DtString myXml;
00101 
00102    // Document writer - used to convert the document to XML in memory or file
00103    // myXmlWriter is persistant so that the XML memory buffer does not re-allocate as often
00104    std::auto_ptr< DtEnvXMLWriter > myXmlWriter;
00105 };
00106 
00107 inline std::ostream& operator<<( std::ostream& ostr, const DtSpyXmlDocument& doc )
00108 {
00109    return doc.print( ostr, true );
00110 }
00111 
00112 DtSpyXmlBlockSP DtSpyXmlDocument::root() const
00113 {
00114    return myRoot;
00115 }
00116 
00117 #endif // DtSpyXmlDocument_H_
00118 

Document ID: Generated on Thu Jun 14 14:15:04 EDT 2012 from SVN revision 116116
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)