|
From: <ric...@us...> - 2011-10-04 23:42:54
|
Revision: 1138
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1138&view=rev
Author: rich_sposato
Date: 2011-10-04 23:42:48 +0000 (Tue, 04 Oct 2011)
Log Message:
-----------
Fixed bug 2694067.
Modified Paths:
--------------
trunk/include/loki/SafeFormat.h
trunk/src/SafeFormat.cpp
Modified: trunk/include/loki/SafeFormat.h
===================================================================
--- trunk/include/loki/SafeFormat.h 2011-10-04 20:48:36 UTC (rev 1137)
+++ trunk/include/loki/SafeFormat.h 2011-10-04 23:42:48 UTC (rev 1138)
@@ -100,6 +100,21 @@
template <class Device, class Char>
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)
: device_(dev)
, format_(format)
@@ -113,6 +128,15 @@
~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) \
PrintfState& operator()(type par) {\
return (*this)(static_cast< LOKI_SAFEFORMAT_UNSIGNED_LONG >(par)); \
Modified: trunk/src/SafeFormat.cpp
===================================================================
--- trunk/src/SafeFormat.cpp 2011-10-04 20:48:36 UTC (rev 1137)
+++ trunk/src/SafeFormat.cpp 2011-10-04 23:42:48 UTC (rev 1138)
@@ -66,27 +66,51 @@
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) {
- 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) {
- 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) {
- 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) {
- 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) {
- 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) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|