Though implementation problem

This is a discussion on Though implementation problem within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by Elysia No, it's not the interface per se that's the problem, but the internal mechanisms. And it ...

  1. #121
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Quote Originally Posted by Elysia View Post
    No, it's not the interface per se that's the problem, but the internal mechanisms.
    And it should be Replace(What, With, Start, End).
    How you compare if a subsequence is equal to "what"?
    And why do you need start/end?

  2. #122
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,624
    Quote Originally Posted by manav View Post
    How you compare if a subsequence is equal to "what"?
    Subsequence equal to what?

    And why do you need start/end?
    If you only want to perform and search and replace within a specific region.
    However, there will also be overloads that doesn't take start or begin (will perform search & replace on whole string).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #123
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Replace is the public interface of the free function that you should call to do the work.
    Then they will wrap ReplaceInternal that will do the actual replacing.
    But ReplaceInternal shouldn't be called directly because 1) it takes a bool that should not be passed directly and 2) it has only one version - the one that takes a range. Therefore ReplaceInternal should be hidden away from prying eyes, but since it's free it cannot.
    It has become an accepted convention to put implementation details in a sub-namespace called detail. Users know to stay away from those.

    Code:
    namespace mystuff
    {
      namespace detail
      {
        // Implementation details here.
      }
    
      // Interface stuff here.
    }
    True, the compiler doesn't actually enforce this, but accidentally typing 'detail::' does not sound plausible to me.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #124
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Quote Originally Posted by Elysia View Post
    Subsequence equal to what?
    If I understand you right, then you probably want to replace "This" with "That" in following sentence:
    "This is a tree."
    Right?

    So if in your example Replace(what, with, start, end):
    what - "This"
    with - "That"
    Then how will your generic solution compare if the sequence to be replaced is actually equal to "This", which is not a single word, but, generically speaking, a sequence of elements.

    How will you compare such sequence within the destination sequence, which needs the replacement!?!

    I am speaking generically! Reusable ofcourse!!

    Other wise forget the bling-bling-blah!
    And, just think, how to replace words within a string, in simple yet efficient manner!

    If you only want to perform and search and replace within a specific region.However, there will also be overloads that doesn't take start or begin (will perform search & replace on whole string).
    Extra features never hurt! Make them some default arguments! So I need not concern myself with them!

  5. #125
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,624
    Quote Originally Posted by manav View Post
    If I understand you right, then you probably want to replace "This" with "That" in following sentence:
    "This is a tree."
    Right?

    So if in your example Replace(what, with, start, end):
    what - "This"
    with - "That"
    Then how will your generic solution compare if the sequence to be replaced is actually equal to "This", which is not a single word, but, generically speaking, a sequence of elements.

    How will you compare such sequence within the destination sequence, which needs the replacement!?!

    I am speaking generically! Reusable ofcourse!!

    Other wise forget the bling-bling-blah!
    And, just think, how to replace words within a string, in simple yet efficient manner!
    Err hello? How it a problem to replace a string? We've done that a hundred times and that implementation is already done. A long time ago.

    Extra features never hurt! Make them some default arguments! So I need not concern myself with them!
    Yes, also unfortunately, the C++ standard forbids initializing default arguments with a non-static value (I think I'm getting this right), and also references must be initialized with a const value.

    So,
    Code:
    void foo(int i = 0); // OK, constant
    
    class cfoo
    {
        int some_member;
        void foo(int i = some_member); // Illegal, not static
    };
    Therefore, I overloaded the function:
    Code:
    void Replace(const CTmplStringBase& strReplaceWhat,
        const CTmplStringBase& strReplaceWith);
    void Replace(const CTmplStringBase& strReplaceWhat,
        const CTmplStringBase& strReplaceWith, const const_iterator& vStart);
    void Replace(const CTmplStringBase& strReplaceWhat, const CTmplStringBase& 
        strReplaceWith, const const_iterator& vStart, const const_iterator& vEnd);
    You can choose whichever version suits you best.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #126
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Quote Originally Posted by Elysia View Post
    Err hello? How it a problem to replace a string? We've done that a hundred times and that implementation is already done. A long time ago.
    So you are not writing a single generic function that could replace any sequence with another sequence? Ok never mind.

    Yes, also unfortunately, the C++ standard forbids initializing default arguments with a non-static value (I think I'm getting this right), and also references must be initialized with a const value.
    Code:
    void Replace(const CTmplStringBase& strReplaceWhat,
        const CTmplStringBase& strReplaceWith);
    void Replace(const CTmplStringBase& strReplaceWhat,
        const CTmplStringBase& strReplaceWith, const const_iterator& vStart);
    void Replace(const CTmplStringBase& strReplaceWhat, const CTmplStringBase& 
        strReplaceWith, const const_iterator& vStart, const const_iterator& vEnd);
    You can choose whichever version suits you best.
    Thanks for you efforts. I just want to do this:
    Code:
    CStringEx("This is ${NAME}!").Replace("${NAME}", getName());

  7. #127
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,624
    Quote Originally Posted by manav View Post
    So you are not writing a single generic function that could replace any sequence with another sequence? Ok never mind.
    I don't know what you're on about.

    Code:
    Strings::CStringEx str = "This is a tree";
    cout << str << endl; // This is a tree
    str.Replace("This", "That");
    cout << str << endl; // That is a tree
    Thanks for you efforts. I just want to do this:
    Code:
    CStringEx("This is ${NAME}!").Replace("${NAME}", getName());
    Don't worry - you have it!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #128
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Quote Originally Posted by Elysia View Post
    I don't know what you're on about.
    Well replacing (as in the real meaning), is easy, but only if the "with" is equal in length to "what".
    Otherwise see this string:
    CStringEx str("Name: {1}\nOver draft {2}\nInterest {3}\n");
    and this Replace usage:
    Code:
    str.Replace("{1}", "Elysia Petralovech");
    str.Replace("{2}", "7500.50");
    str.Replace("{3}", "250.50");
    Do you see, that, every replacement is increasing the string size?
    And do you also see that this is basically a sub-sequence insertion over the deletion?

    Does that sound a generic solution bell?

    May be a generic == operator also, which can compare sub-sequences and return start/end iterator pair?

    // I think they have brain washed me more than enough, boy, I am also thinking generically now!!!

  9. #129
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,624
    My implementation does move around to make room.
    Code:
    Strings::CStringEx str = "{1} is a tree";
    cout << str << endl; // {1} is a tree
    str.Replace("{1}", "That");
    cout << str << endl; // That is a tree
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #130
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Quote Originally Posted by Elysia View Post
    My implementation does move around to make room.
    Code:
    Strings::CStringEx str = "{1} is a tree";
    cout << str << endl; // {1} is a tree
    str.Replace("{1}", "That");
    cout << str << endl; // That is a tree
    Of course your implementation does/would have it! I was just asking, that, are you doing it for strings only, or for any kind of sequences?

    Anyway, never mind now! I am just waiting for your first Alpha release

  11. #131
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,624
    It would work with any given type, but it only works on a element basis.
    You can't expect a sequence of values to be treated as one value or element.
    Boost isn't letting me define a proper return type for my operators -/+...
    After that... well... Well, after that's over and done with, I guess major testing is due.
    Then I could release an alpha.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #132
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Quote Originally Posted by Elysia View Post
    It would work with any given type, but it only works on a element basis.
    You can't expect a sequence of values to be treated as one value or element.
    I got it (I was thinking something similar).
    Boost isn't letting me define a proper return type for my operators -/+...
    After that... well... Well, after that's over and done with, I guess major testing is due.
    I understand the '+', but what is '-' for?

    Would you enable this in your string class?
    Code:
    CStringEx str;
    int age = 23;
    float cm = 167.1f;
    str << "She is " << age << " years old, " << cm << " centimeter high!" << endl;

  13. #133
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,624
    [
    Quote Originally Posted by manav View Post
    I understand the '+', but what is '-' for?
    Iterators.
    Iter1 + Iter2
    OR
    Iter1 - Iter2
    I really need to implement a range iterator here or some such. A lot of thinking left there.

    Quote Originally Posted by manav View Post
    Would you enable this in your string class?
    Code:
    CStringEx str;
    int age = 23;
    float cm = 167.1f;
    str << "She is " << age << " years old, " << cm << " centimeter high!" << endl;
    No, but this would work:
    Code:
    CStringEx str;
    int age = 23;
    float cm = 167.1f;
    str = "She is "+ age + " years old, " + cm + " centimeter high!";
    cout << str << endl;
    Or rather, float and doubles don't work. At least not yet, but maybe in the future. But integers works.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #134
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Quote Originally Posted by Elysia View Post
    Iterators.
    Iter1 + Iter2
    OR
    Iter1 - Iter2
    I really need to implement a range iterator here or some such. A lot of thinking left there.
    Ok got it

    No, but this would work:
    Code:
    CStringEx str;
    int age = 23;
    float cm = 167.1f;
    str = "She is "+ age + " years old, " + cm + " centimeter high!";
    cout << str << endl;
    Or rather, float and doubles don't work. At least not yet, but maybe in the future. But integers works.
    That's even better! I already feel like being in heaven!
    Release your implementation pretty soon!!

  15. #135
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,624
    A lot of linking errors for VS + two operator problems + testing left.
    Last edited by Elysia; 05-13-2008 at 07:29 AM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  2. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 05:24 PM
  3. implementation file
    By bejiz in forum C++ Programming
    Replies: 5
    Last Post: 11-28-2005, 12:59 AM
  4. Replies: 5
    Last Post: 11-07-2005, 10:34 PM
  5. Memory Problem - I think...
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 10-24-2001, 12:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21