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

Bidirectional CMap

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
12 Posts 6 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.
  • K Offline
    K Offline
    Konrad Windszus
    wrote on last edited by
    #1

    I need a map where I can find the value to a key and also a key to a value. Since I can't find any article on Codeproject regarding this issue, I ask this question here: Is there a simple solution to this? My idea was to simply use two CMaps: CMap<KEY, KEY&, VALUE, VALUE&> and CMap<VALUE, VALUE&, KEY, KEY&>. Is there a simpler approach? Thanks for any help. Konrad

    K RaviBeeR L 3 Replies Last reply
    0
    • K Konrad Windszus

      I need a map where I can find the value to a key and also a key to a value. Since I can't find any article on Codeproject regarding this issue, I ask this question here: Is there a simple solution to this? My idea was to simply use two CMaps: CMap<KEY, KEY&, VALUE, VALUE&> and CMap<VALUE, VALUE&, KEY, KEY&>. Is there a simpler approach? Thanks for any help. Konrad

      K Offline
      K Offline
      Kevin McFarlane
      wrote on last edited by
      #2

      This came up recently somewhere. I think someone may have posted a version at Boost. http://www.boost.org[^]. In the past I've just done as you've done. Ah, just done a search. See here http://www.boost.org/libs/multi_index/doc/examples.html#example4[^] Kevin

      K 1 Reply Last reply
      0
      • K Kevin McFarlane

        This came up recently somewhere. I think someone may have posted a version at Boost. http://www.boost.org[^]. In the past I've just done as you've done. Ah, just done a search. See here http://www.boost.org/libs/multi_index/doc/examples.html#example4[^] Kevin

        K Offline
        K Offline
        Konrad Windszus
        wrote on last edited by
        #3

        Isn't there a simple MFC class somewhere out there as extension to CMap, because I don't want to use the huge boost library? Konrad

        K J 2 Replies Last reply
        0
        • K Konrad Windszus

          Isn't there a simple MFC class somewhere out there as extension to CMap, because I don't want to use the huge boost library? Konrad

          K Offline
          K Offline
          Kevin McFarlane
          wrote on last edited by
          #4

          I've not come across one and yes I too am put of by the huge Boost library.:(( I vaguely recall coming across a simpler solution somewhere but I can't think where. Maybe on CodeGuru? Kevin

          N 1 Reply Last reply
          0
          • K Konrad Windszus

            Isn't there a simple MFC class somewhere out there as extension to CMap, because I don't want to use the huge boost library? Konrad

            J Offline
            J Offline
            jhwurmbach
            wrote on last edited by
            #5

            Konrad Windszus wrote: because I don't want to use the huge boost library? You probably can insert only the relevant classes into your project. Boost is all source code. I am doing so with the smart-pointer classes from boost. You will want to stay well clear of the MFC-containers, as the STL containers are better in all respects, and are well documented and portable.


            "We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation." -- Caius Petronius, Roman Consul, 66 A.D.

            K 1 Reply Last reply
            0
            • K Konrad Windszus

              I need a map where I can find the value to a key and also a key to a value. Since I can't find any article on Codeproject regarding this issue, I ask this question here: Is there a simple solution to this? My idea was to simply use two CMaps: CMap<KEY, KEY&, VALUE, VALUE&> and CMap<VALUE, VALUE&, KEY, KEY&>. Is there a simpler approach? Thanks for any help. Konrad

              RaviBeeR Offline
              RaviBeeR Offline
              RaviBee
              wrote on last edited by
              #6

              If you don't expect the number of keys to be very large, you could just write a simple function to do the latter (i.e. return the collection of keys that map to the value). /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

              1 Reply Last reply
              0
              • K Konrad Windszus

                I need a map where I can find the value to a key and also a key to a value. Since I can't find any article on Codeproject regarding this issue, I ask this question here: Is there a simple solution to this? My idea was to simply use two CMaps: CMap<KEY, KEY&, VALUE, VALUE&> and CMap<VALUE, VALUE&, KEY, KEY&>. Is there a simpler approach? Thanks for any help. Konrad

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Did you checked one of the best available source code here[^]

                K 1 Reply Last reply
                0
                • L Lost User

                  Did you checked one of the best available source code here[^]

                  K Offline
                  K Offline
                  Konrad Windszus
                  wrote on last edited by
                  #8

                  Thank you very much. I also found that article, after I posted my request. I already programmed my own CMap extension class, because I use MFC in my project (and therefore don't use STL, because I don't want to mix them). I will write an article about my extension class for codeproject when I have some free time. Regards Konrad

                  K 1 Reply Last reply
                  0
                  • K Kevin McFarlane

                    I've not come across one and yes I too am put of by the huge Boost library.:(( I vaguely recall coming across a simpler solution somewhere but I can't think where. Maybe on CodeGuru? Kevin

                    N Offline
                    N Offline
                    Neville Franks
                    wrote on last edited by
                    #9

                    Nearly all of Boost is in headers and it does not add lots of code to your app. The fact that it is large is irrelevant IMO. MFC and STL are also large. I would definitely recommend using STL and Boost wherever possible instead of the MFC Containers (which I used to use heavilly). Boost.MultiIndex will do what you want and it looks quite elegant. Of course you can use two CMap's or two STL map's but why would you want to. Make the move to STL and Boost and you'll never regret it.;) Neville Franks, Author of ED for Windows www.getsoft.com and Surfulater www.surfulater.com "Save what you Surf"

                    K 1 Reply Last reply
                    0
                    • N Neville Franks

                      Nearly all of Boost is in headers and it does not add lots of code to your app. The fact that it is large is irrelevant IMO. MFC and STL are also large. I would definitely recommend using STL and Boost wherever possible instead of the MFC Containers (which I used to use heavilly). Boost.MultiIndex will do what you want and it looks quite elegant. Of course you can use two CMap's or two STL map's but why would you want to. Make the move to STL and Boost and you'll never regret it.;) Neville Franks, Author of ED for Windows www.getsoft.com and Surfulater www.surfulater.com "Save what you Surf"

                      K Offline
                      K Offline
                      Kevin McFarlane
                      wrote on last edited by
                      #10

                      Neville Franks wrote: The fact that it is large is irrelevant IMO. Well, I've only comparatively recently moved from dial-up to broadband. With dial-up it just wasn't worth it. Now I've got broadband it's more psychological. Neville Franks wrote: I would definitely recommend using STL and Boost wherever possible instead of the MFC Containers (which I used to use heavilly). Recently I've been more focused on .NET,so I've not had much incentive to look into Boost. When I do get to do C++ it's invariably maintenance work on code that's barely heard of STL, yet alone Boost! (For that nmatter it's often barely heard of MFC's data structures!) I just don't think it would go down too well if I downloaded Boost just to do maintenance work. However, for new work or new extensions to MFC apps. I tend to go for STL containers nowadays. Still, I do intend to give Boost a try at some point. Kevin

                      1 Reply Last reply
                      0
                      • J jhwurmbach

                        Konrad Windszus wrote: because I don't want to use the huge boost library? You probably can insert only the relevant classes into your project. Boost is all source code. I am doing so with the smart-pointer classes from boost. You will want to stay well clear of the MFC-containers, as the STL containers are better in all respects, and are well documented and portable.


                        "We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation." -- Caius Petronius, Roman Consul, 66 A.D.

                        K Offline
                        K Offline
                        Kevin McFarlane
                        wrote on last edited by
                        #11

                        jhwurmbach wrote: You will want to stay well clear of the MFC-containers, as the STL containers are better in all respects, and are well documented and portable. If you're working on an MFC app. it's generally going to be non-portable anyway, so why is it important to use portable STL? I agree that the STL containers are better and I use them for that reason, not because they're portable. Kevin

                        1 Reply Last reply
                        0
                        • K Konrad Windszus

                          Thank you very much. I also found that article, after I posted my request. I already programmed my own CMap extension class, because I use MFC in my project (and therefore don't use STL, because I don't want to mix them). I will write an article about my extension class for codeproject when I have some free time. Regards Konrad

                          K Offline
                          K Offline
                          Kevin McFarlane
                          wrote on last edited by
                          #12

                          Konrad Windszus wrote: because I use MFC in my project (and therefore don't use STL, because I don't want to mix them). Why not? What's the problem? Kevin

                          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