]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - libs/script/scripttokenwriter.h
Merge commit '830125fad042fad35dc029b6eb57c8156ad7e176'
[xonotic/netradiant.git] / libs / script / scripttokenwriter.h
1 /*
2    Copyright (C) 2001-2006, William Joseph.
3    All Rights Reserved.
4
5    This file is part of GtkRadiant.
6
7    GtkRadiant is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    GtkRadiant is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with GtkRadiant; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21
22 #if !defined( INCLUDED_SCRIPT_SCRIPTTOKENWRITER_H )
23 #define INCLUDED_SCRIPT_SCRIPTTOKENWRITER_H
24
25 #include "iscriplib.h"
26
27 class SimpleTokenWriter : public TokenWriter
28 {
29 public:
30 SimpleTokenWriter( TextOutputStream& ostream )
31         : m_ostream( ostream ), m_separator( '\n' ){
32 }
33 ~SimpleTokenWriter(){
34         writeSeparator();
35 }
36 void release(){
37         delete this;
38 }
39 void nextLine(){
40         m_separator = '\n';
41 }
42 void writeToken( const char* token ){
43         ASSERT_MESSAGE( strchr( token, ' ' ) == 0, "token contains whitespace: " );
44         writeSeparator();
45         m_ostream << token;
46 }
47 void writeString( const char* string ){
48         writeSeparator();
49         m_ostream << '"' << string << '"';
50 }
51 void writeInteger( int i ){
52         writeSeparator();
53         m_ostream << i;
54 }
55 void writeUnsigned( std::size_t i ){
56         writeSeparator();
57         m_ostream << Unsigned( i );
58 }
59 void writeFloat( double f ){
60         writeSeparator();
61         m_ostream << Decimal( f );
62 }
63
64 private:
65 void writeSeparator(){
66         m_ostream << m_separator;
67         m_separator = ' ';
68 }
69 TextOutputStream& m_ostream;
70 char m_separator;
71 };
72
73 inline TokenWriter& NewSimpleTokenWriter( TextOutputStream& ostream ){
74         return *( new SimpleTokenWriter( ostream ) );
75 }
76
77 #endif