471,078 Members | 856 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,078 software developers and data experts.

A problem with Nested Maps

Dear all,

I am trying to create a look-up table for a text search and replacement
class which will be used with a commercial software(MCS NASTRAN, I
guess you may have heard that before ).

I want to create a table like

vector<string> ===mapping=== (vector<string>, vector<int>)

more clearly, as an example:

GRID GRID 1
ID 2
CP 3
X1 4
X2 5
X3 6
CD 7
PS 8
SEID 9

Here there will be another entry like this

Field1 string1 int1
. .
. .
string9 int2

So I tried something with a nested map, but the problem is that(I
think) since the elements of a map are pairs and the keys of these
pairs are constant, I could not initialize that with the values I
wanted, take a look at:

map<vector<string>,map<vector<string>,vector<int> > > mapp;
map<vector<string>,map<vector<string>,vector<int> > >::iterator
iter_;
map<vector<string>,vector<int> >::iterator iter__;

iter_->first.push_back("GRID");
(iter_->second).(iter__->first.push_back("GRID"));
(iter_->second).(iter__->second.push_back(1));

Since my stl knowledge is limited, I need help from experienced
programmers.

Regards,

May 20 '06 #1
3 5529
sorry for the alingment of data fields

May 20 '06 #2
A map keyed on vector<string>? This does not sound like a good start.
Can you explain the problem in a little more detail? I could not really
infer anything from the two sample tables you presented. What exactly
are you trying to do?

May 20 '06 #3
"utab" <um********@gmail.com> schrieb im Newsbeitrag news:11**********************@j73g2000cwa.googlegr oups.com...
Dear all,

I am trying to create a look-up table for a text search and replacement
class which will be used with a commercial software(MCS NASTRAN, I
guess you may have heard that before ).

I want to create a table like

vector<string> ===mapping=== (vector<string>, vector<int>)

more clearly, as an example:

GRID GRID 1
ID 2
CP 3
X1 4
X2 5
X3 6
CD 7
PS 8
SEID 9

Here there will be another entry like this

Field1 string1 int1
. .
. .
string9 int2


Looks like you first need a map<string, int> to store pairs like (ID, 2), (CP, 3) ... That should be simple:

typedef std::map<std::string, int> MapStringToInt;

Then to map GRID to the first group of pairs, Field1 to the next group etc. you should use a map from string to MapStringToInt:

typedef std::map<std::string, MapStringToInt> MapStringToMap;

Now you can create a map to maps and populate it:

MapStringToMap metaMap;
metaMap["GRID"].insert(MapStringToInt::value_type("GRID", 1));
metaMap["GRID"].insert(MapStringToInt::value_type("ID", 2));
...
metaMap["Fields1"].insert(MapStringToInt::value_type("string1, int1));
metaMap["Fields1"].insert(MapStringToInt::value_type("string2, int2));
...

HTH
Heinz

May 20 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Roberto A. F. De Almeida | last post: by
reply views Thread by Juan Cabanela | last post: by
6 posts views Thread by Sam Carleton | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.