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_
41 #include "trace_writer.hpp"
54 virtual void visit(Visitor &visitor) = 0;
56 virtual bool toBool(void) const = 0;
57 virtual signed long long toSInt(void) const;
58 virtual unsigned long long toUInt(void) const;
59 virtual float toFloat(void) const;
60 virtual double toDouble(void) const;
62 virtual void *toPointer(void) const;
63 virtual unsigned long long toUIntPtr(void) const;
64 virtual const char *toString(void) const;
66 const Value & operator[](size_t index) const;
70 class Null : public Value
73 bool toBool(void) const;
74 signed long long toSInt(void) const;
75 unsigned long long toUInt(void) const;
76 virtual float toFloat(void) const;
77 virtual double toDouble(void) const;
78 void *toPointer(void) const;
79 unsigned long long toUIntPtr(void) const;
80 const char *toString(void) const;
81 void visit(Visitor &visitor);
85 class Bool : public Value
88 Bool(bool _value) : value(_value) {}
90 bool toBool(void) const;
91 signed long long toSInt(void) const;
92 unsigned long long toUInt(void) const;
93 virtual float toFloat(void) const;
94 virtual double toDouble(void) const;
95 void visit(Visitor &visitor);
101 class SInt : public Value
104 SInt(signed long long _value) : value(_value) {}
106 bool toBool(void) const;
107 signed long long toSInt(void) const;
108 unsigned long long toUInt(void) const;
109 virtual float toFloat(void) const;
110 virtual double toDouble(void) const;
111 void visit(Visitor &visitor);
113 signed long long value;
117 class UInt : public Value
120 UInt(unsigned long long _value) : value(_value) {}
122 bool toBool(void) const;
123 signed long long toSInt(void) const;
124 unsigned long long toUInt(void) const;
125 virtual float toFloat(void) const;
126 virtual double toDouble(void) const;
127 void visit(Visitor &visitor);
129 unsigned long long value;
133 class Float : public Value
136 Float(double _value) : value(_value) {}
138 bool toBool(void) const;
139 signed long long toSInt(void) const;
140 unsigned long long toUInt(void) const;
141 virtual float toFloat(void) const;
142 virtual double toDouble(void) const;
143 void visit(Visitor &visitor);
149 class String : public Value
152 String(const char * _value) : value(_value) {}
154 bool toBool(void) const;
155 const char *toString(void) const;
156 void visit(Visitor &visitor);
162 class Enum : public Value
165 struct Signature : public std::pair<const char *, Value *>
168 : std::pair<const char *, Value *>()
170 Signature(const char *n, Trace::Value *val)
171 : std::pair<const char *, Value *>(n, val)
179 Enum(const Signature *_sig) : sig(_sig) {}
181 bool toBool(void) const;
182 signed long long toSInt(void) const;
183 unsigned long long toUInt(void) const;
184 virtual float toFloat(void) const;
185 virtual double toDouble(void) const;
186 void visit(Visitor &visitor);
188 const Signature *sig;
192 class Bitmask : public UInt
195 typedef std::vector<BitmaskVal> Signature;
197 Bitmask(const Signature *_sig, unsigned long long _value) : UInt(_value), sig(_sig) {}
199 void visit(Visitor &visitor);
201 const Signature *sig;
205 class Struct : public Value
210 std::vector<const char *> member_names;
213 Struct(Signature *_sig) : sig(_sig), members(_sig->member_names.size()) { }
216 bool toBool(void) const;
217 void visit(Visitor &visitor);
219 const Signature *sig;
220 std::vector<Value *> members;
224 class Array : public Value
227 Array(size_t len) : values(len) {}
230 bool toBool(void) const;
231 void visit(Visitor &visitor);
233 std::vector<Value *> values;
237 class Blob : public Value
242 buf = new char[_size];
247 bool toBool(void) const;
248 void *toPointer(void) const;
249 void visit(Visitor &visitor);
256 class Pointer : public UInt
259 Pointer(unsigned long long value) : UInt(value) {}
261 bool toBool(void) const;
262 void *toPointer(void) const;
263 unsigned long long toUIntPtr(void) const;
264 void visit(Visitor &visitor);
271 virtual void visit(Null *);
272 virtual void visit(Bool *);
273 virtual void visit(SInt *);
274 virtual void visit(UInt *);
275 virtual void visit(Float *);
276 virtual void visit(String *);
277 virtual void visit(Enum *);
278 virtual void visit(Bitmask *);
279 virtual void visit(Struct *);
280 virtual void visit(Array *);
281 virtual void visit(Blob *);
282 virtual void visit(Pointer *);
285 inline void _visit(Value *value) {
293 std::ostream & operator <<(std::ostream &os, Value *value);
301 std::vector<const char *> arg_names;
305 const Signature *sig;
306 std::vector<Value *> args;
309 Call(Signature *_sig) : sig(_sig), args(_sig->arg_names.size()), ret(0) { }
312 inline const char * name(void) const {
316 inline Value & arg(unsigned index) {
317 assert(index < args.size());
318 return *(args[index]);
323 std::ostream & operator <<(std::ostream &os, Call &call);
326 } /* namespace Trace */
328 #endif /* _TRACE_MODEL_HPP_ */