source: NonGTP/Boost/boost/test/utils/xml_printer.hpp @ 857

Revision 857, 4.4 KB checked in by igarcia, 18 years ago (diff)
Line 
1//  (C) Copyright Gennadiy Rozental 2004-2005.
2//  Distributed under the Boost Software License, Version 1.0.
3//  (See accompanying file LICENSE_1_0.txt or copy at
4//  http://www.boost.org/LICENSE_1_0.txt)
5
6//  See http://www.boost.org/libs/test for the library home page.
7//
8//  File        : $RCSfile: xml_printer.hpp,v $
9//
10//  Version     : $Revision: 1.7 $
11//
12//  Description : common code used by any agent serving as XML printer
13// ***************************************************************************
14
15#ifndef BOOST_TEST_XML_PRINTER_HPP_071894GER
16#define BOOST_TEST_XML_PRINTER_HPP_071894GER
17
18// Boost.Test
19#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
20#include <boost/test/utils/fixed_mapping.hpp>
21#include <boost/test/utils/custom_manip.hpp>
22#include <boost/test/utils/foreach.hpp>
23
24// Boost
25#include <boost/config.hpp>
26
27// STL
28#include <iostream>
29
30#include <boost/test/detail/suppress_warnings.hpp>
31
32//____________________________________________________________________________//
33
34namespace boost {
35
36namespace unit_test {
37
38// ************************************************************************** //
39// **************               xml print helpers              ************** //
40// ************************************************************************** //
41
42inline void
43print_escaped( std::ostream& where_to, const_string value )
44{
45    static fixed_mapping<char,char const*> char_type(
46        '<' , "lt",
47        '>' , "gt",
48        '&' , "amp",
49        '\'', "apos" ,
50        '"' , "quot",
51
52        0
53    );
54
55    BOOST_TEST_FOREACH( char, c, value ) {
56        char const* ref = char_type[c];
57
58        if( ref )
59            where_to << '&' << ref << ';';
60        else
61            where_to << c;
62    }
63}
64
65//____________________________________________________________________________//
66
67inline void
68print_escaped( std::ostream& where_to, std::string const& value )
69{
70        print_escaped( where_to, const_string( value ) );
71}
72
73//____________________________________________________________________________//
74
75template<typename T>
76inline void
77print_escaped( std::ostream& where_to, T const& value )
78{
79        where_to << value;
80}
81
82//____________________________________________________________________________//
83
84typedef custom_manip<struct attr_value_t> attr_value;
85
86template<typename T>
87inline std::ostream&
88operator<<( custom_printer<attr_value> const& p, T const& value )
89{
90        *p << "=\"";
91        print_escaped( *p, value );
92        *p << '"';
93
94        return *p;
95}
96
97//____________________________________________________________________________//
98
99typedef custom_manip<struct pcdata_t> pcdata;
100
101inline std::ostream&
102operator<<( custom_printer<pcdata> const& p, const_string value )
103{
104    print_escaped( *p, value );
105
106    return *p;
107}
108
109//____________________________________________________________________________//
110
111} // namespace unit_test
112
113} // namespace boost
114
115//____________________________________________________________________________//
116
117#include <boost/test/detail/enable_warnings.hpp>
118
119// ***************************************************************************
120//  Revision History :
121//
122//  $Log: xml_printer.hpp,v $
123//  Revision 1.7  2005/07/14 15:50:28  dgregor
124//  Untabify
125//
126//  Revision 1.6  2005/04/29 06:31:18  rogeeff
127//  bug fix for incorrect XML output
128//
129//  Revision 1.5  2005/02/20 08:27:08  rogeeff
130//  This a major update for Boost.Test framework. See release docs for complete list of fixes/updates
131//
132//  Revision 1.4  2005/02/01 06:40:08  rogeeff
133//  copyright update
134//  old log entries removed
135//  minor stilistic changes
136//  depricated tools removed
137//
138//  Revision 1.3  2005/01/23 09:59:34  vawjr
139//  Changed - all the \r\r\n to \r\n in the windows flavor of the file
140//            because VC++ 8.0 complains and refuses to compile
141//
142//  Revision 1.2  2005/01/22 19:22:13  rogeeff
143//  implementation moved into headers section to eliminate dependency of included/minimal component on src directory
144//
145//  Revision 1.1  2005/01/22 18:21:40  rogeeff
146//  moved sharable staff into utils
147//
148//  Revision 1.3  2005/01/21 07:31:44  rogeeff
149//  xml helper facilities reworked to present manipulator interfaces
150//
151// ***************************************************************************
152
153#endif // BOOST_TEST_XML_PRINTER_HPP_071894GER
Note: See TracBrowser for help on using the repository browser.