00001 // This file is part of ff3d - http://www.freefem.org/ff3d 00002 // Copyright (C) 2001, 2002, 2003 Stéphane Del Pino 00003 00004 // This program is free software; you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation; either version 2, or (at your option) 00007 // any later version. 00008 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program; if not, write to the Free Software Foundation, 00016 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 00018 // $Id: XMLWriter.hpp,v 1.6 2008/02/02 23:47:28 delpinux Exp $ 00019 00020 #ifndef XML_WRITER_HPP 00021 #define XML_WRITER_HPP 00022 00023 #include <XMLTag.hpp> 00024 00025 #include <iostream> 00026 #include <string> 00027 #include <stack> 00028 00036 class XMLWriter 00037 { 00038 private: 00039 std::ostream& __os; 00040 std::stack<std::string> __openTagsName; 00041 00042 public: 00043 void insert(const real_t& f) 00044 { 00045 __os << ' ' << f; 00046 } 00047 00048 void insert(const int& f) 00049 { 00050 __os << ' ' << f; 00051 } 00052 00053 void insert(const size_t& f) 00054 { 00055 __os << ' ' << f; 00056 } 00057 00058 void insertUnderscore() 00059 { 00060 for (size_t i=0; i<__openTagsName.size(); ++i) { 00061 __os << " "; 00062 } 00063 __os << '_'; 00064 } 00065 00066 void insertNewLine() 00067 { 00068 __os << '\n'; 00069 } 00070 00071 void writeHeader() 00072 { 00073 __os << "<?xml version=\"1.0\"?>"; 00074 if (StreamCenter::instance().getDebugLevel() > 0) { 00075 __os << " <!-- Generated by " << PACKAGE_STRING " -->"; 00076 } 00077 __os << '\n'; 00078 } 00079 00080 void add(const XMLTag& xmlTag) 00081 { 00082 for (size_t i=0; i<__openTagsName.size(); ++i) { 00083 __os << " "; 00084 } 00085 __os << '<' << xmlTag << ">\n"; 00086 __openTagsName.push(xmlTag.name()); 00087 } 00088 00089 void closeTag() 00090 { 00091 for (size_t i=1; i<__openTagsName.size(); ++i) { 00092 __os << " "; 00093 } 00094 __os << "</" << __openTagsName.top() << ">\n"; 00095 __openTagsName.pop(); 00096 } 00097 00098 XMLWriter(std::ostream& os) 00099 : __os(os) 00100 { 00101 ; 00102 } 00103 00104 ~XMLWriter() 00105 { 00106 while (not(__openTagsName.empty())) { 00107 this->closeTag(); 00108 } 00109 } 00110 }; 00111 00112 #endif // XML_WRITER_HPP
1.5.6