Hello, all. Rather urgent question.


I'm trying to implement a simple Cstring/Cstring map in my application so users can specify what they want to see instead of the MAC address.
The information on http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcstdlib/html/vclrfmapvaluetype.asp , however, tells me I can use ::mapped_type.

But that doesn't exist as an option in VC++ 6.0. I've tried ::_Tref, but I think it's responsible for a number of C4786 messages (ranging from 34 to 179) appearing every time I modify and compile. I can't get these stupid things (Supposedly not shown by default) to go away, no matter what I set the warning levels at.

So, I need help, because this is a big part of my project and my time is up at the end of the month, with a number of other features not even started and documentation in dire need of updating.


I want a map that is automatically filled by the program with the keys and mapped values intially identical until the user edits the mapped value.

I would greatly appreciate any help that could be given about implementing a map for the aforementioned purpose.

Thanks in advance!

>I'm trying to implement a simple Cstring/Cstring map in my application
>so users can specify what they want to see instead of the MAC address.
The who and the what, now? It sounds like you want some sort of variant type, but I'm not sure. So be more specific and feel free to express yourself with pseudo-C++ so we have a better idea of what you're trying to do.

All right. I'm not very good with pseudo code, but there's no need to cloak and dagger this stuff.

In the header, as part of my MFC app's document class:

typedef pair <const CString, CString> cCStr2CStr;
	map <CString, CString> MACaddrMAP;
	map <CString, CString>:: key_type key1;
	map <CString, CString>::_Tref mapped1;
	//map <CString, CString>:: value_type value1;
	map <CString, CString>:: iterator mapIter;

I'm not entirely sure I'll even need all of the above.


In the constructor for the document class:

CGUISnoopDoc::CGUISnoopDoc():mapped1(MACaddrMAP.begin()->second)
{
	MACaddrMAP.insert (cCStr2CStr("FF:FF:FF:FF:FF","Ethernet Broadcast") );
}

and I get this error from putting this stuff in:
c:\program files\microsoft visual studio\vc98\include\xtree(151) : warning C4786: '?$reverse_bidirectional_iterator@Viterator@?$_Tree@VCString@@U?$pair@$$
CBVCString@@V1@@std@@U_Kfn@?$map@VCString@@V1@U?$less
@VCString@@@std@@V?$allocator@VCString@@@3
@@3@U?$less@VCString@@@3@V?$allocator@VCString@@@3@@
std@@U?$pair@$$CBVCString@@V1@@3@AAU43@PAU43@H' :
identifier was truncated to '255' characters in the browser information
c:\program files\microsoft visual studio\vc98\include\map(46) :
see reference to class template instantiation
'std::_Tree<class CString,struct std::pair<class CString const ,class CString>,
struct std::map<class CString,class CString,struct std::less<class CString>,
class std::allocator<class CString> >::_Kfn,struct std::less<class CString>,
class std::allocator<class CString> >' being compiled
c:\mfctutorials\guisnoop\guisnoopdoc.h(72) : see reference to class template instantiation
'std::map<class CString,class CString,struct std::less<class CString>,class std::allocator<class CString> >' being compiled


I just want a map class that pairs off a CString as both key and value. This map will be initially populated by the program, setting the key and value to the same CString.
The user will then be able to edit the value and have the program remap all occurances of that value to the new definition, while preserving the original CString in the key.
This is going to be used to make a whole bunch of MAC addresses more distinct when viewed in a column, and I figure that this is the best way to do it so that the program can be expanded to save the user-defined values for reload later.

I never really did pseudocode, I'm afraid, If this isn't good enough, I'll go learn a pseudocode method as fast as I can...

>and I get this error from putting this stuff in:
That's not an error, it's a warning that the Microsoft programmers aren't smart enough to realize that template identifiers get really really big, really really fast.

>The user will then be able to edit the value and have the program
>remap all occurances of that value to the new definition, while
>preserving the original CString in the key.
Well, there's only going to be one occurance of the value unless different keys can have the same value. But searching a map by value is a bitch. To change the value of a key/value pair, just do something like this:

m.find ( x )->second = y;

>I'll go learn a pseudocode method
Riiight. Pseudocode is easy, but what I asked for was some C++ that doesn't necessarily compile yet clearly shows us what you're trying to get done.

It's just that for MFC, the code's all over the place, but I'll try.

In Document:

//Map declaration (Eventually, determine if config file for this file exists
    //and load map at file open.

   //Read in data for many packets, storing MAC address in unsigned char array

in View:

CGUISnoopDoc* pDoc = GetDocument();  //allows access of document from view
	ASSERT_VALID(pDoc);	
  //go through data, display on screen
  //decode and format MAC addresses through inline function
  //if no previous file existed, store unique addresses in document's map through
 pDoc->map::mymap.insert(MAC address, MAC address);

Wait until user elects to change the name for a particular address.
In Document:

//Message map for clicking on rename button
//in function called by message map:
{
  //open dialog box to allow renaming
 //if user updates with 'okay', 
  //update map with new names for MAC addresses and set enumeration to inform view on update all views. 
 UpdateAllViews(NULL); //To inform grid to redraw

//if user cancels, revert values to their keys, which are the original MAC addresses, and no update of grid occurs.
}

In view:

//Redraw grid, noticing flag to use the user-defined values, only spend processor time updating two columns instead of 24.

Is that better?

Okay, let me try this again.

I want to know how to implement a map inside a class.
This map will use a CString data type as the keys. This map will use a CString data type for value associated with each key.
I can't get it to work because I can't follow the example given by MSDN, as my version of VC++ doesn't recognize the '::mapped_type' shown here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcstdlib/html/vclrfmapvaluetype.asp

Given what I want to do with the application, I am not even sure if this would be useful for me, because I just want to be able to look through the map to see if the key exists, or to enter a new value to associate with the key.

Could someone please provide an example of implementing a map as I have written about here, or a site that could help me finish this very important piece of my application?

I apologize for being so strange earlier. I was not explaining myself well.


EDIT:
I have just removed everything but the map and iterator, and It seems to be working. I'll just work on this now. Sorry about the fuss.

>as my version of VC++ doesn't recognize the '::mapped_type'
That should teach you to use standard options when they exist:

#include <iostream>
#include <map>
#include <utility>

using namespace std;

typedef pair <const int, int> cInt2Int;

int main()
{
   map<int, int> m1;
   map<int, int>::value_type value1;
   map<int, int>::iterator pIter;
   int key1, mapped1;
   
   // value_type can be used to pass the correct type
   // explicitly to avoid implicit type conversion
   m1.insert ( map<int, int>::value_type ( 1, 10 ) );

   // Compare other ways to insert objects into a map
   m1.insert ( make_pair ( 2, 20 ) );
   m1[3] = 30;

   // Initializing key1 and mapped1
   key1 = m1.begin()->first;
   mapped1 = m1.begin()->second;

   cout<<"The key of first element in the map is "<< key1 <<".\n";
   cout<<"The data value of first element in the map is "<< mapped1 <<".\n";

   cout<<"The keys of the mapped elements are:";
   for ( pIter = m1.begin(); pIter != m1.end(); pIter++ )
      cout<<" "<< pIter->first;
   cout<<".\n";

   cout<<"The values of the mapped elements are:";
   for ( pIter = m1.begin(); pIter != m1.end(); pIter++ )
      cout<<" "<< pIter->second;
   cout<<"."<<endl;
}

Thank you very much. That's exactly what I needed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.