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. using CMap

using CMap

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structuresworkspace
14 Posts 6 Posters 2 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.
  • L laiju

    I have declared the following in my application. "CMap < CString,LPCSTR,CWnd*,CWnd* > m_map" I have a windows explorer like setup. When i click a node in the tree i need to display an MDI Window. So i have mapped the node item's text (LPCSTR) to that of the window pointer .So when i click a node i use CMap to get the window pointer and display the window. Now when i alternatively click the windows i get the window pointer and i want to correspondingly shift the focus on the tree items. So my question is how do i look up the key ( i.e LPCSTR) when i have the value (i.e.. CWnd*). . laiju

    C Offline
    C Offline
    Christian Graus
    wrote on last edited by
    #3

    Is there any reason you're using CMap instead of map, in the C++ standard library ? CMap, CList, CArray,etc. were all written only as a stopgap until the stl came online. They are really crappy in comparison. You need to build a second map that goes the other way. Even if you iterate through the keys collection, checking for the value ( which is a very lousy thing to have to do ), there's no guarentee that your value appears only once, so there's no guarentee you'll find the right key. Christian Graus - Microsoft MVP - C++

    1 Reply Last reply
    0
    • L laiju

      I have declared the following in my application. "CMap < CString,LPCSTR,CWnd*,CWnd* > m_map" I have a windows explorer like setup. When i click a node in the tree i need to display an MDI Window. So i have mapped the node item's text (LPCSTR) to that of the window pointer .So when i click a node i use CMap to get the window pointer and display the window. Now when i alternatively click the windows i get the window pointer and i want to correspondingly shift the focus on the tree items. So my question is how do i look up the key ( i.e LPCSTR) when i have the value (i.e.. CWnd*). . laiju

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #4

      You'll need to iterate through all keys and check if each key's value matches the CWnd* you're searching for. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

      C 1 Reply Last reply
      0
      • R Ravi Bhavnani

        You'll need to iterate through all keys and check if each key's value matches the CWnd* you're searching for. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #5

        But that only works if each CWnd is only in there once. And it's damn ugly. Christian Graus - Microsoft MVP - C++

        R 1 Reply Last reply
        0
        • C Christian Graus

          But that only works if each CWnd is only in there once. And it's damn ugly. Christian Graus - Microsoft MVP - C++

          R Offline
          R Offline
          Ravi Bhavnani
          wrote on last edited by
          #6

          True. What he really needs is a multimap. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

          C 1 Reply Last reply
          0
          • R Ravi Bhavnani

            True. What he really needs is a multimap. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #7

            Does multimap let you search the values ? Christian Graus - Microsoft MVP - C++

            R 1 Reply Last reply
            0
            • C Christian Graus

              Does multimap let you search the values ? Christian Graus - Microsoft MVP - C++

              R Offline
              R Offline
              Ravi Bhavnani
              wrote on last edited by
              #8

              Sorry, I meant a bi-directional map, not a multi-map. :-O /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

              P 1 Reply Last reply
              0
              • R Ravi Bhavnani

                Sorry, I meant a bi-directional map, not a multi-map. :-O /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

                P Offline
                P Offline
                PJ Arends
                wrote on last edited by
                #9

                I have used map and multimap, and read about but never used hash_map and hash_multimap. What exactly do you mean by a bi-directional map? I always thought bi-directional containers were containers that had both forward and reverse iterators, but that definition does not seem to be what is being discussed here. What I think you mean is a map where both the key and value are unique, and has a find() member that can find either the key or the value. Is there such a beast? If so what is it called and where can I get it? Currently I am just using a map for this functionality, I check to make sure the value is unique before I add a new value to the map, and I sequentially iterate the map, comparing values, until I find the keyvalue I am looking for. If there is a better implementation out there I would be interested in learning about it.


                "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" - mYkel - 21 Jun '04 "There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05 Within you lies the power for good - Use it!

                R 1 Reply Last reply
                0
                • L laiju

                  I have declared the following in my application. "CMap < CString,LPCSTR,CWnd*,CWnd* > m_map" I have a windows explorer like setup. When i click a node in the tree i need to display an MDI Window. So i have mapped the node item's text (LPCSTR) to that of the window pointer .So when i click a node i use CMap to get the window pointer and display the window. Now when i alternatively click the windows i get the window pointer and i want to correspondingly shift the focus on the tree items. So my question is how do i look up the key ( i.e LPCSTR) when i have the value (i.e.. CWnd*). . laiju

                  M Offline
                  M Offline
                  Maximilien
                  wrote on last edited by
                  #10

                  a tought ... if the strings are unique, make a map that points to ( a pointer to ) a structure containing a CWnd and a HTREEITEM when you create the CWnd, attach the structure to the CWnd ( as a member of the class ) when you create the Tree Item, attach the structure to the Item ( CTreeCtrl::SetItemData ) when you click on the window, you can find exactly which item to highlight; and when you click on the tree item you have the pointer to the CWnd.


                  Maximilien Lincourt Your Head A Splode - Strong Bad

                  1 Reply Last reply
                  0
                  • P PJ Arends

                    I have used map and multimap, and read about but never used hash_map and hash_multimap. What exactly do you mean by a bi-directional map? I always thought bi-directional containers were containers that had both forward and reverse iterators, but that definition does not seem to be what is being discussed here. What I think you mean is a map where both the key and value are unique, and has a find() member that can find either the key or the value. Is there such a beast? If so what is it called and where can I get it? Currently I am just using a map for this functionality, I check to make sure the value is unique before I add a new value to the map, and I sequentially iterate the map, comparing values, until I find the keyvalue I am looking for. If there is a better implementation out there I would be interested in learning about it.


                    "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" - mYkel - 21 Jun '04 "There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05 Within you lies the power for good - Use it!

                    R Offline
                    R Offline
                    Ravi Bhavnani
                    wrote on last edited by
                    #11

                    PJ Arends wrote: What I think you mean is a map where both the key and value are unique, and has a find() member that can find either the key or the value. Yes, exactly. PJ Arends wrote: If so what is it called and where can I get it? I don't know. I'm tempted to write one, but I doubt I'll come up with anything revolutionary (i.e. very efficient). A hashmap of pairs, with uniqueness enforced on values is what comes to mind. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

                    P 1 Reply Last reply
                    0
                    • R Ravi Bhavnani

                      PJ Arends wrote: What I think you mean is a map where both the key and value are unique, and has a find() member that can find either the key or the value. Yes, exactly. PJ Arends wrote: If so what is it called and where can I get it? I don't know. I'm tempted to write one, but I doubt I'll come up with anything revolutionary (i.e. very efficient). A hashmap of pairs, with uniqueness enforced on values is what comes to mind. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

                      P Offline
                      P Offline
                      PJ Arends
                      wrote on last edited by
                      #12

                      Thanks Ravi. I thought you were refering to an already existing implementation that I did not know about. I guess I have to stick to my home-brewed hack.


                      "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" - mYkel - 21 Jun '04 "There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05 Within you lies the power for good - Use it!

                      J 1 Reply Last reply
                      0
                      • P PJ Arends

                        Thanks Ravi. I thought you were refering to an already existing implementation that I did not know about. I guess I have to stick to my home-brewed hack.


                        "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" - mYkel - 21 Jun '04 "There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05 Within you lies the power for good - Use it!

                        J Offline
                        J Offline
                        Joaquin M Lopez Munoz
                        wrote on last edited by
                        #13

                        An off-the-sheld bidirectional map is provided here[^]; unfortunately, it doesn't work with MSVC 7.1. For a more comprehensive solution, allow me to suggest you take a look at the Boost Multi-index Containers Library[^], which enables the construction of bidirectional maps and more. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo Want a Boost forum in Code Project? Vote here[^]!

                        P 1 Reply Last reply
                        0
                        • J Joaquin M Lopez Munoz

                          An off-the-sheld bidirectional map is provided here[^]; unfortunately, it doesn't work with MSVC 7.1. For a more comprehensive solution, allow me to suggest you take a look at the Boost Multi-index Containers Library[^], which enables the construction of bidirectional maps and more. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo Want a Boost forum in Code Project? Vote here[^]!

                          P Offline
                          P Offline
                          PJ Arends
                          wrote on last edited by
                          #14

                          Thanks Joaquín, your CP article looks interesting. I will DL the code and play with it to see if it fits my needs:)


                          "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" - mYkel - 21 Jun '04 "There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05 Within you lies the power for good - Use it!

                          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