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_
52 virtual void visit(Visitor &visitor) = 0;
54 virtual bool toBool(void) const = 0;
55 virtual signed long long toSInt(void) const;
56 virtual unsigned long long toUInt(void) const;
57 virtual float toFloat(void) const;
58 virtual double toDouble(void) const;
60 virtual void *toPointer(void) const;
61 virtual unsigned long long toUIntPtr(void) const;
62 virtual const char *toString(void) const;
64 const Value & operator[](size_t index) const;
68 class Null : public Value
71 bool toBool(void) const;
72 signed long long toSInt(void) const;
73 unsigned long long toUInt(void) const;
74 virtual float toFloat(void) const;
75 virtual double toDouble(void) const;
76 void *toPointer(void) const;
77 unsigned long long toUIntPtr(void) const;
78 const char *toString(void) const;
79 void visit(Visitor &visitor);
83 class Bool : public Value
86 Bool(bool _value) : value(_value) {}
88 bool toBool(void) const;
89 signed long long toSInt(void) const;
90 unsigned long long toUInt(void) const;
91 virtual float toFloat(void) const;
92 virtual double toDouble(void) const;
93 void visit(Visitor &visitor);
99 class SInt : public Value
102 SInt(signed long long _value) : value(_value) {}
104 bool toBool(void) const;
105 signed long long toSInt(void) const;
106 unsigned long long toUInt(void) const;
107 virtual float toFloat(void) const;
108 virtual double toDouble(void) const;
109 void visit(Visitor &visitor);
111 signed long long value;
115 class UInt : public Value
118 UInt(unsigned long long _value) : value(_value) {}
120 bool toBool(void) const;
121 signed long long toSInt(void) const;
122 unsigned long long toUInt(void) const;
123 virtual float toFloat(void) const;
124 virtual double toDouble(void) const;
125 void visit(Visitor &visitor);
127 unsigned long long value;
131 class Float : public Value
134 Float(double _value) : value(_value) {}
136 bool toBool(void) const;
137 signed long long toSInt(void) const;
138 unsigned long long toUInt(void) const;
139 virtual float toFloat(void) const;
140 virtual double toDouble(void) const;
141 void visit(Visitor &visitor);
147 class String : public Value
150 String(const char * _value) : value(_value) {}
152 bool toBool(void) const;
153 const char *toString(void) const;
154 void visit(Visitor &visitor);
160 class Enum : public Value
163 struct Signature : public std::pair<const char *, Value *>
166 : std::pair<const char *, Value *>()
168 Signature(const char *n, Trace::Value *val)
169 : std::pair<const char *, Value *>(n, val)
177 Enum(const Signature *_sig) : sig(_sig) {}
179 bool toBool(void) const;
180 signed long long toSInt(void) const;
181 unsigned long long toUInt(void) const;
182 virtual float toFloat(void) const;
183 virtual double toDouble(void) const;
184 void visit(Visitor &visitor);
186 const Signature *sig;
190 class Bitmask : public UInt
193 typedef std::pair<const char *, unsigned long long> Pair;
194 typedef std::vector<Pair> Signature;
196 Bitmask(const Signature *_sig, unsigned long long _value) : UInt(_value), sig(_sig) {}
198 void visit(Visitor &visitor);
200 const Signature *sig;
204 class Struct : public Value
209 std::vector<const char *> member_names;
212 Struct(Signature *_sig) : sig(_sig), members(_sig->member_names.size()) { }
215 bool toBool(void) const;
216 void visit(Visitor &visitor);
218 const Signature *sig;
219 std::vector<Value *> members;
223 class Array : public Value
226 Array(size_t len) : values(len) {}
229 bool toBool(void) const;
230 void visit(Visitor &visitor);
232 std::vector<Value *> values;
236 class Blob : public Value
241 buf = new char[_size];
246 bool toBool(void) const;
247 void *toPointer(void) const;
248 void visit(Visitor &visitor);
255 class Pointer : public UInt
258 Pointer(unsigned long long value) : UInt(value) {}
260 bool toBool(void) const;
261 void *toPointer(void) const;
262 unsigned long long toUIntPtr(void) const;
263 void visit(Visitor &visitor);
270 virtual void visit(Null *);
271 virtual void visit(Bool *);
272 virtual void visit(SInt *);
273 virtual void visit(UInt *);
274 virtual void visit(Float *);
275 virtual void visit(String *);
276 virtual void visit(Enum *);
277 virtual void visit(Bitmask *);
278 virtual void visit(Struct *);
279 virtual void visit(Array *);
280 virtual void visit(Blob *);
281 virtual void visit(Pointer *);
284 inline void _visit(Value *value) {
292 std::ostream & operator <<(std::ostream &os, Value *value);
300 std::vector<const char *> arg_names;
304 const Signature *sig;
305 std::vector<Value *> args;
308 Call(Signature *_sig) : sig(_sig), args(_sig->arg_names.size()), ret(0) { }
311 inline const char * name(void) const {
315 inline Value & arg(unsigned index) {
316 assert(index < args.size());
317 return *(args[index]);
322 std::ostream & operator <<(std::ostream &os, Call &call);
325 } /* namespace Trace */
327 #endif /* _TRACE_MODEL_HPP_ */