00001 /* 00002 ot_lib - Object Type Library 00003 Copyright (C) 2002 Alessandro Bonfanti 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free 00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 00019 Alessandro Bonfanti 00020 xjbon@tin.it 00021 */ 00022 00023 00024 // ------------------------------------ 00026 // ------------------------------------ 00027 00028 #ifndef OT_XML_H 00029 #define OT_XML_H 00030 00031 template <class X> class xmlTag 00032 { 00033 private: 00034 ostream &out; 00035 string tagName; 00036 string indent_str; 00037 bool indent; 00038 00039 public: 00040 00045 xmlTag(ostream &o,int indent,const string &t) : out(o), tagName(t), indent(true) 00046 { 00047 for(int i=0;i<indent;i++) indent_str+=" "; 00048 00049 out << indent_str << "<" << tagName << ">" << endl; 00050 } 00051 00052 00058 xmlTag(ostream &o,int indent,const string &t,const X &v) : out(o), tagName(t), indent(false) 00059 { 00060 for(int i=0;i<indent;i++) indent_str+=" "; 00061 00062 out << indent_str << "<" << tagName << ">" << v; 00063 } 00064 00065 00067 ~xmlTag(void) 00068 { 00069 if(indent) out << indent_str << "</" << tagName << ">" << endl; 00070 else out << "</" << tagName << ">" << endl; 00071 } 00072 00075 void addValue(const X &v) 00076 { 00077 out << indent_str << " " << v << endl; 00078 } 00079 }; 00080 00081 #else 00082 #endif 00083