]> git.cworth.org Git - apitrace/commitdiff
Make Value::blob a virtual method.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Fri, 25 Mar 2011 10:12:22 +0000 (10:12 +0000)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Fri, 25 Mar 2011 10:12:22 +0000 (10:12 +0000)
Should do the same for many other Value methods which abuse dynamic_casts.

trace_model.cpp
trace_model.hpp

index 4bdb0c0f1ab619c9c2d4fad753463b844f6c4106..a10eef51e6353ca884ec8117565caf9ab9f17860 100644 (file)
@@ -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<const Blob *>(unwrap(this));
-    if (blob)
-        return blob->buf;
-    const Null *null = dynamic_cast<const Null *>(unwrap(this));
-    if (null)
-        return NULL;
-    const Pointer *pointer = dynamic_cast<const Pointer *>(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<const String *>(unwrap(this));
     if (string)
index 90fa0f6da47987893c8424a3e137f349bee5a1fc..62316e9ea7edfa27d985441ae132abac98d6f146 100644 (file)
@@ -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);
 };