Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. replace CMapStringToOb by standard C

replace CMapStringToOb by standard C

Scheduled Pinned Locked Moved C / C++ / MFC
c++businesstutorialquestion
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RedSonja
    wrote on last edited by
    #1

    I have inherited some old code. Our sadistic project management has decided to forbid use of MFC in the hope of being more portable. I replaced all the CStrings with string, now I have got some tricky parts left. The guy who wrote this used CMapStringToOb in what seems to be a very clever way and I think it is a fine piece of code. But I have to replace it - but with what? I can't use CObjects any more. I have things like this: CString csMsgID; pCommand SACommand; //(which is a CObject) CMapStringToOb m_knownCommands; m_knownCommands.Lookup((LPCTSTR)csMsgID, (CObject*&) pCommand) m_knownCommands.SetAt((LPCTSTR)csMsgID, apFba[i]); I suppose I could plod through and dream up something complicated and slow, but does anyone have an idea how to do this in an elegant manner? Is this what the type Object is for?

    ------------- Bibo ergo sum

    C 1 Reply Last reply
    0
    • R RedSonja

      I have inherited some old code. Our sadistic project management has decided to forbid use of MFC in the hope of being more portable. I replaced all the CStrings with string, now I have got some tricky parts left. The guy who wrote this used CMapStringToOb in what seems to be a very clever way and I think it is a fine piece of code. But I have to replace it - but with what? I can't use CObjects any more. I have things like this: CString csMsgID; pCommand SACommand; //(which is a CObject) CMapStringToOb m_knownCommands; m_knownCommands.Lookup((LPCTSTR)csMsgID, (CObject*&) pCommand) m_knownCommands.SetAt((LPCTSTR)csMsgID, apFba[i]); I suppose I could plod through and dream up something complicated and slow, but does anyone have an idea how to do this in an elegant manner? Is this what the type Object is for?

      ------------- Bibo ergo sum

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      RedSonja wrote:

      I have inherited some old code. Our sadistic project management has decided to forbid use of MFC in the hope of being more portable.

      I'm definitely not an MFC fan, anyway I think your management deserves a kick in the ass. Must you be stuck with C language or may you use C++? With C++, you may use STL containers. If you need to use only C, then I suppose you should search for a library offering hashing functions. :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      R 1 Reply Last reply
      0
      • C CPallini

        RedSonja wrote:

        I have inherited some old code. Our sadistic project management has decided to forbid use of MFC in the hope of being more portable.

        I'm definitely not an MFC fan, anyway I think your management deserves a kick in the ass. Must you be stuck with C language or may you use C++? With C++, you may use STL containers. If you need to use only C, then I suppose you should search for a library offering hashing functions. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        R Offline
        R Offline
        RedSonja
        wrote on last edited by
        #3

        Oh, yes, we can use STL containers. Which do you recommend? (I am not really lazy, but I do not usually program this high up in the food chain, and my boss wanted it done in December.)

        ------------- Bibo ergo sum

        C C 2 Replies Last reply
        0
        • R RedSonja

          Oh, yes, we can use STL containers. Which do you recommend? (I am not really lazy, but I do not usually program this high up in the food chain, and my boss wanted it done in December.)

          ------------- Bibo ergo sum

          C Offline
          C Offline
          Cedric Moonen
          wrote on last edited by
          #4

          I guess using a std::map would do the trick. The problem is that you won't be able to use CObject as a base class, but anyway it is quite ugly anyway. If all the objects in your map have the same base class, then it is fine. If your map needs to store different kind of objects, then probably you need to think the design a bit better...

          Cédric Moonen Software developer
          Charting control [v1.5] OpenGL game tutorial in C++

          1 Reply Last reply
          0
          • R RedSonja

            Oh, yes, we can use STL containers. Which do you recommend? (I am not really lazy, but I do not usually program this high up in the food chain, and my boss wanted it done in December.)

            ------------- Bibo ergo sum

            C Offline
            C Offline
            CPallini
            wrote on last edited by
            #5

            std::map< std::string, YourRootClass * >

            However, as already suggested by Cedric Moonen, maybe better to re-think a bit about the project design (I know it would require experience, time and effort) than mimic the MFC behaviour. :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
            [My articles]

            R 1 Reply Last reply
            0
            • C CPallini

              std::map< std::string, YourRootClass * >

              However, as already suggested by Cedric Moonen, maybe better to re-think a bit about the project design (I know it would require experience, time and effort) than mimic the MFC behaviour. :)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              R Offline
              R Offline
              RedSonja
              wrote on last edited by
              #6

              Hmm, you are quite right. Looking at the code a bit harder (I was scared off by CMapStringToOb looking so complicated) I can see he has nothing more than a list of objects derived from the same class, nothing more than that. So I can try with std::list and do the clever bits in a simpler way. I was hoping to avoid changing every single reference to the things (this is a very large amount of code), but it has to be done, and this week no-one is there to ask what I'm doing. I have redesigned this project quite a lot since it landed on my desk, and this is just about the last untouched corner.

              ------------- Bibo ergo sum

              C 1 Reply Last reply
              0
              • R RedSonja

                Hmm, you are quite right. Looking at the code a bit harder (I was scared off by CMapStringToOb looking so complicated) I can see he has nothing more than a list of objects derived from the same class, nothing more than that. So I can try with std::list and do the clever bits in a simpler way. I was hoping to avoid changing every single reference to the things (this is a very large amount of code), but it has to be done, and this week no-one is there to ask what I'm doing. I have redesigned this project quite a lot since it landed on my desk, and this is just about the last untouched corner.

                ------------- Bibo ergo sum

                C Offline
                C Offline
                Cedric Moonen
                wrote on last edited by
                #7

                RedSonja wrote:

                I can see he has nothing more than a list of objects derived from the same class, nothing more than that. So I can try with std::list and do the clever bits in a simpler way.

                It is a bit more complex than just a list. It is a map which associate each object to a key (being a string). No duplicate key can be found in the map. To begin working with a std::map, you can look at these tutorials: here[^] or here[^]. You can probably find hundreds of tutorials on the net if you google a bit.

                Cédric Moonen Software developer
                Charting control [v1.5] OpenGL game tutorial in C++

                R 1 Reply Last reply
                0
                • C Cedric Moonen

                  RedSonja wrote:

                  I can see he has nothing more than a list of objects derived from the same class, nothing more than that. So I can try with std::list and do the clever bits in a simpler way.

                  It is a bit more complex than just a list. It is a map which associate each object to a key (being a string). No duplicate key can be found in the map. To begin working with a std::map, you can look at these tutorials: here[^] or here[^]. You can probably find hundreds of tutorials on the net if you google a bit.

                  Cédric Moonen Software developer
                  Charting control [v1.5] OpenGL game tutorial in C++

                  R Offline
                  R Offline
                  RedSonja
                  wrote on last edited by
                  #8

                  Yes, I spotted the key, I need some of those too. Thank you for the tutorials, I shall have a look.

                  ------------- Bibo ergo sum

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups