diff options
Diffstat (limited to 'src/tafwriter.cpp')
-rw-r--r-- | src/tafwriter.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/tafwriter.cpp b/src/tafwriter.cpp new file mode 100644 index 0000000..6b505ef --- /dev/null +++ b/src/tafwriter.cpp | |||
@@ -0,0 +1,70 @@ | |||
1 | #include "tafwriter.h" | ||
2 | |||
3 | Bu::TafWriter::TafWriter( Bu::Stream &sOut ) : | ||
4 | sOut( sOut ) | ||
5 | { | ||
6 | } | ||
7 | |||
8 | Bu::TafWriter::~TafWriter() | ||
9 | { | ||
10 | } | ||
11 | |||
12 | void Bu::TafWriter::writeGroup( const Bu::TafGroup *pRoot ) | ||
13 | { | ||
14 | sOut.write("{", 1 ); | ||
15 | writeString( pRoot->getName() ); | ||
16 | sOut.write(": ", 2 ); | ||
17 | const Bu::TafGroup::NodeList &nl = pRoot->getChildren(); | ||
18 | for( Bu::TafGroup::NodeList::const_iterator i = nl.begin(); i != nl.end(); i++ ) | ||
19 | { | ||
20 | switch( (*i)->getType() ) | ||
21 | { | ||
22 | case Bu::TafNode::typeGroup: | ||
23 | writeGroup( (Bu::TafGroup *)(*i) ); | ||
24 | break; | ||
25 | |||
26 | case Bu::TafNode::typeProperty: | ||
27 | writeProperty( (Bu::TafProperty *)(*i) ); | ||
28 | break; | ||
29 | |||
30 | case Bu::TafNode::typeComment: | ||
31 | writeComment( (Bu::TafComment *)(*i) ); | ||
32 | break; | ||
33 | } | ||
34 | } | ||
35 | sOut.write("}", 1 ); | ||
36 | } | ||
37 | |||
38 | void Bu::TafWriter::writeProperty( const Bu::TafProperty *pProp ) | ||
39 | { | ||
40 | writeString( pProp->getName() ); | ||
41 | if( pProp->getValue().getStr() != NULL ) | ||
42 | { | ||
43 | sOut.write("=", 1 ); | ||
44 | writeString( pProp->getValue() ); | ||
45 | } | ||
46 | sOut.write(" ", 1 ); | ||
47 | } | ||
48 | |||
49 | void Bu::TafWriter::writeComment( const Bu::TafComment *pComment ) | ||
50 | { | ||
51 | sOut.write("/*", 2 ); | ||
52 | sOut.write( pComment->getText().getStr(), pComment->getText().getSize() ); | ||
53 | sOut.write("*/ ", 3 ); | ||
54 | } | ||
55 | |||
56 | void Bu::TafWriter::writeString( const Bu::FString &str ) | ||
57 | { | ||
58 | if( str.getStr() == NULL ) | ||
59 | return; | ||
60 | sOut.write("\"", 1 ); | ||
61 | for( const char *s = str.getStr(); *s; s++ ) | ||
62 | { | ||
63 | if( *s == '\"' ) | ||
64 | sOut.write("\\\"", 2 ); | ||
65 | else | ||
66 | sOut.write( s, 1 ); | ||
67 | } | ||
68 | sOut.write("\"", 1 ); | ||
69 | } | ||
70 | |||