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_
54 virtual void visit(Visitor &visitor) = 0;
56 operator bool (void) const;
57 operator signed long long (void) const;
58 operator unsigned long long (void) const;
59 operator double (void) const;
61 void *blob(void) const;
62 const char *string(void) const;
64 inline operator signed char (void) const {
65 return static_cast<signed long long>(*this);
68 inline operator unsigned char (void) const {
69 return static_cast<signed long long>(*this);
72 inline operator signed short (void) const {
73 return static_cast<signed long long>(*this);
76 inline operator unsigned short (void) const {
77 return static_cast<unsigned long long>(*this);
80 inline operator signed (void) const {
81 return static_cast<signed long long>(*this);
84 inline operator unsigned (void) const {
85 return static_cast<unsigned long long>(*this);
88 inline operator signed long (void) const {
89 return static_cast<signed long long>(*this);
92 inline operator unsigned long (void) const {
93 return static_cast<unsigned long long>(*this);
96 inline operator float (void) const {
97 return static_cast<double>(*this);
100 const Value & operator[](size_t index) const;
104 class Null : public Value
107 void visit(Visitor &visitor);
113 class Bool : public Value
116 Bool(bool _value) : value(_value) {}
118 void visit(Visitor &visitor);
124 class SInt : public Value
127 SInt(signed long long _value) : value(_value) {}
129 void visit(Visitor &visitor);
131 signed long long value;
135 class UInt : public Value
138 UInt(unsigned long long _value) : value(_value) {}
140 void visit(Visitor &visitor);
142 unsigned long long value;
146 class Float : public Value
149 Float(double _value) : value(_value) {}
151 void visit(Visitor &visitor);
157 class String : public Value
160 String(std::string _value) : value(_value) {}
162 void visit(Visitor &visitor);
168 class Enum : public Value
171 Enum(std::string &_name, Value *_value) : name(_name), value(_value) {}
173 void visit(Visitor &visitor);
180 class Bitmask : public UInt
183 typedef std::pair<std::string, unsigned long long> Pair;
184 typedef std::vector<Pair> Signature;
186 Bitmask(const Signature *_sig, unsigned long long _value) : UInt(_value), sig(_sig) {}
188 void visit(Visitor &visitor);
190 const Signature *sig;
194 class Struct : public Value
199 std::vector<std::string> member_names;
202 Struct(Signature *_sig) : sig(_sig), members(_sig->member_names.size()) { }
204 void visit(Visitor &visitor);
206 const Signature *sig;
207 std::vector<Value *> members;
211 class Array : public Value
214 Array(size_t len) : values(len) {}
216 void visit(Visitor &visitor);
218 std::vector<Value *> values;
222 class Blob : public Value
227 buf = new char[_size];
234 void visit(Visitor &visitor);
244 virtual void visit(Null *) {assert(0);}
245 virtual void visit(Bool *) {assert(0);}
246 virtual void visit(SInt *) {assert(0);}
247 virtual void visit(UInt *) {assert(0);}
248 virtual void visit(Float *) {assert(0);}
249 virtual void visit(String *) {assert(0);}
250 virtual void visit(Enum *) {assert(0);}
251 virtual void visit(Bitmask *bitmask) {visit(static_cast<UInt *>(bitmask));}
252 virtual void visit(Struct *) {assert(0);}
253 virtual void visit(Array *) {assert(0);}
254 virtual void visit(Blob *) {assert(0);}
257 inline void _visit(Value *value) {
265 std::ostream & operator <<(std::ostream &os, Value *value);
268 signed long long asSInt(const Value &node);
269 unsigned long long asUInt(const Value &node);
270 double asFloat(const Value &node);
278 std::vector<std::string> arg_names;
282 const Signature *sig;
283 std::vector<Value *> args;
286 Call(Signature *_sig) : sig(_sig), args(_sig->arg_names.size()), ret(0) { }
288 inline const std::string name(void) const {
292 inline Value & arg(unsigned index) {
293 return *(args[index]);
298 std::ostream & operator <<(std::ostream &os, Call &call);
301 } /* namespace Trace */
303 #endif /* _TRACE_MODEL_HPP_ */