From: José Fonseca Date: Sat, 28 May 2011 11:45:56 +0000 (+0100) Subject: Unify Enum::Signature into EnumSig. X-Git-Tag: 2.0_alpha^2~846 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ec494edf0f473db4088c23ec7a97f20eab393c2d;p=tools%2Fapitrace.git Unify Enum::Signature into EnumSig. --- diff --git a/gui/apitracecall.cpp b/gui/apitracecall.cpp index 865f9ae..6112877 100644 --- a/gui/apitracecall.cpp +++ b/gui/apitracecall.cpp @@ -271,13 +271,10 @@ void VariantVisitor::visit(Trace::String *node) void VariantVisitor::visit(Trace::Enum *e) { - VariantVisitor vis; - e->sig->second->visit(vis); - - QVariant val = vis.variant(); + QVariant val = QVariant(e->sig->value); m_variant = QVariant::fromValue( - ApiEnum(QString::fromStdString(e->sig->first), val)); + ApiEnum(QString::fromStdString(e->sig->name), val)); } void VariantVisitor::visit(Trace::Bitmask *bitmask) diff --git a/trace_model.cpp b/trace_model.cpp index 303e953..617abc7 100644 --- a/trace_model.cpp +++ b/trace_model.cpp @@ -69,7 +69,7 @@ bool SInt ::toBool(void) const { return value != 0; } bool UInt ::toBool(void) const { return value != 0; } bool Float ::toBool(void) const { return value != 0; } bool String ::toBool(void) const { return true; } -bool Enum ::toBool(void) const { return sig->second->toBool(); } +bool Enum ::toBool(void) const { return sig->value != 0; } bool Struct ::toBool(void) const { return true; } bool Array ::toBool(void) const { return true; } bool Blob ::toBool(void) const { return true; } @@ -83,7 +83,7 @@ signed long long Bool ::toSInt(void) const { return static_cast(value) >= 0); return static_cast(value); } signed long long Float ::toSInt(void) const { return static_cast(value); } -signed long long Enum ::toSInt(void) const { return sig->second->toSInt(); } +signed long long Enum ::toSInt(void) const { return sig->value; } // unsigned integer cast @@ -93,7 +93,7 @@ unsigned long long Bool ::toUInt(void) const { return static_cast= 0); return static_cast(value); } unsigned long long UInt ::toUInt(void) const { return value; } unsigned long long Float ::toUInt(void) const { return static_cast(value); } -unsigned long long Enum ::toUInt(void) const { return sig->second->toUInt(); } +unsigned long long Enum ::toUInt(void) const { assert(sig->value >= 0); return sig->value; } // floating point cast @@ -103,7 +103,7 @@ float Bool ::toFloat(void) const { return static_cast(value); } float SInt ::toFloat(void) const { return static_cast(value); } float UInt ::toFloat(void) const { return static_cast(value); } float Float ::toFloat(void) const { return value; } -float Enum ::toFloat(void) const { return sig->second->toFloat(); } +float Enum ::toFloat(void) const { return static_cast(sig->value); } // floating point cast @@ -113,7 +113,7 @@ double Bool ::toDouble(void) const { return static_cast(value); } double SInt ::toDouble(void) const { return static_cast(value); } double UInt ::toDouble(void) const { return static_cast(value); } double Float ::toDouble(void) const { return value; } -double Enum ::toDouble(void) const { return sig->second->toDouble(); } +double Enum ::toDouble(void) const { return static_cast(sig->value); } // pointer cast @@ -156,7 +156,7 @@ void Visitor::visit(SInt *) { assert(0); } void Visitor::visit(UInt *) { assert(0); } void Visitor::visit(Float *) { assert(0); } void Visitor::visit(String *) { assert(0); } -void Visitor::visit(Enum *node) { _visit(node->sig->second); } +void Visitor::visit(Enum *node) { assert(0); } void Visitor::visit(Bitmask *node) { visit(static_cast(node)); } void Visitor::visit(Struct *) { assert(0); } void Visitor::visit(Array *) { assert(0); } @@ -250,7 +250,7 @@ public: } void visit(Enum *node) { - os << literal << node->sig->first << normal; + os << literal << node->sig->name << normal; } void visit(Bitmask *bitmask) { diff --git a/trace_model.hpp b/trace_model.hpp index 6560346..eb28465 100644 --- a/trace_model.hpp +++ b/trace_model.hpp @@ -162,21 +162,7 @@ public: class Enum : public Value { public: - struct Signature : public std::pair - { - Signature() - : std::pair() - {} - Signature(const char *n, Trace::Value *val) - : std::pair(n, val) - {} - ~Signature() - { - delete second; - } - }; - - Enum(const Signature *_sig) : sig(_sig) {} + Enum(const EnumSig *_sig) : sig(_sig) {} bool toBool(void) const; signed long long toSInt(void) const; @@ -185,7 +171,7 @@ public: virtual double toDouble(void) const; void visit(Visitor &visitor); - const Signature *sig; + const EnumSig *sig; }; diff --git a/trace_parser.cpp b/trace_parser.cpp index 77bdd1f..1af9ad0 100644 --- a/trace_parser.cpp +++ b/trace_parser.cpp @@ -309,11 +309,14 @@ Value *Parser::parse_string() { Value *Parser::parse_enum() { size_t id = read_uint(); - Enum::Signature *sig = lookup(enums, id); + EnumSig *sig = lookup(enums, id); if (!sig) { - const char *name = read_string(); + sig = new EnumSig; + sig->id = id; + sig->name = read_string(); Value *value = parse_value(); - sig = new Enum::Signature(name, value); + sig->value = value->toSInt(); + delete value; enums[id] = sig; } assert(sig); diff --git a/trace_parser.hpp b/trace_parser.hpp index 634cb59..fe36023 100644 --- a/trace_parser.hpp +++ b/trace_parser.hpp @@ -51,7 +51,7 @@ protected: typedef std::vector StructMap; StructMap structs; - typedef std::vector EnumMap; + typedef std::vector EnumMap; EnumMap enums; typedef std::vector BitmaskMap;