RetroArch
InfoSink.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions
7 // are met:
8 //
9 // Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
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.
16 //
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.
20 //
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.
33 //
34 
35 #ifndef _INFOSINK_INCLUDED_
36 #define _INFOSINK_INCLUDED_
37 
38 #include "../Include/Common.h"
39 #include <cmath>
40 
41 namespace glslang {
42 
43 //
44 // TPrefixType is used to centralize how info log messages start.
45 // See below.
46 //
54 };
55 
57  ENull = 0,
58  EDebugger = 0x01,
59  EStdOut = 0x02,
60  EString = 0x04,
61 };
62 //
63 // Encapsulate info logs for all objects that have them.
64 //
65 // The methods are a general set of tools for getting a variety of
66 // messages and types inserted into the log.
67 //
69 public:
71  void erase() { sink.erase(); }
72  TInfoSinkBase& operator<<(const TPersistString& t) { append(t); return *this; }
73  TInfoSinkBase& operator<<(char c) { append(1, c); return *this; }
74  TInfoSinkBase& operator<<(const char* s) { append(s); return *this; }
75  TInfoSinkBase& operator<<(int n) { append(String(n)); return *this; }
76  TInfoSinkBase& operator<<(unsigned int n) { append(String(n)); return *this; }
77  TInfoSinkBase& operator<<(float n) { const int size = 40; char buf[size];
78  snprintf(buf, size, (fabs(n) > 1e-8 && fabs(n) < 1e8) || n == 0.0f ? "%f" : "%g", n);
79  append(buf);
80  return *this; }
81  TInfoSinkBase& operator+(const TPersistString& t) { append(t); return *this; }
82  TInfoSinkBase& operator+(const TString& t) { append(t); return *this; }
83  TInfoSinkBase& operator<<(const TString& t) { append(t); return *this; }
84  TInfoSinkBase& operator+(const char* s) { append(s); return *this; }
85  const char* c_str() const { return sink.c_str(); }
87  switch(message) {
88  case EPrefixNone: break;
89  case EPrefixWarning: append("WARNING: "); break;
90  case EPrefixError: append("ERROR: "); break;
91  case EPrefixInternalError: append("INTERNAL ERROR: "); break;
92  case EPrefixUnimplemented: append("UNIMPLEMENTED: "); break;
93  case EPrefixNote: append("NOTE: "); break;
94  default: append("UNKNOWN ERROR: "); break;
95  }
96  }
97  void location(const TSourceLoc& loc) {
98  const int maxSize = 24;
99  char locText[maxSize];
100  snprintf(locText, maxSize, ":%d", loc.line);
101  append(loc.getStringNameOrNum(false).c_str());
102  append(locText);
103  append(": ");
104  }
105  void message(TPrefixType message, const char* s) {
106  prefix(message);
107  append(s);
108  append("\n");
109  }
110  void message(TPrefixType message, const char* s, const TSourceLoc& loc) {
111  prefix(message);
112  location(loc);
113  append(s);
114  append("\n");
115  }
116 
117  void setOutputStream(int output = 4)
118  {
120  }
121 
122 protected:
123  void append(const char* s);
124 
125  void append(int count, char c);
126  void append(const TPersistString& t);
127  void append(const TString& t);
128 
129  void checkMem(size_t growth) { if (sink.capacity() < sink.size() + growth + 2)
130  sink.reserve(sink.capacity() + sink.capacity() / 2); }
131  void appendToStream(const char* s);
134 };
135 
136 } // end namespace glslang
137 
138 class TInfoSink {
139 public:
142 };
143 
144 #endif // _INFOSINK_INCLUDED_
Definition: InfoSink.h:50
void location(const TSourceLoc &loc)
Definition: InfoSink.h:97
static size_t maxSize(size_t a, size_t b)
Definition: compat_ifaddrs.c:225
void erase()
Definition: InfoSink.h:71
TInfoSinkBase & operator+(const TPersistString &t)
Definition: InfoSink.h:81
Definition: InfoSink.h:48
std::string getStringNameOrNum(bool quoteStringName=true) const
Definition: Common.h:235
Definition: InfoSink.h:60
void message(TPrefixType message, const char *s, const TSourceLoc &loc)
Definition: InfoSink.h:110
TInfoSinkBase & operator<<(const TPersistString &t)
Definition: InfoSink.h:72
Definition: InfoSink.h:59
Definition: InfoSink.h:138
Definition: Common.h:231
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:8418
int line
Definition: Common.h:243
GLdouble GLdouble t
Definition: glext.h:6398
GLsizeiptr size
Definition: glext.h:6559
GLfloat f
Definition: glext.h:8207
void checkMem(size_t growth)
Definition: InfoSink.h:129
Definition: InfoSink.h:68
GLdouble s
Definition: glext.h:6390
TInfoSinkBase & operator<<(float n)
Definition: InfoSink.h:77
void setOutputStream(int output=4)
Definition: InfoSink.h:117
void appendToStream(const char *s)
std::basic_string< char > TPersistString
Definition: Common.h:201
void append(const char *s)
Definition: InfoSink.cpp:41
TPersistString sink
Definition: InfoSink.h:132
void message(TPrefixType message, const char *s)
Definition: InfoSink.h:105
TInfoSinkBase & operator<<(const TString &t)
Definition: InfoSink.h:83
Definition: InfoSink.h:57
const GLubyte * c
Definition: glext.h:9812
GLuint GLuint GLsizei count
Definition: glext.h:6292
#define fabs(x)
Definition: math.h:27
glslang::TInfoSinkBase info
Definition: InfoSink.h:140
int outputStream
Definition: InfoSink.h:133
const char * c_str() const
Definition: InfoSink.h:85
GLsizei GLenum GLboolean sink
Definition: glext.h:6324
TInfoSinkBase & operator<<(int n)
Definition: InfoSink.h:75
TInfoSinkBase & operator<<(unsigned int n)
Definition: InfoSink.h:76
void prefix(TPrefixType message)
Definition: InfoSink.h:86
TOutputStream
Definition: InfoSink.h:56
TPrefixType
Definition: InfoSink.h:47
Definition: InfoSink.h:52
Definition: InfoSink.h:49
GLenum GLuint GLenum GLsizei const GLchar * message
Definition: glext.h:6233
glslang::TInfoSinkBase debug
Definition: InfoSink.h:141
Definition: InfoSink.h:51
TInfoSinkBase()
Definition: InfoSink.h:70
TInfoSinkBase & operator<<(char c)
Definition: InfoSink.h:73
Definition: arrays.h:46
TInfoSinkBase & operator+(const char *s)
Definition: InfoSink.h:84
std::string output
Definition: Config.FromFile.cpp:44
Definition: InfoSink.h:58
TInfoSinkBase & operator+(const TString &t)
Definition: InfoSink.h:82
const TString String(const int i, const int=10)
Definition: Common.h:220
TInfoSinkBase & operator<<(const char *s)
Definition: InfoSink.h:74
GLdouble n
Definition: glext.h:8396
Definition: InfoSink.h:53
Definition: lobject.h:303