ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> boost
boost
[boost] Re: Proven ptr<>
by David B. Held other posts by this author
Aug 12 2002 7:40PM messages near this date
Re: [boost] Re: Re: Proven ptr<> | [boost] Re: Re: Re: Proven ptr<>
"David Abrahams" <dave@[...].com>  wrote in message
news:042201c24229$3a13be60$6501a8c0@[...]..
>  [...]
>  I haven't been paying enough attention to your implementation details
>  to know whether a container is appropriate or neccessary, nor what
>  s_rectify is.

For those without the inclination to wade through the code, here is my
understanding of how Philipe's ptr<>  works:

class Base { };
class Derived : public Base { };

ptr<Derived>  pDerived;
// ptr<Derived> ::s_rectify[] = {0}

ptr<Base>  pBase(pDerived);
// ptr<Base> ::s_rectify[] = {0, 2}

The numbers in s_rectify are for illustration only.  The idea is that when
you access a polymorphic object, it computes the offset to return by
adding s_rectify to an internal pointer to the object, like so:

  element_type * get() const
  {
   return m_ptr + s_rectify[get_type_id()];
  }

However, this code is misleading, because s_rectify is a vector of
offsets, which means we need to consider this:

template <typename T> 
 inline T * operator + (T * p1, offset p2)
 {
  return reinterpret_cast<T *> (reinterpret_cast<char *>(p1) +
static_cast<int> (p2));
 }

So to see what get() is really doing, here is the expanded equivalent:

element_type * get() const
{
    return reinterpret_cast<T *> (
        reinterpret_cast<char *> (m_ptr) +
        static_cast<int> (s_rectify[get_type_id()])
    );
}

That looks to me like adding an integer offset to a char* to get at the
internals of a non-POD object.

In order to compute the offsets, he does this:

    s_rectify[...] = int(static_cast<T *> ((U *) 1) - offset(1));

Whether all this is conforming code I'll leave up to the language lawyers.

Dave





_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Thread:
Peter Dimov
Philippe A. Bouchard
David B. Held
David Abrahams
Philippe A. Bouchard
Philippe A. Bouchard
Greg Colvin
David B. Held
Philippe A. Bouchard
David Abrahams
David Abrahams
Philippe A. Bouchard
David Abrahams
Philippe A. Bouchard
Philippe A. Bouchard
Philippe A. Bouchard
Greg Colvin
Philippe A. Bouchard
Greg Colvin
Greg Colvin

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved