![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsXMLSimpleWriter.cpp 00003 00004 XMLSimpleWriter class (cpp file). 00005 00006 SUKITTI PUNAK (05/08/2008) 00007 UPDATE (05/08/2008) 00008 ******************************************************************************/ 00009 #include "TAPsXMLSimpleWriter.hpp" 00010 // Using Inclusion Model (i.e. definitions are included in declarations) 00011 // (this name.cpp is included in name.hpp) 00012 // Each friend is defined directly inside its declaration. 00013 00014 BEGIN_NAMESPACE_TAPs__XML 00015 //============================================================================= 00016 //----------------------------------------------------------------------------- 00017 // Constructor 00018 XMLSimpleWriter::XMLSimpleWriter () 00019 { 00020 } 00021 //----------------------------------------------------------------------------- 00022 // Destructor 00023 XMLSimpleWriter::~XMLSimpleWriter () 00024 {} 00025 //----------------------------------------------------------------------------- 00026 00027 //============================================================================= 00028 // Start of Operation Set 00029 //----------------------------------------------------------------------------- 00030 // Open the file for writing. 00031 void XMLSimpleWriter::OpenFile ( std::string const & fileName ) 00032 { 00033 try { 00034 m_outStream.open( fileName.c_str(), std::ios::out ); 00035 } 00036 catch (...) { 00037 throw "Error"; 00038 } 00039 } 00040 00041 // Write a comment. 00042 void XMLSimpleWriter::WriteComment ( std::string const & comment ) 00043 { 00044 WriteTabs(); 00045 m_outStream << "<!-- " << comment << "-->\n"; 00046 } 00047 00049 void XMLSimpleWriter::WriteXMLDeclaration () throw () 00050 { 00051 m_outStream << "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"; 00052 } 00053 00055 void XMLSimpleWriter::WriteXMLDeclaration ( std::string const & declaration ) 00056 { 00057 m_outStream << declaration << "\n"; 00058 } 00059 00061 void XMLSimpleWriter::WritXSLStyleSheetName ( std::string const & XSLName ) 00062 { 00063 m_outStream << "<?xml-stylesheet type=\"text/xsl\" href=\"" << XSLName << "\"?>\n"; 00064 } 00065 00067 void XMLSimpleWriter::WritXSLStyleSheetRef ( std::string const & XSLRef ) 00068 { 00069 m_outStream << XSLRef << "\n"; 00070 } 00071 00072 // Write name element. 00073 void XMLSimpleWriter::WriteElementInOneLine ( 00074 std::string const & name, std::string const & value ) 00075 { 00076 WriteTabs(); 00077 m_outStream << "<" << name << ">" 00078 << value 00079 << "</" << name << ">\n"; 00080 } 00081 00082 // Write closing tag of Tyco suturing simulation. 00083 void XMLSimpleWriter::WriteOpeningTag ( 00084 std::string & name, std::string const * category ) 00085 { 00086 WriteTabs(); 00087 m_strOpeningTagList.push_back( name ); 00088 m_outStream << "<" << name; 00089 if ( category ) { 00090 m_outStream << " category=\"" << *category << "\""; 00091 } 00092 m_outStream << ">\n"; 00093 } 00094 00096 void XMLSimpleWriter::WriteClosingTag () 00097 { 00098 std::string tag = m_strOpeningTagList[m_strOpeningTagList.size()-1]; 00099 m_strOpeningTagList.pop_back(); 00100 WriteTabs(); 00101 m_outStream << "</" << tag << ">\n"; 00102 } 00103 00104 // Close the file. 00105 void XMLSimpleWriter::CloseFile () 00106 { 00107 m_outStream.close(); 00108 } 00109 00110 // Close the file. 00111 void XMLSimpleWriter::WriteTabs () 00112 { 00113 for ( int i = 0; i < static_cast<int>(m_strOpeningTagList.size()); ++i ) { 00114 m_outStream << "\t"; 00115 } 00116 } 00117 //----------------------------------------------------------------------------- 00118 // End of Operation Set 00119 //============================================================================= 00120 //----------------------------------------------------------------------------- 00121 //============================================================================= 00122 END_NAMESPACE_TAPs__XML 00123 //34567890123456789012345678901234567890123456789012345678901234567890123456789 00124 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----