Fixed bug 2694067.
git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@1138 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
parent
c8216caa6c
commit
88ba6e783c
2 changed files with 54 additions and 6 deletions
|
@ -100,6 +100,21 @@ namespace Loki
|
||||||
|
|
||||||
template <class Device, class Char>
|
template <class Device, class Char>
|
||||||
struct PrintfState {
|
struct PrintfState {
|
||||||
|
|
||||||
|
/** This constructor exists only to convert a PrintfState for one device type into a
|
||||||
|
PrintfState for another device type. It is not for public use.
|
||||||
|
*/
|
||||||
|
template < class Device2 >
|
||||||
|
PrintfState( Device2 & dev, const Char * format, size_t width, size_t prec,
|
||||||
|
unsigned int flags, LOKI_SAFEFORMAT_SIGNED_LONG result )
|
||||||
|
: device_( dev )
|
||||||
|
, format_( format )
|
||||||
|
, width_( width )
|
||||||
|
, prec_( prec )
|
||||||
|
, flags_( flags )
|
||||||
|
, result_( result ) {
|
||||||
|
}
|
||||||
|
|
||||||
PrintfState(Device dev, const Char * format)
|
PrintfState(Device dev, const Char * format)
|
||||||
: device_(dev)
|
: device_(dev)
|
||||||
, format_(format)
|
, format_(format)
|
||||||
|
@ -113,6 +128,15 @@ namespace Loki
|
||||||
~PrintfState() {
|
~PrintfState() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** This function converts a PrintfState for one device type into a PrintfState for
|
||||||
|
another device type. It is not for public use.
|
||||||
|
*/
|
||||||
|
template < class Device2 >
|
||||||
|
PrintfState< Device2, Char > ChangeDevice( Device2 & device ) const
|
||||||
|
{
|
||||||
|
return PrintfState< Device2, Char >( device, format_, width_, prec_, flags_, result_ );
|
||||||
|
}
|
||||||
|
|
||||||
#define LOKI_PRINTF_STATE_FORWARD(type) \
|
#define LOKI_PRINTF_STATE_FORWARD(type) \
|
||||||
PrintfState& operator()(type par) {\
|
PrintfState& operator()(type par) {\
|
||||||
return (*this)(static_cast< LOKI_SAFEFORMAT_UNSIGNED_LONG >(par)); \
|
return (*this)(static_cast< LOKI_SAFEFORMAT_UNSIGNED_LONG >(par)); \
|
||||||
|
|
|
@ -66,27 +66,51 @@ namespace Loki
|
||||||
|
|
||||||
|
|
||||||
PrintfState<std::FILE*, char> Printf(const char* format) {
|
PrintfState<std::FILE*, char> Printf(const char* format) {
|
||||||
return PrintfState<std::FILE*, char>(stdout, format);
|
::std::string buffer;
|
||||||
|
const PrintfState< ::std::string &, char > state1( buffer, format );
|
||||||
|
::std::fwrite( buffer.c_str(), 1, buffer.size(), stdout );
|
||||||
|
PrintfState< std::FILE *, char > printState2 = state1.ChangeDevice( stdout );
|
||||||
|
return printState2;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintfState<std::FILE*, char> Printf(const std::string& format) {
|
PrintfState<std::FILE*, char> Printf(const std::string& format) {
|
||||||
return PrintfState<std::FILE*, char>(stdout, format.c_str());
|
::std::string buffer;
|
||||||
|
const PrintfState< ::std::string &, char > state1( buffer, format.c_str() );
|
||||||
|
::std::fwrite( buffer.c_str(), 1, buffer.size(), stdout );
|
||||||
|
PrintfState< std::FILE *, char > printState2 = state1.ChangeDevice( stdout );
|
||||||
|
return printState2;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintfState<std::FILE*, char> FPrintf(std::FILE* f, const char* format) {
|
PrintfState<std::FILE*, char> FPrintf(std::FILE* f, const char* format) {
|
||||||
return PrintfState<std::FILE*, char>(f, format);
|
::std::string buffer;
|
||||||
|
const PrintfState< ::std::string &, char > state1( buffer, format );
|
||||||
|
::std::fwrite( buffer.c_str(), 1, buffer.size(), f );
|
||||||
|
PrintfState< std::FILE *, char > printState2 = state1.ChangeDevice( f );
|
||||||
|
return printState2;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintfState<std::FILE*, char> FPrintf(std::FILE* f, const std::string& format) {
|
PrintfState<std::FILE*, char> FPrintf(std::FILE* f, const std::string& format) {
|
||||||
return PrintfState<std::FILE*, char>(f, format.c_str());
|
::std::string buffer;
|
||||||
|
const PrintfState< ::std::string &, char > state1( buffer, format.c_str() );
|
||||||
|
::std::fwrite( buffer.c_str(), 1, buffer.size(), f );
|
||||||
|
PrintfState< std::FILE *, char > printState2 = state1.ChangeDevice( f );
|
||||||
|
return printState2;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintfState<std::ostream&, char> FPrintf(std::ostream& f, const char* format) {
|
PrintfState<std::ostream&, char> FPrintf(std::ostream& f, const char* format) {
|
||||||
return PrintfState<std::ostream&, char>(f, format);
|
::std::string buffer;
|
||||||
|
const PrintfState< ::std::string &, char > state1( buffer, format );
|
||||||
|
f.write( buffer.c_str(), buffer.size() );
|
||||||
|
PrintfState< ::std::ostream &, char > printState2 = state1.ChangeDevice< ::std::ostream & >( f );
|
||||||
|
return printState2;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintfState<std::ostream&, char> FPrintf(std::ostream& f, const std::string& format) {
|
PrintfState<std::ostream&, char> FPrintf(std::ostream& f, const std::string& format) {
|
||||||
return PrintfState<std::ostream&, char>(f, format.c_str());
|
::std::string buffer;
|
||||||
|
const PrintfState< ::std::string &, char > state1( buffer, format.c_str() );
|
||||||
|
f.write( buffer.c_str(), buffer.size() );
|
||||||
|
PrintfState< std::ostream &, char > printState2 = state1.ChangeDevice< ::std::ostream & >( f );
|
||||||
|
return printState2;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintfState<std::string&, char> SPrintf(std::string& s, const char* format) {
|
PrintfState<std::string&, char> SPrintf(std::string& s, const char* format) {
|
||||||
|
|
Loading…
Reference in a new issue