//////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2005 by Andrei Alexandrescu // Copyright (c) 2006 Peter Kümmel // Permission to use, copy, modify, distribute, and sell this software for any // purpose is hereby granted without fee, provided that the above copyright // notice appear in all copies and that both that copyright notice and this // permission notice appear in supporting documentation. // The author makes no representations about the suitability of this software // for any purpose. It is provided "as is" without express or implied // warranty. //////////////////////////////////////////////////////////////////////////////// // $Header: /diskb/tmp/stefano/project2/CVS/ACS/LGPL/Tools/loki/ws/src/lokiSafeFormat.cpp,v 1.2 2007/02/01 17:29:01 sharring Exp $ #include namespace Loki { // Crude writing method: writes straight to the file, unbuffered // Must be combined with a buffer to work properly (and efficiently) void write(std::FILE* f, const char* from, const char* to) { assert(from <= to); fwrite(from, 1, to - from, f); } // Write to a string void write(std::string& s, const char* from, const char* to) { assert(from <= to); s.append(from, to); } //////////////////////////////////////////////////////////////////////////////// // PrintfState class template // Holds the formatting state, and implements operator() to format stuff // Todo: make sure errors are handled properly //////////////////////////////////////////////////////////////////////////////// PrintfState Printf(const char* format) { return PrintfState(stdout, format); } PrintfState Printf(const std::string format) { return PrintfState(stdout, format.c_str()); } PrintfState FPrintf(FILE* f, const char* format) { return PrintfState(f, format); } PrintfState FPrintf(FILE* f, const std::string& format) { return PrintfState(f, format.c_str()); } PrintfState SPrintf(std::string& s, const char* format) { return PrintfState(s, format); } PrintfState SPrintf(std::string& s, const std::string& format) { return PrintfState(s, format.c_str()); } }// namespace Loki // $Log: lokiSafeFormat.cpp,v $ // Revision 1.2 2007/02/01 17:29:01 sharring // updating to newer version of loki library, with support for multi-threading enabled. manually renamed files to avoid name conflicts, by // prepending "loki" to the names of header files. also manually edited lokiThreads.h to #define LOKI_OBJECT_LEVEL_THREADING; this could // also be done with a compile FLAG, perhaps would be better. // // Revision 1.1.2.1 2007/02/01 07:36:57 sharring // // updating loki to newer version for testing in SFI in the hopes of fixing some // multi-threading problems seen in acs logging code for which the stack trace // indicates that loki smart pointers were involved. // // Revision 1.2 2006/01/16 20:59:53 rich_sposato // Added cvs keywords. //