make SafeFormat linkable
git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@465 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
parent
44f7af2935
commit
2f9d9a21d0
5 changed files with 106 additions and 54 deletions
|
@ -314,6 +314,10 @@
|
|||
RelativePath=".\OrderedStatic.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\SafeFormat.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Singleton.cpp"
|
||||
>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
OBJ = Singleton.o SmallObj.o OrderedStatic.o
|
||||
OBJ = Singleton.o SmallObj.o OrderedStatic.o SafeFormat.o
|
||||
BIN = ../lib/libloki.a
|
||||
CXXFLAGS = -Wall -O2
|
||||
CPPFLAGS = -I../include -DNDEBUG
|
||||
|
|
70
src/SafeFormat.cpp
Executable file
70
src/SafeFormat.cpp
Executable file
|
@ -0,0 +1,70 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#include <loki/SafeFormat.h>
|
||||
|
||||
|
||||
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<std::FILE*, char> Printf(const char* format) {
|
||||
return PrintfState<std::FILE*, char>(stdout, format);
|
||||
}
|
||||
|
||||
PrintfState<std::FILE*, char> Printf(const std::string format) {
|
||||
return PrintfState<std::FILE*, char>(stdout, format.c_str());
|
||||
}
|
||||
|
||||
PrintfState<std::FILE*, char> FPrintf(FILE* f, const char* format) {
|
||||
return PrintfState<std::FILE*, char>(f, format);
|
||||
}
|
||||
|
||||
PrintfState<std::FILE*, char> FPrintf(FILE* f, const std::string& format) {
|
||||
return PrintfState<std::FILE*, char>(f, format.c_str());
|
||||
}
|
||||
|
||||
PrintfState<std::string&, char> SPrintf(std::string& s, const char* format) {
|
||||
return PrintfState<std::string&, char>(s, format);
|
||||
}
|
||||
|
||||
PrintfState<std::string&, char> SPrintf(std::string& s, const std::string& format) {
|
||||
return PrintfState<std::string&, char>(s, format.c_str());
|
||||
}
|
||||
|
||||
|
||||
}// namespace Loki
|
||||
|
|
@ -2,7 +2,7 @@ if not exist ..\lib\ mkdir ..\lib
|
|||
|
||||
if not exist tmp\ mkdir tmp
|
||||
|
||||
cl -c -Zm200 -O2 -DNDEBUG -MT -EHsc -GR -W4 -I"." -I"..\include" -Fo.\tmp\ SmallObj.cpp Singleton.cpp OrderedStatic.cpp
|
||||
cl -c -Zm200 -O2 -DNDEBUG -MT -EHsc -GR -W4 -I"." -I"..\include" -Fo.\tmp\ SmallObj.cpp Singleton.cpp OrderedStatic.cpp SafeFormat.cpp
|
||||
|
||||
link /lib /NOLOGO /OUT:"..\lib\loki.lib" tmp\SmallObj.obj tmp\Singleton.obj tmp\OrderedStatic.obj
|
||||
link /lib /NOLOGO /OUT:"..\lib\loki.lib" tmp\SmallObj.obj tmp\Singleton.obj tmp\OrderedStatic.obj tmp\SafeFormat.obj
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue