]> git.cworth.org Git - apitrace/blob - trace_model.hpp
Show call name on glGetError warning messages.
[apitrace] / trace_model.hpp
1 /**************************************************************************
2  *
3  * Copyright 2010 VMware, Inc.
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  *
24  **************************************************************************/
25
26 /*
27  * Object hierarchy for describing the traces in memory.
28  */
29
30 #ifndef _TRACE_MODEL_HPP_
31 #define _TRACE_MODEL_HPP_
32
33
34 #include <cassert>
35
36 #include <string>
37 #include <map>
38 #include <list>
39 #include <vector>
40 #include <iostream>
41
42
43 namespace Trace {
44
45
46 class Visitor;
47 class Dumper;
48 class UInt;
49
50
51 class Value
52 {
53 public:
54     virtual ~Value() {}
55     virtual void visit(Visitor &visitor) = 0;
56
57     virtual bool toBool(void) const = 0;
58     virtual signed long long toSInt(void) const;
59     virtual unsigned long long toUInt(void) const;
60     virtual float toFloat(void) const;
61     virtual double toDouble(void) const;
62
63     virtual void *toPointer(void) const;
64     virtual unsigned long long toUIntPtr(void) const;
65     virtual const char *toString(void) const;
66
67     const Value & operator[](size_t index) const;
68 };
69
70
71 class Null : public Value
72 {
73 public:
74     bool toBool(void) const;
75     signed long long toSInt(void) const;
76     unsigned long long toUInt(void) const;
77     virtual float toFloat(void) const;
78     virtual double toDouble(void) const;
79     void *toPointer(void) const;
80     unsigned long long toUIntPtr(void) const;
81     const char *toString(void) const;
82     void visit(Visitor &visitor);
83 };
84
85
86 class Bool : public Value
87 {
88 public:
89     Bool(bool _value) : value(_value) {}
90
91     bool toBool(void) const;
92     signed long long toSInt(void) const;
93     unsigned long long toUInt(void) const;
94     virtual float toFloat(void) const;
95     virtual double toDouble(void) const;
96     void visit(Visitor &visitor);
97
98     bool value;
99 };
100
101
102 class SInt : public Value
103 {
104 public:
105     SInt(signed long long _value) : value(_value) {}
106
107     bool toBool(void) const;
108     signed long long toSInt(void) const;
109     unsigned long long toUInt(void) const;
110     virtual float toFloat(void) const;
111     virtual double toDouble(void) const;
112     void visit(Visitor &visitor);
113
114     signed long long value;
115 };
116
117
118 class UInt : public Value
119 {
120 public:
121     UInt(unsigned long long _value) : value(_value) {}
122
123     bool toBool(void) const;
124     signed long long toSInt(void) const;
125     unsigned long long toUInt(void) const;
126     virtual float toFloat(void) const;
127     virtual double toDouble(void) const;
128     void visit(Visitor &visitor);
129
130     unsigned long long value;
131 };
132
133
134 class Float : public Value
135 {
136 public:
137     Float(double _value) : value(_value) {}
138
139     bool toBool(void) const;
140     signed long long toSInt(void) const;
141     unsigned long long toUInt(void) const;
142     virtual float toFloat(void) const;
143     virtual double toDouble(void) const;
144     void visit(Visitor &visitor);
145
146     double value;
147 };
148
149
150 class String : public Value
151 {
152 public:
153     String(std::string _value) : value(_value) {}
154
155     bool toBool(void) const;
156     const char *toString(void) const;
157     void visit(Visitor &visitor);
158
159     std::string value;
160 };
161
162
163 class Enum : public Value
164 {
165 public:
166     struct Signature : public std::pair<std::string, Value *>
167     {
168         Signature()
169             : std::pair<std::string, Value *>()
170         {}
171         Signature(const std::string &n, Trace::Value *val)
172             : std::pair<std::string, Value *>(n, val)
173         {}
174         ~Signature()
175         {
176             delete second;
177         }
178     };
179
180     Enum(const Signature *_sig) : sig(_sig) {}
181
182     bool toBool(void) const;
183     signed long long toSInt(void) const;
184     unsigned long long toUInt(void) const;
185     virtual float toFloat(void) const;
186     virtual double toDouble(void) const;
187     void visit(Visitor &visitor);
188
189     const Signature *sig;
190 };
191
192
193 class Bitmask : public UInt
194 {
195 public:
196     typedef std::pair<std::string, unsigned long long> Pair;
197     typedef std::vector<Pair> Signature;
198
199     Bitmask(const Signature *_sig, unsigned long long _value) : UInt(_value), sig(_sig) {}
200
201     void visit(Visitor &visitor);
202
203     const Signature *sig;
204 };
205
206
207 class Struct : public Value
208 {
209 public:
210     struct Signature {
211         std::string name;
212         std::vector<std::string> member_names;
213     };
214
215     Struct(Signature *_sig) : sig(_sig), members(_sig->member_names.size()) { }
216     ~Struct();
217
218     bool toBool(void) const;
219     void visit(Visitor &visitor);
220
221     const Signature *sig;
222     std::vector<Value *> members;
223 };
224
225
226 class Array : public Value
227 {
228 public:
229     Array(size_t len) : values(len) {}
230     ~Array();
231
232     bool toBool(void) const;
233     void visit(Visitor &visitor);
234
235     std::vector<Value *> values;
236 };
237
238
239 class Blob : public Value
240 {
241 public:
242     Blob(size_t _size) {
243         size = _size;
244         buf = new char[_size];
245     }
246
247     ~Blob();
248
249     bool toBool(void) const;
250     void *toPointer(void) const;
251     void visit(Visitor &visitor);
252
253     size_t size;
254     char *buf;
255 };
256
257
258 class Pointer : public UInt
259 {
260 public:
261     Pointer(unsigned long long value) : UInt(value) {}
262
263     bool toBool(void) const;
264     void *toPointer(void) const;
265     unsigned long long toUIntPtr(void) const;
266     void visit(Visitor &visitor);
267 };
268
269
270 class Visitor
271 {
272 public:
273     virtual void visit(Null *);
274     virtual void visit(Bool *);
275     virtual void visit(SInt *);
276     virtual void visit(UInt *);
277     virtual void visit(Float *);
278     virtual void visit(String *);
279     virtual void visit(Enum *);
280     virtual void visit(Bitmask *);
281     virtual void visit(Struct *);
282     virtual void visit(Array *);
283     virtual void visit(Blob *);
284     virtual void visit(Pointer *);
285
286 protected:
287     inline void _visit(Value *value) {
288         if (value) { 
289             value->visit(*this); 
290         }
291     }
292 };
293
294
295 std::ostream & operator <<(std::ostream &os, Value *value);
296
297
298 class Call
299 {
300 public:
301     struct Signature {
302         std::string name;
303         std::vector<std::string> arg_names;
304     };
305
306     unsigned no;
307     const Signature *sig;
308     std::vector<Value *> args;
309     Value *ret;
310
311     Call(Signature *_sig) : sig(_sig), args(_sig->arg_names.size()), ret(0) { }
312     ~Call();
313
314     inline const std::string & name(void) const {
315         return sig->name;
316     }
317
318     inline Value & arg(unsigned index) {
319         return *(args[index]);
320     }
321 };
322
323
324 std::ostream & operator <<(std::ostream &os, Call &call);
325
326
327 } /* namespace Trace */
328
329 #endif /* _TRACE_MODEL_HPP_ */