Click here to Skip to main content
15,904,652 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
GeneralATL App consuming .NET Pin
Chiew Heng Wah17-Feb-05 19:25
Chiew Heng Wah17-Feb-05 19:25 
GeneralRe: ATL App consuming .NET Pin
Gevorg22-Feb-05 10:15
Gevorg22-Feb-05 10:15 
GeneralPWSTR length Pin
dabayi17-Feb-05 1:45
dabayi17-Feb-05 1:45 
GeneralRe: PWSTR length Pin
ThatsAlok17-Feb-05 3:03
ThatsAlok17-Feb-05 3:03 
GeneralRe: PWSTR length Pin
dabayi17-Feb-05 3:17
dabayi17-Feb-05 3:17 
GeneralRe: PWSTR length Pin
ThatsAlok17-Feb-05 4:50
ThatsAlok17-Feb-05 4:50 
GeneralRe: PWSTR length Pin
dabayi17-Feb-05 5:22
dabayi17-Feb-05 5:22 
Generalcalling member functions from a map Pin
Malcolm Smart16-Feb-05 21:43
Malcolm Smart16-Feb-05 21:43 
Hi
I am reading in an XML(ish) file and want to pass the file handle off to different member functions depending on the section being read. New sections are being added so I wanted the code to be 'maintainable'. I am creating a map of
pairs and want to call the sectionhandler for the section. I've come up with the following up to now :-

class MyFileClass
{
//lots of stuff here
private:
   void Section1Handler() {//do nothing for now; };
   void Section2Handler() {//do nothing for now; };
   void Section3Handler() {//do nothing for now; };
public:
   void ReadFile(/* parameters */);
};

void MyFileClass::ReadFile(/* params*/)
{
map <string , void (MyFileClass::*)() > functionMap;

functionMap["<Section1>"] = Section1Handler;
functionMap["<Section2>"] = Section2Handler;
functionMap["<Section3>"] = Section3Handler;

ifstream myfile(....)

string myBuffer;

while (myfile)
   {
   getline(myfile , myBuffer)
   //now I want to call the function
   functionMap[myBuffer]; <--- clearly won't work - it just returns the address.
   //I've tried things like *(functionMap[myBuffer])(); but getting nowhere
   }
}

Whilst the code might not be perfect above, it gives the idea of what I am trying to do. Call a function directly related to the content of myBuffer. That way, a new sectionhandler can be added and inserted into the map, instead of
if (myBuffer == "Section1") Section1Handler;
else if (myBuffer == "Section2") Section2Handler;

which, now I've looked at it again, doesn't seem that hard to maintain does it really? But regardless of that, I really would like to know what I'm doing wrong WRT the map of member function pointers...

Regards

Angel














*********************************************
The sooner you fall behind, the longer you have to catch up.

GeneralRe: calling member functions from a map Pin
Stuart Dootson17-Feb-05 10:33
professionalStuart Dootson17-Feb-05 10:33 
GeneralRe: calling member functions from a map Pin
Malcolm Smart17-Feb-05 21:46
Malcolm Smart17-Feb-05 21:46 
GeneralRe: calling member functions from a map Pin
Stuart Dootson18-Feb-05 4:39
professionalStuart Dootson18-Feb-05 4:39 
GeneralRe: calling member functions from a map Pin
Malcolm Smart18-Feb-05 5:36
Malcolm Smart18-Feb-05 5:36 
GeneralProblem with regular C Class in ATL Pin
rwestgraham16-Feb-05 0:06
rwestgraham16-Feb-05 0:06 
Questionhow to provide same con. point in different objects Pin
grinder15-Feb-05 23:00
grinder15-Feb-05 23:00 
GeneralList Control in ATL dialog Pin
abel66615-Feb-05 8:10
abel66615-Feb-05 8:10 
GeneralRe: List Control in ATL dialog Pin
Michael Dunn15-Feb-05 8:49
sitebuilderMichael Dunn15-Feb-05 8:49 
GeneralRe: List Control in ATL dialog Pin
abel66615-Feb-05 21:16
abel66615-Feb-05 21:16 
Questionhow to debug exchange store event sink Pin
muh22m15-Feb-05 7:53
muh22m15-Feb-05 7:53 
QuestionHow to get random numbers? Pin
Anonymous14-Feb-05 20:05
Anonymous14-Feb-05 20:05 
Generalspirit and unicode Pin
bruce2g14-Feb-05 14:40
bruce2g14-Feb-05 14:40 
GeneralRe: spirit and unicode Pin
Stuart Dootson15-Feb-05 5:19
professionalStuart Dootson15-Feb-05 5:19 
GeneralATL Collection Problem Pin
ekling14-Feb-05 11:32
ekling14-Feb-05 11:32 
Generalconvert PWSTR to LPCTSTR Pin
dabayi14-Feb-05 0:03
dabayi14-Feb-05 0:03 
GeneralRe: convert PWSTR to LPCTSTR Pin
rocky_pulley14-Feb-05 2:22
rocky_pulley14-Feb-05 2:22 
GeneralRe: convert PWSTR to LPCTSTR Pin
dabayi14-Feb-05 3:17
dabayi14-Feb-05 3:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.