1/* 2 * Copyright (c) 1999-2000, Eric Moon. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions, and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions, and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * 3. The name of the author may not be used to endorse or promote products 17 * derived from this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 27 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 32// xml_export_utils.h 33// * PURPOSE 34// helper functions for writing XML representations of 35// C++ objects. 36// 37// * HISTORY 38// e.moon 5jul99 Begun 39 40#ifndef __xml_export_utils_H__ 41#define __xml_export_utils_H__ 42 43#include "cortex_defs.h" 44__BEGIN_CORTEX_NAMESPACE 45 46// Writes the correct number of spaces to the given stream, 47// so that text written after this call will start at the given 48// column. 49// Assumes that the given text string has already been written 50// (with the level of indentation currently stored in the given 51// context.) 52 53inline ostream& pad_with_spaces( 54 ostream& str, 55 const char* text, 56 ExportContext& context, 57 uint16 column=30) { 58 59 int16 spaces = column - (strlen(text) + context.indentLevel()); 60 if(spaces < 0) spaces = 0; 61 while(spaces--) str << ' '; 62 return str; 63} 64 65 66// Writes the given key/value as an XML attribute (a newline 67// is written first, to facilitate compact representation of 68// elements with no attributes.) 69 70template <class T> 71void write_attr( 72 const char* key, 73 T value, 74 ostream& stream, 75 ExportContext& context) { 76 77 stream << endl << context.indentString() << key; 78 pad_with_spaces(stream, key, context) << " = '" << value << '\''; 79} 80 81__END_CORTEX_NAMESPACE 82 83#endif /*__xml_export_utils_H__*/ 84