SUMO - Simulation of Urban MObility
PlainXMLFormatter.cpp
Go to the documentation of this file.
00001 /****************************************************************************/
00007 // Static storage of an output device and its base (abstract) implementation
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00011 /****************************************************************************/
00012 //
00013 //   This file is part of SUMO.
00014 //   SUMO is free software: you can redistribute it and/or modify
00015 //   it under the terms of the GNU General Public License as published by
00016 //   the Free Software Foundation, either version 3 of the License, or
00017 //   (at your option) any later version.
00018 //
00019 /****************************************************************************/
00020 
00021 
00022 // ===========================================================================
00023 // included modules
00024 // ===========================================================================
00025 #ifdef _MSC_VER
00026 #include <windows_config.h>
00027 #else
00028 #include <config.h>
00029 #endif
00030 
00031 #include <utils/common/ToString.h>
00032 #include <utils/options/OptionsCont.h>
00033 #include "PlainXMLFormatter.h"
00034 
00035 #ifdef CHECK_MEMORY_LEAKS
00036 #include <foreign/nvwa/debug_new.h>
00037 #endif // CHECK_MEMORY_LEAKS
00038 
00039 
00040 // ===========================================================================
00041 // member method definitions
00042 // ===========================================================================
00043 PlainXMLFormatter::PlainXMLFormatter(const unsigned int defaultIndentation)
00044     : myDefaultIndentation(defaultIndentation) {
00045 }
00046 
00047 
00048 bool
00049 PlainXMLFormatter::writeXMLHeader(std::ostream& into, const std::string& rootElement, const std::string xmlParams,
00050                                   const std::string& attrs, const std::string& comment) {
00051     if (myXMLStack.empty()) {
00052         OptionsCont::getOptions().writeXMLHeader(into, xmlParams);
00053         if (comment != "") {
00054             into << comment << "\n";
00055         }
00056         openTag(into, rootElement);
00057         if (attrs != "") {
00058             into << " " << attrs;
00059         }
00060         into << ">\n";
00061         return true;
00062     }
00063     return false;
00064 }
00065 
00066 
00067 void
00068 PlainXMLFormatter::openTag(std::ostream& into, const std::string& xmlElement) {
00069     into << std::string(4 * (myXMLStack.size() + myDefaultIndentation), ' ') << "<" << xmlElement;
00070     myXMLStack.push_back(xmlElement);
00071 }
00072 
00073 
00074 void
00075 PlainXMLFormatter::openTag(std::ostream& into, const SumoXMLTag& xmlElement) {
00076     openTag(into, toString(xmlElement));
00077 }
00078 
00079 
00080 void
00081 PlainXMLFormatter::closeOpener(std::ostream& into) {
00082     into << ">\n";
00083 }
00084 
00085 
00086 bool
00087 PlainXMLFormatter::closeTag(std::ostream& into, bool abbreviated) {
00088     if (!myXMLStack.empty()) {
00089         if (abbreviated) {
00090             into << "/>\n";
00091         } else {
00092             const std::string indent(4 * (myXMLStack.size() + myDefaultIndentation - 1), ' ');
00093             into << indent << "</" << myXMLStack.back() << ">\n";
00094         }
00095         myXMLStack.pop_back();
00096         return true;
00097     }
00098     return false;
00099 }
00100 
00101 
00102 void
00103 PlainXMLFormatter::writeAttr(std::ostream& into, const std::string& attr, const std::string& val) {
00104     into << " " << attr << "=\"" << val << "\"";
00105 }
00106 
00107 /****************************************************************************/
00108 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines