~ubuntu-branches/ubuntu/quantal/mesa/quantal

« back to all changes in this revision

Viewing changes to src/mesa/shader/slang/Include/InfoSink.h

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-02-21 12:44:07 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20070221124407-rgcacs32mycrtadl
ImportĀ upstreamĀ versionĀ 6.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 <math.h>
40
 
 
41
 
//
42
 
// TPrefixType is used to centralize how info log messages start.
43
 
// See below.
44
 
//
45
 
enum TPrefixType {
46
 
    EPrefixNone,
47
 
    EPrefixWarning,
48
 
    EPrefixError,
49
 
    EPrefixInternalError,
50
 
    EPrefixUnimplemented
51
 
};
52
 
 
53
 
enum TOutputStream {
54
 
    ENull = 0,
55
 
    EDebugger = 0x01,
56
 
    EStdOut = 0x02,
57
 
    EString = 0x04
58
 
};
59
 
//
60
 
// Encapsulate info logs for all objects that have them.
61
 
//
62
 
// The methods are a general set of tools for getting a variety of
63
 
// messages and types inserted into the log.
64
 
//
65
 
class TInfoSinkBase {
66
 
public:
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 ?
76
 
                                                             "%f" : "%g", n);
77
 
                                                     append(buf); 
78
 
                                                     return *this; }
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) {
85
 
        switch(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;
92
 
        }
93
 
    }
94
 
    void location(TSourceLoc loc) {
95
 
        append(FormatSourceLoc(loc).c_str());
96
 
        append(": ");
97
 
    }
98
 
    void message(TPrefixType message, const char* s) {
99
 
        prefix(message);
100
 
        append(s);
101
 
        append("\n");
102
 
    }
103
 
    void message(TPrefixType message, const char* s, TSourceLoc loc) {
104
 
        prefix(message);
105
 
        location(loc);
106
 
        append(s);
107
 
        append("\n");
108
 
    }
109
 
    
110
 
    void setOutputStream(int output = 4)
111
 
    {
112
 
        outputStream = output;
113
 
    }
114
 
 
115
 
protected:
116
 
    void append(const char *s); 
117
 
 
118
 
    void append(int count, char c);
119
 
    void append(const TPersistString& t);
120
 
    void append(const TString& t);
121
 
 
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);
125
 
    TPersistString sink;
126
 
    int outputStream;
127
 
};
128
 
 
129
 
class TInfoSink {
130
 
public:
131
 
    TInfoSinkBase info;
132
 
    TInfoSinkBase debug;
133
 
};
134
 
 
135
 
#endif // _INFOSINK_INCLUDED_