string's class question

Discussion in 'C++' started by Nephi Immortal, Sep 9, 2011.

  1. I was curious to examine Microsoft’s source code. The headers are
    string, xmemory, and xutility. I could see container class and proxy
    class. They inherit into _String_val and _String_val inherits into
    basic_string.
    Why are several classes needed? Why not create single basic_string
    class? Look at Microsoft’s code here.

    struct _Container_base12;
    struct _Iterator_base12;

    // CLASS _Container_proxy
    struct _Container_proxy
    { // store head of iterator chain and back pointer
    _Container_proxy()
    : _Mycont(0), _Myfirstiter(0)
    { // construct from pointers
    }

    const _Container_base12 *_Mycont;
    _Iterator_base12 *_Myfirstiter;
    };

    struct _CRTIMP2_PURE _Container_base12
    { // store pointer to _Container_proxy
    public:
    _Container_base12()
    : _Myproxy(0)
    { // construct childless container
    }

    _Container_base12(const _Container_base12&)
    : _Myproxy(0)
    { // copy a container
    }

    _Container_base12& operator=(const _Container_base12&)
    { // assign a container
    return (*this);
    }

    ~_Container_base12()
    { // destroy the container
    _Orphan_all();
    }

    _Iterator_base12 **_Getpfirst() const
    { // get address of iterator chain
    return (_Myproxy == 0 ? 0 : &_Myproxy->_Myfirstiter);
    }

    void _Orphan_all(); // orphan all iterators
    void _Swap_all(_Container_base12&); // swap all iterators

    _Container_proxy *_Myproxy;
    };
     
    Nephi Immortal, Sep 9, 2011
    #1
    1. Advertising

  2. Nephi Immortal

    Bo Persson Guest

    Nephi Immortal wrote:
    > I was curious to examine Microsoft’s source code. The headers are
    > string, xmemory, and xutility. I could see container class and
    > proxy class. They inherit into _String_val and _String_val
    > inherits into basic_string.
    > Why are several classes needed? Why not create single basic_string
    > class? Look at Microsoft’s code here.
    >
    > struct _Container_base12;
    > struct _Iterator_base12;
    >
    > // CLASS _Container_proxy
    > struct _Container_proxy
    > { // store head of iterator chain and back pointer
    > _Container_proxy()
    >> _Mycont(0), _Myfirstiter(0)

    > { // construct from pointers
    > }
    >
    > const _Container_base12 *_Mycont;
    > _Iterator_base12 *_Myfirstiter;
    > };
    >
    >


    That looks like code used for iterator debugging in debug mode.
    Putting it in a base class perhaps help sharing this code with other
    containers?

    Anyway, this is just an implementation detail that doesn't matter
    much. A library is allowed to organize the code the way it wants to.


    Bo Persson
     
    Bo Persson, Sep 10, 2011
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mladen Adamovic
    Replies:
    0
    Views:
    767
    Mladen Adamovic
    Dec 4, 2003
  2. Purush
    Replies:
    4
    Views:
    1,730
    Purush Rudrakshala
    Apr 13, 2005
  3. E11
    Replies:
    1
    Views:
    4,900
    Thomas Weidenfeller
    Oct 12, 2005
  4. christopher diggins
    Replies:
    16
    Views:
    774
    Pete Becker
    May 4, 2005
  5. Joseph Turian
    Replies:
    5
    Views:
    615
Loading...

Share This Page