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 void *blob(void) const;
57 const char *string(void) const;
59 inline operator signed char (void) const {
60 return static_cast<signed long long>(*this);
63 inline operator unsigned char (void) const {
64 return static_cast<signed long long>(*this);
67 inline operator signed short (void) const {
68 return static_cast<signed long long>(*this);
71 inline operator unsigned short (void) const {
72 return static_cast<unsigned long long>(*this);
75 inline operator signed (void) const {
76 return static_cast<signed long long>(*this);
79 inline operator unsigned (void) const {
80 return static_cast<unsigned long long>(*this);
83 inline operator signed long (void) const {
84 return static_cast<signed long long>(*this);
87 inline operator unsigned long (void) const {
88 return static_cast<unsigned long long>(*this);
91 inline operator float (void) const {
92 return static_cast<double>(*this);
95 const Value & operator[](size_t index) const;
99 class Null : public Value
102 void visit(Visitor &visitor);
106 class Bool : public Value
109 Bool(bool _value) : value(_value) {}
111 void visit(Visitor &visitor);
117 class SInt : public Value
120 SInt(signed long long _value) : value(_value) {}
122 void visit(Visitor &visitor);
124 signed long long value;
128 class UInt : public Value
131 UInt(unsigned long long _value) : value(_value) {}
133 void visit(Visitor &visitor);
135 unsigned long long value;
139 class Float : public Value
142 Float(double _value) : value(_value) {}
144 void visit(Visitor &visitor);
150 class String : public Value
153 String(std::string _value) : value(_value) {}
155 void visit(Visitor &visitor);
161 class Const : public Value
164 Const(std::string _name, Value *_value) : name(_name), value(_value) {}
166 void visit(Visitor &visitor);
173 class Array : public Value
176 Array(size_t len) : values(len) {}
178 void visit(Visitor &visitor);
180 std::vector<Value *> values;
184 class Blob : public Value
189 buf = new char[_size];
196 void visit(Visitor &visitor);
206 virtual void visit(Null *) {assert(0);}
207 virtual void visit(Bool *) {assert(0);}
208 virtual void visit(SInt *) {assert(0);}
209 virtual void visit(UInt *) {assert(0);}
210 virtual void visit(Float *) {assert(0);}
211 virtual void visit(String *) {assert(0);}
212 virtual void visit(Const *) {assert(0);}
213 virtual void visit(Array *) {assert(0);}
214 virtual void visit(Blob *) {assert(0);}
218 std::ostream & operator <<(std::ostream &os, Value *value);
221 signed long long asSInt(const Value &node);
222 unsigned long long asUInt(const Value &node);
223 double asFloat(const Value &node);
226 typedef std::pair<std::string, Value *> Arg;
237 Value & arg(const char *name);
242 std::ostream & operator <<(std::ostream &os, Call &call);
245 } /* namespace Trace */
247 #endif /* _TRACE_MODEL_HPP_ */