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 **************************************************************************/
26 #ifndef _TRACE_MODEL_HPP_
27 #define _TRACE_MODEL_HPP_
50 virtual void visit(Visitor &visitor) = 0;
52 operator signed long long (void) const;
53 operator unsigned long long (void) const;
54 operator double (void) const;
56 inline operator signed char (void) const {
57 return static_cast<signed long long>(*this);
60 inline operator unsigned char (void) const {
61 return static_cast<signed long long>(*this);
64 inline operator signed short (void) const {
65 return static_cast<signed long long>(*this);
68 inline operator unsigned short (void) const {
69 return static_cast<unsigned long long>(*this);
72 inline operator signed (void) const {
73 return static_cast<signed long long>(*this);
76 inline operator unsigned (void) const {
77 return static_cast<unsigned long long>(*this);
80 inline operator signed long (void) const {
81 return static_cast<signed long long>(*this);
84 inline operator unsigned long (void) const {
85 return static_cast<unsigned long long>(*this);
88 inline operator float (void) const {
89 return static_cast<double>(*this);
92 const Value & operator[](size_t index) const;
96 class Void : public Value
99 void visit(Visitor &visitor);
103 class Bool : public Value
106 Bool(bool _value) : value(_value) {}
108 void visit(Visitor &visitor);
114 class SInt : public Value
117 SInt(signed long long _value) : value(_value) {}
119 void visit(Visitor &visitor);
121 signed long long value;
125 class UInt : public Value
128 UInt(unsigned long long _value) : value(_value) {}
130 void visit(Visitor &visitor);
132 unsigned long long value;
136 class Float : public Value
139 Float(double _value) : value(_value) {}
141 void visit(Visitor &visitor);
147 class String : public Value
150 String(std::string _value) : value(_value) {}
152 void visit(Visitor &visitor);
158 class Const : public Value
161 Const(std::string _name, Value *_value) : name(_name), value(_value) {}
163 void visit(Visitor &visitor);
170 class Array : public Value
173 Array(size_t len) : values(len) {}
175 void visit(Visitor &visitor);
177 std::vector<Value *> values;
184 virtual void visit(Void *) {assert(0);}
185 virtual void visit(Bool *) {assert(0);}
186 virtual void visit(SInt *) {assert(0);}
187 virtual void visit(UInt *) {assert(0);}
188 virtual void visit(Float *) {assert(0);}
189 virtual void visit(String *) {assert(0);}
190 virtual void visit(Const *) {assert(0);}
191 virtual void visit(Array *) {assert(0);}
195 std::ostream & operator <<(std::ostream &os, Value *value);
198 signed long long asSInt(const Value &node);
199 unsigned long long asUInt(const Value &node);
200 double asFloat(const Value &node);
203 typedef std::pair<std::string, Value *> Arg;
214 Value & arg(const char *name);
219 std::ostream & operator <<(std::ostream &os, Call &call);
222 } /* namespace Trace */
224 #endif /* _TRACE_MODEL_HPP_ */