2 // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
7 #ifndef _INFOSINK_INCLUDED_
8 #define _INFOSINK_INCLUDED_
13 // Returns the fractional part of the given floating-point number.
14 inline float fractionalPart(float f) {
16 return modff(f, &intPart);
20 // TPrefixType is used to centralize how info log messages start.
33 // Encapsulate info logs for all objects that have them.
35 // The methods are a general set of tools for getting a variety of
36 // messages and types inserted into the log.
43 TInfoSinkBase& operator<<(const T& t) {
44 TPersistStringStream stream;
46 sink.append(stream.str());
49 // Override << operator for specific types. It is faster to append strings
50 // and characters directly to the sink.
51 TInfoSinkBase& operator<<(char c) {
55 TInfoSinkBase& operator<<(const char* str) {
59 TInfoSinkBase& operator<<(const TPersistString& str) {
63 TInfoSinkBase& operator<<(const TString& str) {
64 sink.append(str.c_str());
67 // Make sure floats are written with correct precision.
68 TInfoSinkBase& operator<<(float f) {
69 // Make sure that at least one decimal point is written. If a number
70 // does not have a fractional part, the default precision format does
71 // not write the decimal portion which gets interpreted as integer by
73 TPersistStringStream stream;
74 if (fractionalPart(f) == 0.0f) {
76 stream << std::showpoint << std::fixed << f;
78 stream.unsetf(std::ios::fixed);
79 stream.unsetf(std::ios::scientific);
83 sink.append(stream.str());
86 // Write boolean values as their names instead of integral value.
87 TInfoSinkBase& operator<<(bool b) {
88 const char* str = b ? "true" : "false";
93 void erase() { sink.clear(); }
94 int size() { return static_cast<int>(sink.size()); }
96 const TPersistString& str() const { return sink; }
97 const char* c_str() const { return sink.c_str(); }
99 void prefix(TPrefixType message);
100 void location(TSourceLoc loc);
101 void message(TPrefixType message, const char* s);
102 void message(TPrefixType message, const char* s, TSourceLoc loc);
115 #endif // _INFOSINK_INCLUDED_