31#ifndef CFGFILE__UTILS_HPP__INCLUDED
32#define CFGFILE__UTILS_HPP__INCLUDED
41#if defined( CFGFILE_QT_SUPPORT ) && defined( CFGFILE_XML_SUPPORT )
43#include <QDomDocument>
70template<
typename Trait =
string_trait_t >
81 static const typename Trait::char_t
xml = Trait::from_ascii(
'<' );
83 typename Trait::char_t
ch( 0x00 );
85 while( !Trait::is_at_end( m_stream ) )
89 if( Trait::is_space(
ch ) )
103 typename Trait::istream_t & m_stream;
114template<
typename Trait =
string_trait_t >
115static inline void read_cfgfile(
119 typename Trait::istream_t & stream,
121 const typename Trait::string_t & file_name )
126 details::determine_format_t< Trait > d( stream );
131 Trait::to_begin( stream );
137 input_stream_t< Trait > is( file_name, stream );
139 parser_t< Trait > parser( tag, is );
141 parser.parse( file_name );
147#ifdef CFGFILE_QT_SUPPORT
148#ifdef CFGFILE_XML_SUPPORT
155 const QString data = stream.readAll();
157 if( !doc.setContent( data,
true, &error, &line, &column ) )
158 throw exception_t< Trait >( QString(
"Unable to parse XML "
159 "from file: \"%1\". \"%2\" On line %3, column %4." )
162 .arg( QString::number( line ) )
163 .arg( QString::number( column ) ) );
165 parser_t< Trait > parser( tag, doc );
167 parser.parse( file_name );
169 throw exception_t< Trait >(
170 Trait::from_ascii(
"To use XML format build cfgfile "
171 "with CFGFILE_XML_SUPPORT" ) );
174 throw exception_t< Trait >(
175 Trait::from_ascii(
"XML supported only with Qt. Parsing of file \"" ) +
176 file_name + Trait::from_ascii(
"\" failed." ) );
189template<
typename Trait >
190static inline void write_cfgfile(
194 typename Trait::ostream_t & stream,
202 const typename Trait::string_t content = tag.
print();
210#ifdef CFGFILE_QT_SUPPORT
211#ifdef CFGFILE_XML_SUPPORT
216 stream << doc.toString( 4 );
218 throw exception_t< Trait >(
219 Trait::from_ascii(
"To use XML format build cfgfile "
220 "with CFGFILE_XML_SUPPORT" ) );
223 throw exception_t< Trait >(
224 Trait::from_ascii(
"XML supported only with Qt." ) );
Exception in the library.
Definition exceptions.hpp:51
virtual Trait::string_t print(int indent=0) const =0
Print tag to the output.
file_format_t
Format of the conf file.
Definition utils.hpp:55
@ cfgfile_format
cfgfile format.