Results 1 to 8 of 8

Thread: String class

  1. #1

    Thread Starter
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    String class

    I'm working on an extended string class (derived from STL string). What features do you think it should support?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    I don't think you can derive from it (no virtual destructor).

    You'd have to implement it as an adapter.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    hmmmm... true, that's what I don't like about the standard library...

    What's an adapter?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    It's like that for efficiency reasons (similar to a final Java class), and you wouldn't normally want to derive from the standard containers.

    An adapter extends or alters the functionality by compositing an object inside another. Take a look at the source to stack<>, I think that internally uses deque<> to handle the allocation.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5

    Thread Starter
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I see.
    But since my own destructor does nothing (~WString(){}), does it matter?
    WString& destructed -> ~WString() called -> ~tstring called
    tstring& destructed -> ~tstring called

    Since ~WString does nothing, do I loose anything? Or does the destructor do some secret things I don't know about?

    Oh, tstring is defined like this:
    #ifdef UNICODE
    typedef wchar_t tchar_t;
    #else
    typedef char tchar_t;
    #endif
    typedef basic_string<tchar_t> tstring;



    I think final Java classes exist mainly for security reasons - so that no one can derive a class and manipulate behaviour.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Whether a particular implementation does anything "secret" in its destructor is up to the implementer, and you can't rely on it.

    I don't know completely what the standard says about the string class, but I definitely know you can't derive from the standard containers.

    What sort of functionality were you thinking of adding?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7

    Thread Starter
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Functions that do nice things. Search, Strip, Trim, all those things. Maybe RegExp capability.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Well, it's already got find, but trim is a good one to have.

    For regexps, see those boost classes www.boost.org
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width