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 virtual bool toBool(void) const = 0;
58 virtual signed long long toSInt(void) const;
59 virtual unsigned long long toUInt(void) const;
60 virtual float toFloat(void) const;
61 virtual double toDouble(void) const;
63 virtual void *toPointer(void) const;
64 virtual unsigned long long toUIntPtr(void) const;
65 virtual const char *toString(void) const;
67 const Value & operator[](size_t index) const;
71 class Null : public Value
74 bool toBool(void) const;
75 signed long long toSInt(void) const;
76 unsigned long long toUInt(void) const;
77 virtual float toFloat(void) const;
78 virtual double toDouble(void) const;
79 void *toPointer(void) const;
80 unsigned long long toUIntPtr(void) const;
81 const char *toString(void) const;
82 void visit(Visitor &visitor);
86 class Bool : public Value
89 Bool(bool _value) : value(_value) {}
91 bool toBool(void) const;
92 signed long long toSInt(void) const;
93 unsigned long long toUInt(void) const;
94 virtual float toFloat(void) const;
95 virtual double toDouble(void) const;
96 void visit(Visitor &visitor);
102 class SInt : public Value
105 SInt(signed long long _value) : value(_value) {}
107 bool toBool(void) const;
108 signed long long toSInt(void) const;
109 unsigned long long toUInt(void) const;
110 virtual float toFloat(void) const;
111 virtual double toDouble(void) const;
112 void visit(Visitor &visitor);
114 signed long long value;
118 class UInt : public Value
121 UInt(unsigned long long _value) : value(_value) {}
123 bool toBool(void) const;
124 signed long long toSInt(void) const;
125 unsigned long long toUInt(void) const;
126 virtual float toFloat(void) const;
127 virtual double toDouble(void) const;
128 void visit(Visitor &visitor);
130 unsigned long long value;
134 class Float : public Value
137 Float(double _value) : value(_value) {}
139 bool toBool(void) const;
140 signed long long toSInt(void) const;
141 unsigned long long toUInt(void) const;
142 virtual float toFloat(void) const;
143 virtual double toDouble(void) const;
144 void visit(Visitor &visitor);
150 class String : public Value
153 String(std::string _value) : value(_value) {}
155 bool toBool(void) const;
156 const char *toString(void) const;
157 void visit(Visitor &visitor);
163 class Enum : public Value
166 struct Signature : public std::pair<std::string, Value *>
169 : std::pair<std::string, Value *>()
171 Signature(const std::string &n, Trace::Value *val)
172 : std::pair<std::string, Value *>(n, val)
180 Enum(const Signature *_sig) : sig(_sig) {}
182 bool toBool(void) const;
183 signed long long toSInt(void) const;
184 unsigned long long toUInt(void) const;
185 virtual float toFloat(void) const;
186 virtual double toDouble(void) const;
187 void visit(Visitor &visitor);
189 const Signature *sig;
193 class Bitmask : public UInt
196 typedef std::pair<std::string, unsigned long long> Pair;
197 typedef std::vector<Pair> Signature;
199 Bitmask(const Signature *_sig, unsigned long long _value) : UInt(_value), sig(_sig) {}
201 void visit(Visitor &visitor);
203 const Signature *sig;
207 class Struct : public Value
212 std::vector<std::string> member_names;
215 Struct(Signature *_sig) : sig(_sig), members(_sig->member_names.size()) { }
218 bool toBool(void) const;
219 void visit(Visitor &visitor);
221 const Signature *sig;
222 std::vector<Value *> members;
226 class Array : public Value
229 Array(size_t len) : values(len) {}
232 bool toBool(void) const;
233 void visit(Visitor &visitor);
235 std::vector<Value *> values;
239 class Blob : public Value
244 buf = new char[_size];
249 bool toBool(void) const;
250 void *toPointer(void) const;
251 void visit(Visitor &visitor);
258 class Pointer : public UInt
261 Pointer(unsigned long long value) : UInt(value) {}
263 bool toBool(void) const;
264 void *toPointer(void) const;
265 unsigned long long toUIntPtr(void) const;
266 void visit(Visitor &visitor);
273 virtual void visit(Null *);
274 virtual void visit(Bool *);
275 virtual void visit(SInt *);
276 virtual void visit(UInt *);
277 virtual void visit(Float *);
278 virtual void visit(String *);
279 virtual void visit(Enum *);
280 virtual void visit(Bitmask *);
281 virtual void visit(Struct *);
282 virtual void visit(Array *);
283 virtual void visit(Blob *);
284 virtual void visit(Pointer *);
287 inline void _visit(Value *value) {
295 std::ostream & operator <<(std::ostream &os, Value *value);
303 std::vector<std::string> arg_names;
307 const Signature *sig;
308 std::vector<Value *> args;
311 Call(Signature *_sig) : sig(_sig), args(_sig->arg_names.size()), ret(0) { }
314 inline const std::string & name(void) const {
318 inline Value & arg(unsigned index) {
319 assert(index < args.size());
320 return *(args[index]);
325 std::ostream & operator <<(std::ostream &os, Call &call);
328 } /* namespace Trace */
330 #endif /* _TRACE_MODEL_HPP_ */