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.
61 // Encapsulate info logs for all objects that have them.
63 // The methods are a general set of tools for getting a variety of
64 // messages and types inserted into the log.
68 TInfoSinkBase() : outputStream(4) {}
69 void erase() { sink.erase(); }
70 TInfoSinkBase& operator<<(const TPersistString& t) { append(t); return *this; }
71 TInfoSinkBase& operator<<(char c) { append(1, c); return *this; }
72 TInfoSinkBase& operator<<(const char* s) { append(s); return *this; }
73 TInfoSinkBase& operator<<(int n) { append(String(n)); return *this; }
74 TInfoSinkBase& operator<<(const unsigned int n) { append(String(n)); return *this; }
75 TInfoSinkBase& operator<<(float n) { char buf[40];
76 sprintf(buf, (fabs(n) > 1e-8 && fabs(n) < 1e8) || n == 0.0f ?
80 TInfoSinkBase& operator+(const TPersistString& t) { append(t); return *this; }
81 TInfoSinkBase& operator+(const TString& t) { append(t); return *this; }
82 TInfoSinkBase& operator<<(const TString& t) { append(t); return *this; }
83 TInfoSinkBase& operator+(const char* s) { append(s); return *this; }
84 const char* c_str() const { return sink.c_str(); }
85 void prefix(TPrefixType message) {
87 case EPrefixNone: break;
88 case EPrefixWarning: append("WARNING: "); break;
89 case EPrefixError: append("ERROR: "); break;
90 case EPrefixInternalError: append("INTERNAL ERROR: "); break;
91 case EPrefixUnimplemented: append("UNIMPLEMENTED: "); break;
92 case EPrefixNote: append("NOTE: "); break;
93 default: append("UNKOWN ERROR: "); break;
96 void location(TSourceLoc loc) {
97 append(FormatSourceLoc(loc).c_str());
100 void message(TPrefixType message, const char* s) {
105 void message(TPrefixType message, const char* s, TSourceLoc loc) {
112 void setOutputStream(int output = 4)
114 outputStream = output;
118 void append(const char *s);
120 void append(int count, char c);
121 void append(const TPersistString& t);
122 void append(const TString& t);
124 void checkMem(size_t growth) { if (sink.capacity() < sink.size() + growth + 2)
125 sink.reserve(sink.capacity() + sink.capacity() / 2); }
126 void appendToStream(const char* s);
137 #endif // _INFOSINK_INCLUDED_