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 double toFloat(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 double toFloat(void) const;
77 void *toPointer(void) const;
78 unsigned long long toUIntPtr(void) const;
79 const char *toString(void) const;
80 void visit(Visitor &visitor);
84 class Bool : public Value
87 Bool(bool _value) : value(_value) {}
89 bool toBool(void) const;
90 signed long long toSInt(void) const;
91 unsigned long long toUInt(void) const;
92 double toFloat(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 double toFloat(void) const;
108 void visit(Visitor &visitor);
110 signed long long value;
114 class UInt : public Value
117 UInt(unsigned long long _value) : value(_value) {}
119 bool toBool(void) const;
120 signed long long toSInt(void) const;
121 unsigned long long toUInt(void) const;
122 double toFloat(void) const;
123 void visit(Visitor &visitor);
125 unsigned long long value;
129 class Float : public Value
132 Float(double _value) : value(_value) {}
134 bool toBool(void) const;
135 signed long long toSInt(void) const;
136 unsigned long long toUInt(void) const;
137 double toFloat(void) const;
138 void visit(Visitor &visitor);
144 class String : public Value
147 String(std::string _value) : value(_value) {}
149 bool toBool(void) const;
150 const char *toString(void) const;
151 void visit(Visitor &visitor);
157 class Enum : public Value
160 struct Signature : public std::pair<std::string, Value *>
163 : std::pair<std::string, Value *>()
165 Signature(const std::string &n, Trace::Value *val)
166 : std::pair<std::string, Value *>(n, val)
174 Enum(const Signature *_sig) : sig(_sig) {}
176 bool toBool(void) const;
177 signed long long toSInt(void) const;
178 unsigned long long toUInt(void) const;
179 double toFloat(void) const;
180 void visit(Visitor &visitor);
182 const Signature *sig;
186 class Bitmask : public UInt
189 typedef std::pair<std::string, unsigned long long> Pair;
190 typedef std::vector<Pair> Signature;
192 Bitmask(const Signature *_sig, unsigned long long _value) : UInt(_value), sig(_sig) {}
194 void visit(Visitor &visitor);
196 const Signature *sig;
200 class Struct : public Value
205 std::vector<std::string> member_names;
208 Struct(Signature *_sig) : sig(_sig), members(_sig->member_names.size()) { }
211 bool toBool(void) const;
212 void visit(Visitor &visitor);
214 const Signature *sig;
215 std::vector<Value *> members;
219 class Array : public Value
222 Array(size_t len) : values(len) {}
225 bool toBool(void) const;
226 void visit(Visitor &visitor);
228 std::vector<Value *> values;
232 class Blob : public Value
237 buf = new char[_size];
242 bool toBool(void) const;
243 void *toPointer(void) const;
244 void visit(Visitor &visitor);
251 class Pointer : public UInt
254 Pointer(unsigned long long value) : UInt(value) {}
256 bool toBool(void) const;
257 void *toPointer(void) const;
258 unsigned long long toUIntPtr(void) const;
259 void visit(Visitor &visitor);
266 virtual void visit(Null *);
267 virtual void visit(Bool *);
268 virtual void visit(SInt *);
269 virtual void visit(UInt *);
270 virtual void visit(Float *);
271 virtual void visit(String *);
272 virtual void visit(Enum *);
273 virtual void visit(Bitmask *);
274 virtual void visit(Struct *);
275 virtual void visit(Array *);
276 virtual void visit(Blob *);
277 virtual void visit(Pointer *);
280 inline void _visit(Value *value) {
288 std::ostream & operator <<(std::ostream &os, Value *value);
291 signed long long asSInt(const Value &node);
292 unsigned long long asUInt(const Value &node);
293 double asFloat(const Value &node);
301 std::vector<std::string> 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 std::string & name(void) const {
316 inline Value & arg(unsigned index) {
317 return *(args[index]);
322 std::ostream & operator <<(std::ostream &os, Call &call);
325 } /* namespace Trace */
327 #endif /* _TRACE_MODEL_HPP_ */