Need template for list of name/value pairs

W

Woodster

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
 
J

Jerry Coffin

mirror@ said:
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.
 
W

Woodster

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
 
W

Woodster

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
 
C

Chris Theis

Woodster said:
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
 
R

Rolf Magnus

Woodster said:
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> ?
 
W

Woodster

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top