]> git.cworth.org Git - apitrace/blobdiff - trace_model.hpp
Split gltrace.cpp code into multiple files.
[apitrace] / trace_model.hpp
index 50a505874ece7328fb2c81615f2b6013b4fe3577..6adf4c2a55d44a9d286c9ad84d0e376ebd8885fa 100644 (file)
  *
  **************************************************************************/
 
+/*
+ * Object hierarchy for describing the traces in memory.
+ */
+
 #ifndef _TRACE_MODEL_HPP_
 #define _TRACE_MODEL_HPP_
 
@@ -47,171 +51,256 @@ class UInt;
 class Value
 {
 public:
-   virtual void visit(Visitor &visitor) = 0;
+    virtual ~Value() {}
+    virtual void visit(Visitor &visitor) = 0;
 
-   operator signed long long (void) const;
-   operator unsigned long long (void) const;
-   operator double (void) const;
+    virtual operator bool (void) const = 0;
+    virtual operator signed long long (void) const;
+    virtual operator unsigned long long (void) const;
+    virtual operator double (void) const;
 
-   void *blob(void) const;
-   const char *string(void) const;
+    virtual void *blob(void) const;
+    const char *string(void) const;
 
-   inline operator signed char (void) const { 
-      return static_cast<signed long long>(*this);
-   }
+    inline operator signed char (void) const { 
+        return static_cast<signed long long>(*this);
+    }
 
-   inline operator unsigned char (void) const { 
-      return static_cast<signed long long>(*this);
-   }
+    inline operator unsigned char (void) const { 
+        return static_cast<signed long long>(*this);
+    }
 
-   inline operator signed short (void) const { 
-      return static_cast<signed long long>(*this);
-   }
+    inline operator signed short (void) const { 
+        return static_cast<signed long long>(*this);
+    }
 
-   inline operator unsigned short (void) const { 
-      return static_cast<unsigned long long>(*this);
-   }
+    inline operator unsigned short (void) const { 
+        return static_cast<unsigned long long>(*this);
+    }
 
-   inline operator signed (void) const { 
-      return static_cast<signed long long>(*this);
-   }
+    inline operator signed (void) const { 
+        return static_cast<signed long long>(*this);
+    }
 
-   inline operator unsigned (void) const { 
-      return static_cast<unsigned long long>(*this);
-   }
+    inline operator unsigned (void) const { 
+        return static_cast<unsigned long long>(*this);
+    }
 
-   inline operator signed long (void) const { 
-      return static_cast<signed long long>(*this);
-   }
+    inline operator signed long (void) const { 
+        return static_cast<signed long long>(*this);
+    }
 
-   inline operator unsigned long (void) const { 
-      return static_cast<unsigned long long>(*this);
-   }
+    inline operator unsigned long (void) const { 
+        return static_cast<unsigned long long>(*this);
+    }
 
-   inline operator float (void) const { 
-      return static_cast<double>(*this);
-   }
+    inline operator float (void) const { 
+        return static_cast<double>(*this);
+    }
 
-   const Value & operator[](size_t index) const;
+    const Value & operator[](size_t index) const;
 };
 
 
 class Null : public Value
 {
 public:
-   void visit(Visitor &visitor);
+    operator bool (void) const;
+    operator signed long long (void) const;
+    operator unsigned long long (void) const;
+    operator double (void) const;
+    void *blob(void) const;
+    void visit(Visitor &visitor);
 };
 
 
 class Bool : public Value
 {
 public:
-   Bool(bool _value) : value(_value) {}
+    Bool(bool _value) : value(_value) {}
 
-   void visit(Visitor &visitor);
+    operator bool (void) const;
+    operator signed long long (void) const;
+    operator unsigned long long (void) const;
+    operator double (void) const;
+    void visit(Visitor &visitor);
 
-   bool value;
+    bool value;
 };
 
 
 class SInt : public Value
 {
 public:
-   SInt(signed long long _value) : value(_value) {}
+    SInt(signed long long _value) : value(_value) {}
 
-   void visit(Visitor &visitor);
+    operator bool (void) const;
+    operator signed long long (void) const;
+    operator unsigned long long (void) const;
+    operator double (void) const;
+    void visit(Visitor &visitor);
 
-   signed long long value;
+    signed long long value;
 };
 
 
 class UInt : public Value
 {
 public:
-   UInt(unsigned long long _value) : value(_value) {}
+    UInt(unsigned long long _value) : value(_value) {}
 
-   void visit(Visitor &visitor);
+    operator bool (void) const;
+    operator signed long long (void) const;
+    operator unsigned long long (void) const;
+    operator double (void) const;
+    void visit(Visitor &visitor);
 
-   unsigned long long value;
+    unsigned long long value;
 };
 
 
 class Float : public Value
 {
 public:
-   Float(double _value) : value(_value) {}
+    Float(double _value) : value(_value) {}
 
-   void visit(Visitor &visitor);
+    operator bool (void) const;
+    operator signed long long (void) const;
+    operator unsigned long long (void) const;
+    operator double (void) const;
+    void visit(Visitor &visitor);
 
-   double value;
+    double value;
 };
 
 
 class String : public Value
 {
 public:
-   String(std::string _value) : value(_value) {}
+    String(std::string _value) : value(_value) {}
+
+    operator bool (void) const;
+    void visit(Visitor &visitor);
+
+    std::string value;
+};
+
+
+class Enum : public Value
+{
+public:
+    typedef std::pair<std::string, Value *> Signature;
+
+    Enum(const Signature *_sig) : sig(_sig) {}
+
+    operator bool (void) const;
+    operator signed long long (void) const;
+    operator unsigned long long (void) const;
+    operator double (void) const;
+    void visit(Visitor &visitor);
+
+    const Signature *sig;
+};
+
+
+class Bitmask : public UInt
+{
+public:
+    typedef std::pair<std::string, unsigned long long> Pair;
+    typedef std::vector<Pair> Signature;
 
-   void visit(Visitor &visitor);
+    Bitmask(const Signature *_sig, unsigned long long _value) : UInt(_value), sig(_sig) {}
 
-   std::string value;
+    void visit(Visitor &visitor);
+
+    const Signature *sig;
 };
 
 
-class Const : public Value
+class Struct : public Value
 {
 public:
-   Const(std::string _name, Value *_value) : name(_name), value(_value) {}
+    struct Signature {
+        std::string name;
+        std::vector<std::string> member_names;
+    };
+
+    Struct(Signature *_sig) : sig(_sig), members(_sig->member_names.size()) { }
+    ~Struct();
 
-   void visit(Visitor &visitor);
+    operator bool (void) const;
+    void visit(Visitor &visitor);
 
-   std::string name;
-   Value *value;
+    const Signature *sig;
+    std::vector<Value *> members;
 };
 
 
 class Array : public Value
 {
 public:
-   Array(size_t len) : values(len) {}
+    Array(size_t len) : values(len) {}
+    ~Array();
 
-   void visit(Visitor &visitor);
+    operator bool (void) const;
+    void visit(Visitor &visitor);
 
-   std::vector<Value *> values;
+    std::vector<Value *> values;
 };
 
 
 class Blob : public Value
 {
 public:
-   Blob(size_t _size) {
-       size = _size;
-       buf = new char[_size];
-   }
+    Blob(size_t _size) {
+        size = _size;
+        buf = new char[_size];
+    }
+
+    ~Blob();
+
+    operator bool (void) const;
+    void *blob(void) const;
+    void visit(Visitor &visitor);
+
+    size_t size;
+    char *buf;
+};
 
-   ~Blob() {
-       delete [] buf;
-   }
 
-   void visit(Visitor &visitor);
+class Pointer : public UInt
+{
+public:
+    Pointer(unsigned long long value) : UInt(value) {}
 
-   size_t size;
-   char *buf;
+    operator bool (void) const;
+    void *blob(void) const;
+    void visit(Visitor &visitor);
 };
 
 
 class Visitor
 {
 public:
-   virtual void visit(Null *) {assert(0);}
-   virtual void visit(Bool *) {assert(0);}
-   virtual void visit(SInt *) {assert(0);}
-   virtual void visit(UInt *) {assert(0);}
-   virtual void visit(Float *) {assert(0);}
-   virtual void visit(String *) {assert(0);}
-   virtual void visit(Const *) {assert(0);}
-   virtual void visit(Array *) {assert(0);}
-   virtual void visit(Blob *) {assert(0);}
+    virtual void visit(Null *);
+    virtual void visit(Bool *);
+    virtual void visit(SInt *);
+    virtual void visit(UInt *);
+    virtual void visit(Float *);
+    virtual void visit(String *);
+    virtual void visit(Enum *);
+    virtual void visit(Bitmask *);
+    virtual void visit(Struct *);
+    virtual void visit(Array *);
+    virtual void visit(Blob *);
+    virtual void visit(Pointer *);
+
+protected:
+    inline void _visit(Value *value) {
+        if (value) { 
+            value->visit(*this); 
+        }
+    }
 };
 
 
@@ -223,22 +312,32 @@ unsigned long long asUInt(const Value &node);
 double asFloat(const Value &node);
 
 
-typedef std::pair<std::string, Value *> Arg;
-
 class Call
 {
 public:
-   std::string name;
-   std::list<Arg> args;
-   Value *ret;
-
-   Call() : ret(0) { }
-
-   Value & arg(const char *name);
+    struct Signature {
+        std::string name;
+        std::vector<std::string> arg_names;
+    };
+
+    unsigned no;
+    const Signature *sig;
+    std::vector<Value *> args;
+    Value *ret;
+
+    Call(Signature *_sig) : sig(_sig), args(_sig->arg_names.size()), ret(0) { }
+    ~Call();
+
+    inline const std::string name(void) const {
+        return sig->name;
+    }
+
+    inline Value & arg(unsigned index) {
+        return *(args[index]);
+    }
 };
 
 
-
 std::ostream & operator <<(std::ostream &os, Call &call);