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 operator bool (void) const = 0;
58 virtual operator signed long long (void) const;
59 virtual operator unsigned long long (void) const;
60 virtual operator double (void) const;
62 virtual void *toPointer(void) const;
63 virtual unsigned long long toUIntPtr(void) const;
64 virtual const char *toString(void) const;
66 inline operator signed char (void) const {
67 return static_cast<signed long long>(*this);
70 inline operator unsigned char (void) const {
71 return static_cast<signed long long>(*this);
74 inline operator signed short (void) const {
75 return static_cast<signed long long>(*this);
78 inline operator unsigned short (void) const {
79 return static_cast<unsigned long long>(*this);
82 inline operator signed (void) const {
83 return static_cast<signed long long>(*this);
86 inline operator unsigned (void) const {
87 return static_cast<unsigned long long>(*this);
90 inline operator signed long (void) const {
91 return static_cast<signed long long>(*this);
94 inline operator unsigned long (void) const {
95 return static_cast<unsigned long long>(*this);
98 inline operator float (void) const {
99 return static_cast<double>(*this);
102 const Value & operator[](size_t index) const;
106 class Null : public Value
109 operator bool (void) const;
110 operator signed long long (void) const;
111 operator unsigned long long (void) const;
112 operator double (void) const;
113 void *toPointer(void) const;
114 unsigned long long toUIntPtr(void) const;
115 const char *toString(void) const;
116 void visit(Visitor &visitor);
120 class Bool : public Value
123 Bool(bool _value) : value(_value) {}
125 operator bool (void) const;
126 operator signed long long (void) const;
127 operator unsigned long long (void) const;
128 operator double (void) const;
129 void visit(Visitor &visitor);
135 class SInt : public Value
138 SInt(signed long long _value) : value(_value) {}
140 operator bool (void) const;
141 operator signed long long (void) const;
142 operator unsigned long long (void) const;
143 operator double (void) const;
144 void visit(Visitor &visitor);
146 signed long long value;
150 class UInt : public Value
153 UInt(unsigned long long _value) : value(_value) {}
155 operator bool (void) const;
156 operator signed long long (void) const;
157 operator unsigned long long (void) const;
158 operator double (void) const;
159 void visit(Visitor &visitor);
161 unsigned long long value;
165 class Float : public Value
168 Float(double _value) : value(_value) {}
170 operator bool (void) const;
171 operator signed long long (void) const;
172 operator unsigned long long (void) const;
173 operator double (void) const;
174 void visit(Visitor &visitor);
180 class String : public Value
183 String(std::string _value) : value(_value) {}
185 operator bool (void) const;
186 const char *toString(void) const;
187 void visit(Visitor &visitor);
193 class Enum : public Value
196 struct Signature : public std::pair<std::string, Value *>
199 : std::pair<std::string, Value *>()
201 Signature(const std::string &n, Trace::Value *val)
202 : std::pair<std::string, Value *>(n, val)
210 Enum(const Signature *_sig) : sig(_sig) {}
212 operator bool (void) const;
213 operator signed long long (void) const;
214 operator unsigned long long (void) const;
215 operator double (void) const;
216 void visit(Visitor &visitor);
218 const Signature *sig;
222 class Bitmask : public UInt
225 typedef std::pair<std::string, unsigned long long> Pair;
226 typedef std::vector<Pair> Signature;
228 Bitmask(const Signature *_sig, unsigned long long _value) : UInt(_value), sig(_sig) {}
230 void visit(Visitor &visitor);
232 const Signature *sig;
236 class Struct : public Value
241 std::vector<std::string> member_names;
244 Struct(Signature *_sig) : sig(_sig), members(_sig->member_names.size()) { }
247 operator bool (void) const;
248 void visit(Visitor &visitor);
250 const Signature *sig;
251 std::vector<Value *> members;
255 class Array : public Value
258 Array(size_t len) : values(len) {}
261 operator bool (void) const;
262 void visit(Visitor &visitor);
264 std::vector<Value *> values;
268 class Blob : public Value
273 buf = new char[_size];
278 operator bool (void) const;
279 void *toPointer(void) const;
280 void visit(Visitor &visitor);
287 class Pointer : public UInt
290 Pointer(unsigned long long value) : UInt(value) {}
292 operator bool (void) const;
293 void *toPointer(void) const;
294 unsigned long long toUIntPtr(void) const;
295 void visit(Visitor &visitor);
302 virtual void visit(Null *);
303 virtual void visit(Bool *);
304 virtual void visit(SInt *);
305 virtual void visit(UInt *);
306 virtual void visit(Float *);
307 virtual void visit(String *);
308 virtual void visit(Enum *);
309 virtual void visit(Bitmask *);
310 virtual void visit(Struct *);
311 virtual void visit(Array *);
312 virtual void visit(Blob *);
313 virtual void visit(Pointer *);
316 inline void _visit(Value *value) {
324 std::ostream & operator <<(std::ostream &os, Value *value);
327 signed long long asSInt(const Value &node);
328 unsigned long long asUInt(const Value &node);
329 double asFloat(const Value &node);
337 std::vector<std::string> arg_names;
341 const Signature *sig;
342 std::vector<Value *> args;
345 Call(Signature *_sig) : sig(_sig), args(_sig->arg_names.size()), ret(0) { }
348 inline const std::string & name(void) const {
352 inline Value & arg(unsigned index) {
353 return *(args[index]);
358 std::ostream & operator <<(std::ostream &os, Call &call);
361 } /* namespace Trace */
363 #endif /* _TRACE_MODEL_HPP_ */