From 62d74d47f8454fa3982f42e2fc5cc7602ecbbe5b Mon Sep 17 00:00:00 2001 From: rich_sposato Date: Fri, 21 Oct 2011 23:09:48 +0000 Subject: [PATCH] Added functions that print directly to cout. git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@1160 7ec92016-0320-0410-acc4-a06ded1c099a --- include/loki/SafeFormat.h | 8 ++++++++ src/SafeFormat.cpp | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/loki/SafeFormat.h b/include/loki/SafeFormat.h index 7fd211b..5c4919e 100644 --- a/include/loki/SafeFormat.h +++ b/include/loki/SafeFormat.h @@ -605,6 +605,14 @@ namespace Loki LOKI_EXPORT PrintfState FPrintf(std::FILE* f, const std::string& format); + /// Prints to cout. + LOKI_EXPORT + PrintfState FPrintf( const char * format ); + + /// Prints to cout. + LOKI_EXPORT + PrintfState FPrintf( const std::string & format ); + LOKI_EXPORT PrintfState FPrintf(std::ostream& f, const char* format); diff --git a/src/SafeFormat.cpp b/src/SafeFormat.cpp index 5c26acf..865b9a4 100644 --- a/src/SafeFormat.cpp +++ b/src/SafeFormat.cpp @@ -99,6 +99,22 @@ namespace Loki return printState2; } + PrintfState< std::ostream &, char > FPrintf( const char * format ) { + ::std::string buffer; + const PrintfState< ::std::string &, char > state1( buffer, format ); + ::std::cout << buffer.c_str(); + PrintfState< ::std::ostream &, char > printState2 = state1.ChangeDevice< ::std::ostream & >( ::std::cout ); + return printState2; + } + + PrintfState< std::ostream &, char > FPrintf( const std::string & format ) { + ::std::string buffer; + const PrintfState< ::std::string &, char > state1( buffer, format.c_str() ); + ::std::cout << buffer.c_str(); + PrintfState< std::ostream &, char > printState2 = state1.ChangeDevice< ::std::ostream & >( ::std::cout ); + return printState2; + } + PrintfState FPrintf(std::ostream& f, const char* format) { ::std::string buffer; const PrintfState< ::std::string &, char > state1( buffer, format );