Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Need template for list of name/value pairs

Reply
Thread Tools

Need template for list of name/value pairs

 
 
Woodster
Guest
Posts: n/a
 
      10-29-2003
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
 
Reply With Quote
 
 
 
 
Jerry Coffin
Guest
Posts: n/a
 
      10-29-2003
In article <(E-Mail Removed)> , 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.
 
Reply With Quote
 
 
 
 
Woodster
Guest
Posts: n/a
 
      10-29-2003
In article <bnn52h$q55$01$(E-Mail Removed)-online.com>, http://www.velocityreviews.com/forums/(E-Mail Removed)
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
 
Reply With Quote
 
Woodster
Guest
Posts: n/a
 
      10-29-2003
In article <(E-Mail Removed) et>,
(E-Mail Removed) says...
> In article <(E-Mail Removed)> , 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
 
Reply With Quote
 
Chris Theis
Guest
Posts: n/a
 
      10-29-2003

"Woodster" <mirror@127.0.0.1> wrote in message
news:(E-Mail Removed) u...
> In article <bnn52h$q55$01$(E-Mail Removed)-online.com>, (E-Mail Removed)
> 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


 
Reply With Quote
 
Rolf Magnus
Guest
Posts: n/a
 
      10-30-2003
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> ?

 
Reply With Quote
 
Woodster
Guest
Posts: n/a
 
      10-31-2003
In article <(E-Mail Removed) t>,
(E-Mail Removed) 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pairs from a list Alan Isaac Python 31 01-24-2008 05:57 AM
intersection of 2 list of pairs les_ander@yahoo.com Python 7 02-22-2005 11:30 PM
list comprehension for splitting strings into pairs Steven Bethard Python 5 10-14-2004 07:10 PM
all pairs of items in a list without indexing? Steven Bethard Python 12 09-29-2004 05:16 PM
Re: all pairs of items in a list without indexing? Michael Sparks Python 2 09-29-2004 01:50 PM



Advertisments