2
//Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
5
//Redistribution and use in source and binary forms, with or without
6
//modification, are permitted provided that the following conditions
9
// Redistributions of source code must retain the above copyright
10
// notice, this list of conditions and the following disclaimer.
12
// Redistributions in binary form must reproduce the above
13
// copyright notice, this list of conditions and the following
14
// disclaimer in the documentation and/or other materials provided
15
// with the distribution.
17
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
18
// contributors may be used to endorse or promote products derived
19
// from this software without specific prior written permission.
21
//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24
//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26
//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27
//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28
//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30
//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31
//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
//POSSIBILITY OF SUCH DAMAGE.
35
#ifndef _INFOSINK_INCLUDED_
36
#define _INFOSINK_INCLUDED_
38
#include "../Include/Common.h"
42
// TPrefixType is used to centralize how info log messages start.
60
// Encapsulate info logs for all objects that have them.
62
// The methods are a general set of tools for getting a variety of
63
// messages and types inserted into the log.
67
TInfoSinkBase() : outputStream(4) {}
68
void erase() { sink.erase(); }
69
TInfoSinkBase& operator<<(const TPersistString& t) { append(t); return *this; }
70
TInfoSinkBase& operator<<(char c) { append(1, c); return *this; }
71
TInfoSinkBase& operator<<(const char* s) { append(s); return *this; }
72
TInfoSinkBase& operator<<(int n) { append(String(n)); return *this; }
73
TInfoSinkBase& operator<<(const unsigned int n) { append(String(n)); return *this; }
74
TInfoSinkBase& operator<<(float n) { char buf[40];
75
sprintf(buf, (fabs(n) > 1e-8 && fabs(n) < 1e8) || n == 0.0f ?
79
TInfoSinkBase& operator+(const TPersistString& t) { append(t); return *this; }
80
TInfoSinkBase& operator+(const TString& t) { append(t); return *this; }
81
TInfoSinkBase& operator<<(const TString& t) { append(t); return *this; }
82
TInfoSinkBase& operator+(const char* s) { append(s); return *this; }
83
const char* c_str() const { return sink.c_str(); }
84
void prefix(TPrefixType message) {
86
case EPrefixNone: break;
87
case EPrefixWarning: append("WARNING: "); break;
88
case EPrefixError: append("ERROR: "); break;
89
case EPrefixInternalError: append("INTERNAL ERROR: "); break;
90
case EPrefixUnimplemented: append("UNIMPLEMENTED: "); break;
91
default: append("UNKOWN ERROR: "); break;
94
void location(TSourceLoc loc) {
95
append(FormatSourceLoc(loc).c_str());
98
void message(TPrefixType message, const char* s) {
103
void message(TPrefixType message, const char* s, TSourceLoc loc) {
110
void setOutputStream(int output = 4)
112
outputStream = output;
116
void append(const char *s);
118
void append(int count, char c);
119
void append(const TPersistString& t);
120
void append(const TString& t);
122
void checkMem(size_t growth) { if (sink.capacity() < sink.size() + growth + 2)
123
sink.reserve(sink.capacity() + sink.capacity() / 2); }
124
void appendToStream(const char* s);
135
#endif // _INFOSINK_INCLUDED_