tags:

views:

79

answers:

4

Hi,

It's my first time trying out C++ STL. I'm trying to build a multidimensional associative array using map. For example:

typedef struct DA {
    string  read_mode;
    string  data_type;
    void    *pValue;
    void    *pVarMemLoc;
}DA;

int main()
{
    map<string, map<string, map<string, map<string, map<string, DA*>>>>> DATA;

    DATA["lvl1"]["stg1"]["flr1"]["dep1"]["rom1"] = new DA;
    DATA["lvl1"]["stg1"]["flr1"]["dep1"]["rom2"] = new DA;
    DATA["lvl1"]["stg1"]["flr1"]["dep1"]["rom3"] = new DA;

    IEC["lvl1"]["stg1"]["flr1"]["dep1"]["rom1"]->read_mode = "file";
    IEC["lvl1"]["stg1"]["flr1"]["dep1"]["rom2"]->read_mode = "poll";
    IEC["lvl1"]["stg1"]["flr1"]["dep1"]["rom3"]->read_mode = "report";

    return 0;
}

When compiling the code above in VS2005, I got 170 of C4503 warnings. All of the warnings are about "decorated name length exceeded, name was truncated". The program seems to run fine though.

Anyone care to spare some time to explain to me what caused these warnings and how do i solve em? thanks in advance :)

Warning 1   warning C4503: 'std::map<_Kty,_Ty>::~map' : decorated name length exceeded, name was truncated  c:\program files\microsoft visual studio 8\vc\atlmfc\include\cstringt.h 2121
Warning 2   warning C4503: 'std::map<_Kty,_Ty>::map' : decorated name length exceeded, name was truncated   c:\program files\microsoft visual studio 8\vc\atlmfc\include\cstringt.h 2121
Warning 3   warning C4503: 'std::map<_Kty,_Ty>::operator []' : decorated name length exceeded, name was truncated   c:\program files\microsoft visual studio 8\vc\atlmfc\include\cstringt.h 2121
Warning 4   warning C4503: 'std::_Tree<_Traits>::~_Tree' : decorated name length exceeded, name was truncated   c:\program files\microsoft visual studio 8\vc\atlmfc\include\cstringt.h 2121
Warning 5   warning C4503: 'std::map<_Kty,_Ty>::operator []' : decorated name length exceeded, name was truncated   c:\program files\microsoft visual studio 8\vc\atlmfc\include\cstringt.h 2121
Warning 6   warning C4503: 'std::_Tree<_Traits>::iterator::~iterator' : decorated name length exceeded, name was truncated  c:\program files\microsoft visual studio 8\vc\atlmfc\include\cstringt.h 2121
Warning 7   warning C4503: 'std::_Tree<_Traits>::iterator::iterator' : decorated name length exceeded, name was truncated   c:\program files\microsoft visual studio 8\vc\atlmfc\include\cstringt.h 2121
+2  A: 

See this MSDN link for meaning and resolution.

Naveen
hi naveen, thanks for the link :) since the content says that it will not affect the correctness of the program, i'll stick with it for now. But does it affect in terms of program performance?
justin
@Justin: No, it is a pure compile time thing.
Naveen
+1  A: 

If you intend to keep this monster of a data structure, there is little you can do about the warning other than disable it:

#pragma warning(disable:4503)
PigBen
hi PigBen, thanks for your answer. I had to use some multidimensional associative to store my data, something like what PHP arrays can do. Are there other alternatives that you can suggest me to have a look?
justin
@justin: yep: describe your data in another question and ask how you should represent it in C++.
jalf
thanks jalf, i'll do that :)
justin
A: 

Declare in such way( pay attention to finished quotes)

map<string, map<string, map<string, map<string, map<string, DA*> > > > > DATA;

C++ recognizes >> as shift operator.

StNickolay
Fixed in C++0x.
Alf P. Steinbach
That's not the problem (MSVC already parses it the way the OP intended)
jalf
A: 

Others have suggested how you could disable the warning. I suggest that you rethink your design instead. Use some more abstraction than map^5. Or change the data structure of the storage. E.g. use map instead of map^5.

Updated:

What I mean is that you basically have two options:

  • You use a key with as many strings/levels as you need:

    struct Key3 { std::string x, y, z; }; typedef std::map MyMap;

  • Or you build something generic, where each level can hold either the DA* value and/or another level.

wilx
Hi wilx, thanks for the advise. I was rethinking how i could minimize the number of maps. The best i could end up with is map^2. What are the disadvantages of having the data structure such as above, map^5? I need at least 2 levels of data association for iteration purposes. What do you think is a better approach to this?
justin