From: José Fonseca Date: Fri, 25 Mar 2011 10:12:22 +0000 (+0000) Subject: Make Value::blob a virtual method. X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=60ac78c465ecaf50ed8da304e90a6da6a3005e73;p=apitrace Make Value::blob a virtual method. Should do the same for many other Value methods which abuse dynamic_casts. --- diff --git a/trace_model.cpp b/trace_model.cpp index 4bdb0c0..a10eef5 100644 --- a/trace_model.cpp +++ b/trace_model.cpp @@ -62,6 +62,13 @@ Blob::~Blob() { } +// virtual Value::blob() +void * Value ::blob(void) const { assert(0); return NULL; } +void * Null ::blob(void) const { return NULL; } +void * Blob ::blob(void) const { return buf; } +void * Pointer::blob(void) const { assert(value < 0x100000ULL); return (void *)value; } + + // virtual Value::visit() void Null ::visit(Visitor &visitor) { visitor.visit(this); } void Bool ::visit(Visitor &visitor) { visitor.visit(this); } @@ -292,22 +299,6 @@ const Value & Value::operator[](size_t index) const { return null; } -void * Value::blob(void) const { - const Blob *blob = dynamic_cast(unwrap(this)); - if (blob) - return blob->buf; - const Null *null = dynamic_cast(unwrap(this)); - if (null) - return NULL; - const Pointer *pointer = dynamic_cast(unwrap(this)); - if (pointer) { - assert(pointer->value < 0x100000ULL); - return (void *)pointer->value; - } - assert(0); - return NULL; -} - const char * Value::string(void) const { const String *string = dynamic_cast(unwrap(this)); if (string) diff --git a/trace_model.hpp b/trace_model.hpp index 90fa0f6..62316e9 100644 --- a/trace_model.hpp +++ b/trace_model.hpp @@ -59,7 +59,7 @@ public: operator unsigned long long (void) const; operator double (void) const; - void *blob(void) const; + virtual void *blob(void) const; const char *string(void) const; inline operator signed char (void) const { @@ -105,6 +105,7 @@ public: class Null : public Value { public: + void *blob(void) const; void visit(Visitor &visitor); }; @@ -233,6 +234,7 @@ public: ~Blob(); + void *blob(void) const; void visit(Visitor &visitor); size_t size; @@ -245,6 +247,7 @@ class Pointer : public UInt public: Pointer(unsigned long long value) : UInt(value) {} + void *blob(void) const; void visit(Visitor &visitor); };