diff --git a/include/loki/SafeFormat.h b/include/loki/SafeFormat.h index f0c1867..5ec7860 100755 --- a/include/loki/SafeFormat.h +++ b/include/loki/SafeFormat.h @@ -27,6 +27,7 @@ #include #include #include +#include #include @@ -52,6 +53,9 @@ namespace Loki LOKI_EXPORT void write(std::FILE* f, const char* from, const char* to); + // Write to an ostream + LOKI_EXPORT + void write(std::ostream& f, const char* from, const char* to); // Write to a string LOKI_EXPORT @@ -539,7 +543,7 @@ namespace Loki PrintfState Printf(const char* format); LOKI_EXPORT - PrintfState Printf(const std::string format); + PrintfState Printf(const std::string& format); LOKI_EXPORT PrintfState FPrintf(std::FILE* f, const char* format); @@ -547,6 +551,12 @@ namespace Loki LOKI_EXPORT PrintfState FPrintf(std::FILE* f, const std::string& format); + LOKI_EXPORT + PrintfState FPrintf(std::ostream& f, const char* format); + + LOKI_EXPORT + PrintfState FPrintf(std::ostream& f, const std::string& format); + LOKI_EXPORT PrintfState SPrintf(std::string& s, const char* format); @@ -576,6 +586,9 @@ namespace Loki #endif //SAFEFORMAT_H_ // $Log$ +// Revision 1.28 2006/07/06 18:25:28 syntheticpp +// add writing to ostream, by Tom Browder +// // Revision 1.27 2006/07/03 09:55:19 syntheticpp // fix wrong buffer size check // diff --git a/src/SafeFormat.cpp b/src/SafeFormat.cpp index f14d27e..1a28cd9 100755 --- a/src/SafeFormat.cpp +++ b/src/SafeFormat.cpp @@ -32,8 +32,13 @@ namespace Loki assert(from <= to); s.append(from, to); } - + // Write to a stream + + void write(std::ostream& f, const char* from, const char* to) { + assert(from <= to); + f.write(from, to - from); + } //////////////////////////////////////////////////////////////////////////////// // PrintfState class template @@ -46,7 +51,7 @@ namespace Loki return PrintfState(stdout, format); } - PrintfState Printf(const std::string format) { + PrintfState Printf(const std::string& format) { return PrintfState(stdout, format.c_str()); } @@ -58,6 +63,14 @@ namespace Loki return PrintfState(f, format.c_str()); } + PrintfState FPrintf(std::ostream& f, const char* format) { + return PrintfState(f, format); + } + + PrintfState FPrintf(std::ostream& f, const std::string& format) { + return PrintfState(f, format.c_str()); + } + PrintfState SPrintf(std::string& s, const char* format) { return PrintfState(s, format); } @@ -70,6 +83,9 @@ namespace Loki }// namespace Loki // $Log$ +// Revision 1.4 2006/07/06 18:25:28 syntheticpp +// add writing to ostream, by Tom Browder +// // Revision 1.3 2006/06/28 08:04:21 syntheticpp // use standard conforming naming, SUN's compiler needs it //