1 /**************************************************************************
3 * Copyright 2010 VMware, Inc.
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
24 **************************************************************************/
27 * Object hierarchy for describing the traces in memory.
30 #ifndef _TRACE_MODEL_HPP_
31 #define _TRACE_MODEL_HPP_
55 virtual void visit(Visitor &visitor) = 0;
57 operator bool (void) const;
58 operator signed long long (void) const;
59 operator unsigned long long (void) const;
60 operator double (void) const;
62 void *blob(void) const;
63 const char *string(void) const;
65 inline operator signed char (void) const {
66 return static_cast<signed long long>(*this);
69 inline operator unsigned char (void) const {
70 return static_cast<signed long long>(*this);
73 inline operator signed short (void) const {
74 return static_cast<signed long long>(*this);
77 inline operator unsigned short (void) const {
78 return static_cast<unsigned long long>(*this);
81 inline operator signed (void) const {
82 return static_cast<signed long long>(*this);
85 inline operator unsigned (void) const {
86 return static_cast<unsigned long long>(*this);
89 inline operator signed long (void) const {
90 return static_cast<signed long long>(*this);
93 inline operator unsigned long (void) const {
94 return static_cast<unsigned long long>(*this);
97 inline operator float (void) const {
98 return static_cast<double>(*this);
101 const Value & operator[](size_t index) const;
105 class Null : public Value
108 void visit(Visitor &visitor);
114 class Bool : public Value
117 Bool(bool _value) : value(_value) {}
119 void visit(Visitor &visitor);
125 class SInt : public Value
128 SInt(signed long long _value) : value(_value) {}
130 void visit(Visitor &visitor);
132 signed long long value;
136 class UInt : public Value
139 UInt(unsigned long long _value) : value(_value) {}
141 void visit(Visitor &visitor);
143 unsigned long long value;
147 class Float : public Value
150 Float(double _value) : value(_value) {}
152 void visit(Visitor &visitor);
158 class String : public Value
161 String(std::string _value) : value(_value) {}
163 void visit(Visitor &visitor);
169 class Enum : public Value
172 typedef std::pair<std::string, Value *> Signature;
174 Enum(const Signature *_sig) : sig(_sig) {}
176 void visit(Visitor &visitor);
178 const Signature *sig;
182 class Bitmask : public UInt
185 typedef std::pair<std::string, unsigned long long> Pair;
186 typedef std::vector<Pair> Signature;
188 Bitmask(const Signature *_sig, unsigned long long _value) : UInt(_value), sig(_sig) {}
190 void visit(Visitor &visitor);
192 const Signature *sig;
196 class Struct : public Value
201 std::vector<std::string> member_names;
204 Struct(Signature *_sig) : sig(_sig), members(_sig->member_names.size()) { }
207 void visit(Visitor &visitor);
209 const Signature *sig;
210 std::vector<Value *> members;
214 class Array : public Value
217 Array(size_t len) : values(len) {}
220 void visit(Visitor &visitor);
222 std::vector<Value *> values;
226 class Blob : public Value
231 buf = new char[_size];
236 void visit(Visitor &visitor);
243 class Pointer : public UInt
246 Pointer(unsigned long long value) : UInt(value) {}
248 void visit(Visitor &visitor);
255 virtual void visit(Null *);
256 virtual void visit(Bool *);
257 virtual void visit(SInt *);
258 virtual void visit(UInt *);
259 virtual void visit(Float *);
260 virtual void visit(String *);
261 virtual void visit(Enum *);
262 virtual void visit(Bitmask *);
263 virtual void visit(Struct *);
264 virtual void visit(Array *);
265 virtual void visit(Blob *);
266 virtual void visit(Pointer *);
269 inline void _visit(Value *value) {
277 std::ostream & operator <<(std::ostream &os, Value *value);
280 signed long long asSInt(const Value &node);
281 unsigned long long asUInt(const Value &node);
282 double asFloat(const Value &node);
290 std::vector<std::string> arg_names;
294 const Signature *sig;
295 std::vector<Value *> args;
298 Call(Signature *_sig) : sig(_sig), args(_sig->arg_names.size()), ret(0) { }
301 inline const std::string name(void) const {
305 inline Value & arg(unsigned index) {
306 return *(args[index]);
311 std::ostream & operator <<(std::ostream &os, Call &call);
314 } /* namespace Trace */
316 #endif /* _TRACE_MODEL_HPP_ */