]> git.cworth.org Git - apitrace/blob - trace_model.hpp
Support glTexImage through blobs.
[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 #ifndef _TRACE_MODEL_HPP_
27 #define _TRACE_MODEL_HPP_
28
29
30 #include <cassert>
31
32 #include <string>
33 #include <map>
34 #include <list>
35 #include <vector>
36 #include <iostream>
37
38
39 namespace Trace {
40
41
42 class Visitor;
43 class Dumper;
44 class UInt;
45
46
47 class Value
48 {
49 public:
50    virtual void visit(Visitor &visitor) = 0;
51
52    operator signed long long (void) const;
53    operator unsigned long long (void) const;
54    operator double (void) const;
55    operator void * (void) const;
56
57    inline operator signed char (void) const { 
58       return static_cast<signed long long>(*this);
59    }
60
61    inline operator unsigned char (void) const { 
62       return static_cast<signed long long>(*this);
63    }
64
65    inline operator signed short (void) const { 
66       return static_cast<signed long long>(*this);
67    }
68
69    inline operator unsigned short (void) const { 
70       return static_cast<unsigned long long>(*this);
71    }
72
73    inline operator signed (void) const { 
74       return static_cast<signed long long>(*this);
75    }
76
77    inline operator unsigned (void) const { 
78       return static_cast<unsigned long long>(*this);
79    }
80
81    inline operator signed long (void) const { 
82       return static_cast<signed long long>(*this);
83    }
84
85    inline operator unsigned long (void) const { 
86       return static_cast<unsigned long long>(*this);
87    }
88
89    inline operator float (void) const { 
90       return static_cast<double>(*this);
91    }
92
93    const Value & operator[](size_t index) const;
94 };
95
96
97 class Void : public Value
98 {
99 public:
100    void visit(Visitor &visitor);
101 };
102
103
104 class Bool : public Value
105 {
106 public:
107    Bool(bool _value) : value(_value) {}
108
109    void visit(Visitor &visitor);
110
111    bool value;
112 };
113
114
115 class SInt : public Value
116 {
117 public:
118    SInt(signed long long _value) : value(_value) {}
119
120    void visit(Visitor &visitor);
121
122    signed long long value;
123 };
124
125
126 class UInt : public Value
127 {
128 public:
129    UInt(unsigned long long _value) : value(_value) {}
130
131    void visit(Visitor &visitor);
132
133    unsigned long long value;
134 };
135
136
137 class Float : public Value
138 {
139 public:
140    Float(double _value) : value(_value) {}
141
142    void visit(Visitor &visitor);
143
144    double value;
145 };
146
147
148 class String : public Value
149 {
150 public:
151    String(std::string _value) : value(_value) {}
152
153    void visit(Visitor &visitor);
154
155    std::string value;
156 };
157
158
159 class Const : public Value
160 {
161 public:
162    Const(std::string _name, Value *_value) : name(_name), value(_value) {}
163
164    void visit(Visitor &visitor);
165
166    std::string name;
167    Value *value;
168 };
169
170
171 class Array : public Value
172 {
173 public:
174    Array(size_t len) : values(len) {}
175
176    void visit(Visitor &visitor);
177
178    std::vector<Value *> values;
179 };
180
181
182 class Blob : public Value
183 {
184 public:
185    Blob(size_t _size) {
186        size = size;
187        buf = new char[_size];
188    }
189
190    ~Blob() {
191        delete [] buf;
192    }
193
194    void visit(Visitor &visitor);
195
196    size_t size;
197    char *buf;
198 };
199
200
201 class Visitor
202 {
203 public:
204    virtual void visit(Void *) {assert(0);}
205    virtual void visit(Bool *) {assert(0);}
206    virtual void visit(SInt *) {assert(0);}
207    virtual void visit(UInt *) {assert(0);}
208    virtual void visit(Float *) {assert(0);}
209    virtual void visit(String *) {assert(0);}
210    virtual void visit(Const *) {assert(0);}
211    virtual void visit(Array *) {assert(0);}
212    virtual void visit(Blob *) {assert(0);}
213 };
214
215
216 std::ostream & operator <<(std::ostream &os, Value *value);
217
218
219 signed long long asSInt(const Value &node);
220 unsigned long long asUInt(const Value &node);
221 double asFloat(const Value &node);
222
223
224 typedef std::pair<std::string, Value *> Arg;
225
226 class Call
227 {
228 public:
229    std::string name;
230    std::list<Arg> args;
231    Value *ret;
232
233    Call() : ret(0) { }
234
235    Value & arg(const char *name);
236 };
237
238
239
240 std::ostream & operator <<(std::ostream &os, Call &call);
241
242
243 } /* namespace Trace */
244
245 #endif /* _TRACE_MODEL_HPP_ */