Need template for list of name/value pairs

Discussion in 'C++' started by Woodster, Oct 29, 2003.

  1. Woodster

    Woodster Guest

    Further to a question I posted here recently about coding an xml rpeort
    parser, I need to use a list of name/value pairs, in this case, a list
    property names and values for a given tag.

    Rather than deriving a linked list class and adding in 2 char * to the
    derived class, I have decided to try and start using templates howver
    not having used templates before I do not know where to start.
    Unfortunately time is not on my side and I was hoping someone could give
    me a quick kick start with how to declare such a template.

    Deriving from my own base list and list element classes is obviously an
    easy task however I would like to start using templates at some point
    and this would be something easy to get me started.

    Any help or pointers would be rgeatly appreciated.

    Thanks in advance
    Woodster, Oct 29, 2003
    #1
    1. Advertising

  2. Woodster

    Jerry Coffin Guest

    In article <>, mirror@
    127.0.0.1 says...
    > Further to a question I posted here recently about coding an xml rpeort
    > parser, I need to use a list of name/value pairs, in this case, a list
    > property names and values for a given tag.


    It sounds to me like you want a multimap of maps of pairs of strings.

    --
    Later,
    Jerry.

    The universe is a figment of its own imagination.
    Jerry Coffin, Oct 29, 2003
    #2
    1. Advertising

  3. Woodster

    Woodster Guest

    In article <bnn52h$q55$01$-online.com>,
    says...
    > Any reason to not use a standard class, like
    > std::map<std::string, std::string> ?


    No - no reason not to. Just having not used templates at all before
    previously I am looking for pointers to a crash course in how to get
    templates to do what I am after.

    Regards

    Woodster
    Woodster, Oct 29, 2003
    #3
  4. Woodster

    Woodster Guest

    In article <>,
    says...
    > In article <>, mirror@
    > 127.0.0.1 says...
    > > Further to a question I posted here recently about coding an xml rpeort
    > > parser, I need to use a list of name/value pairs, in this case, a list
    > > property names and values for a given tag.

    >
    > It sounds to me like you want a multimap of maps of pairs of strings.


    Well, I have a list of tags that I need to parse, and each of these tags
    can have it's own individual properties as well as standard properties
    that will apply to every tag.

    Regards

    Woodster
    Woodster, Oct 29, 2003
    #4
  5. Woodster

    Chris Theis Guest

    "Woodster" <mirror@127.0.0.1> wrote in message
    news:...
    > In article <bnn52h$q55$01$-online.com>,
    > says...
    > > Any reason to not use a standard class, like
    > > std::map<std::string, std::string> ?

    >
    > No - no reason not to. Just having not used templates at all before
    > previously I am looking for pointers to a crash course in how to get
    > templates to do what I am after.
    >
    > Regards
    >
    > Woodster


    Any decent C++ book (non extensive e.g. Accelerated C++, TC++L, Thinking
    C++,...) should cover the map/multimap classes you're looking for. Otherwise
    I'd strongly recommend "The C++ standard library" by Nicolai Josuttis.

    Regards
    Chris
    Chris Theis, Oct 29, 2003
    #5
  6. Woodster

    Rolf Magnus Guest

    Woodster wrote:

    > Further to a question I posted here recently about coding an xml
    > rpeort parser, I need to use a list of name/value pairs, in this case,
    > a list property names and values for a given tag.
    >
    > Rather than deriving a linked list class and adding in 2 char * to the
    > derived class, I have decided to try and start using templates howver
    > not having used templates before I do not know where to start.
    > Unfortunately time is not on my side and I was hoping someone could
    > give me a quick kick start with how to declare such a template.
    >
    > Deriving from my own base list and list element classes is obviously
    > an easy task however I would like to start using templates at some
    > point and this would be something easy to get me started.
    >
    > Any help or pointers would be rgeatly appreciated.


    Any reason to not use a standard class, like
    std::map<std::string, std::string> ?
    Rolf Magnus, Oct 30, 2003
    #6
  7. Woodster

    Woodster Guest

    In article <>,
    says...
    > Okay, so what do you need help with?
    >
    > A map will allow you to specify one piece of data as a key, and another
    > piece of data that's associated with that key. A multimap is the same,
    > except that a single key can have an arbitrary number of pieces of data
    > associated with it.
    >
    > It sounds to me like your problem maps to this fairly easily. What
    > attempted so far, and what problems have arisen?


    At the moment I have just placded the tags in the code where I needed
    them and just did a comparison against that. The problem with this is
    that it makes adding new tags more complicated as I need to add tags to
    more than one place. I wanted to use the mapping so I had one central
    list of tags.

    Rather than base everything on a linked list, I thought now would be a
    good time to start using templates and was chasing a kick in the right
    direction which seems to be that I need to use std::map.

    All I need now is to do a bit of internet searching for hints and tips
    on exactly where to start with std::map
    Woodster, Oct 31, 2003
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. I R BABOON
    Replies:
    0
    Views:
    305
    I R BABOON
    Oct 21, 2003
  2. TR
    Replies:
    3
    Views:
    1,201
  3. =?Utf-8?B?RGlmZmlkZW50?=
    Replies:
    3
    Views:
    815
    Juan T. Llibre
    May 13, 2005
  4. Replies:
    1
    Views:
    1,622
    Bjorn Abelli
    Apr 24, 2006
  5. Replies:
    5
    Views:
    11,709
    Dimitri Maziuk
    Jun 8, 2006
Loading...

Share This Page