🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #1929

Extended typeinfo (was- dyn

#1929
From: Bill Gibbons
Date: Fri, 08 Sep 1995 21:42
86 lines
3985 bytes
(Etay Bogner wrote about using dynamic_cast to cast to a type described
only by a type_info object, without use of static type information.)

What you want would be better provided as a part of an extended_type_info
class.  For example, with Taligent's proposed extended_type_info you
could write:

     struct B { virtual void f(); };
     struct D : B { };
     const extended_type_info &btype =
         dynamic_cast<const extended_type_info &>(typeid(B));
     const extended_type_info &dtype =
         dynamic_cast<const extended_type_info &>(typeid(D))

     void f() {
         B *b = new D;
         void *d = dtype.do_dynamic_cast(b, btype);
    }

The idea being that an object can be managed using a void pointer together
with a type_info object describing the object, without any static typing
at all.

The proposed extended_type_info is given below.  Since RTTI itself was
added to the language by the standards committee, it was felt that adding
extended type information was way beyond the scope of the committee's
charter.  So Taligent is advocating a defacto standard for extended type
information, by informal agreement among the compiler vendors.

Taligent's compiler implements an earlier very rough version of this
class (we expect to clean it up before releasing the compiler).  Some other
vendors have shown some interest in providing similar functionality.  And
some provide radically different extended type info.

---------------------------------------------------------------------------

     class extended_type_info : public type_info {
     public:
        ~extended_type_info();
        size_t size() const;

        enum Access { gNone, gPublic, gProtected, gPrivate };

        void *create(void *at) const;                // single object
        void *create(void *at, size_t count) const;  // array
        Access createAccess() const;  // default constructor access

        void *copy(void *to, void *from) const;               // single object
        void *copy(void *to, void *from, size_t count) const; // array
        Access copyAccess() const;    // copy constructor access

        void destroy(void *at) const;                // single object
        void destroy(void *at, size_t count) const;  // array
        Access destroyAccess() const; // destructor access

        void *do_dynamic_cast(void *from, extended_type_info &fromType) const;
        void do_throw(void *value) const;         // throw an exception

     protected:
        extended_type_info(const extended_type_info&);
        extended_type_info& operator=(const extended_type_info&);

     private:
        // May of course vary between implementations.
        size_t fsize;
        void (*fDefaultConstructor)();
        void (*fCopyConstructor)();
        void (*fDestructor)();
        Access fDefaultConstructorAccess;
        Access fCopyConstructorAccess;
        Access fDestructorAccess;
        // Even more implementation-specific things.
        unsigned long fOffsetToVtablePointer;
        unsigned short fNumberOfVbasePointerConstructorArguments;
        void *VLDVTT;  // a.k.a. construction-time vtable table
        unsigned short flags;  // misc. exception handling flags
     };

----------------------------------------------------------------------------

Bill Gibbons
bgibbons@taligent.com
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <n1401567773.54923@taligent.com>
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
Date: 08 Sep 95 21:42:45 GMT
Approved: fjh@cs.mu.oz.au
Organization: -
Newsgroups: comp.std.c++
Message-ID: <n1401567773.54923@taligent.com>
X-Original-Date: 8 Sep 1995 10:03:37 -0800
From: "Bill Gibbons" <bill_gibbons@taligent.com>
Subject: Extended typeinfo (was- dyn
X-Mailer: Mail*Link SMTP-QM 3.0.2