Click here to Skip to main content
15,918,742 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Forced scoping as a programming technique? Pin
Michael Dunn14-Jun-07 6:27
sitebuilderMichael Dunn14-Jun-07 6:27 
GeneralRe: Forced scoping as a programming technique? Pin
Nemanja Trifunovic14-Jun-07 6:28
Nemanja Trifunovic14-Jun-07 6:28 
GeneralRe: Forced scoping as a programming technique? Pin
Cyrilix14-Jun-07 6:43
Cyrilix14-Jun-07 6:43 
GeneralRe: Forced scoping as a programming technique? Pin
jbarton14-Jun-07 8:53
jbarton14-Jun-07 8:53 
GeneralRe: Forced scoping as a programming technique? Pin
Cyrilix14-Jun-07 9:38
Cyrilix14-Jun-07 9:38 
GeneralRe: Forced scoping as a programming technique? Pin
jbarton14-Jun-07 9:57
jbarton14-Jun-07 9:57 
GeneralRe: Forced scoping as a programming technique? Pin
Cyrilix14-Jun-07 10:38
Cyrilix14-Jun-07 10:38 
GeneralRe: Forced scoping as a programming technique? Pin
jbarton15-Jun-07 3:20
jbarton15-Jun-07 3:20 
I didn't read your reply until this morning, so I am just replying now.

Looking at your PROCESS macro, it seems like most of it could easily be changed to be a member template function of class MainWindow (although I am making some assumptions about what the various symbols are).

The assumptions that I am making are:
- CallbackWrapperSpecific is a templated class derived from CallbackWrapperGeneric.
- The args passes to PROCESS is a specific variable with the type matching the first argument passed to PROCESS.
- The PROCESS macro is being used inside a member of MainWindow. I assume this because the "this" pointer is being passed to the constructor of CallbackWrapperSpecific.
- The m_localWorkMap is a member of MainWindow which is used to hold thread ids which map to CoreWorkUnit * objects (part of your cleanup mechanism).
- The m_threadPool is a member of MainWindow which is used to create a thread to process the request, with its Process member returning the thread id.

Given these assumptions, the only problem line that I see in the entire macro is:
CoreWorkUnit* cWorkUnit = new CoreWorkUnit(Function_##function, cbwDest);

This line is constructing a Function_ name from a combination of a constant string and the name of the member routine in MainWindow. This appears to be the only line which can't directly be converted into using a member template function. If you could explain what this is for, perhaps I could suggest another way to do this.

The rest of the code looks straight forward and should be easy to change - the following is close to what would be used (if my assumptions were correct):

<br />
   template <typename type><br />
   void Process( void (MainWindow::*memberFn)(type&), type args )<br />
   {<br />
      CallbackWrapperSpecific< MainWindow, void (MainWindow::*)(type&), type >* cbwSpecific =<br />
         new CallbackWrapperSpecific< MainWindow,void(MainWindow::*)(type&), type>( this, memberFn, args );<br />
<br />
      CallbackWrapperGeneric<type>* cbwGeneric = cbwSpecific;<br />
      CallbackWrapperDestroy* cbwDest = cbwSpecific;<br />
      CoreWorkUnit* cWorkUnit = new CoreWorkUnit(/*Function_##function,*/ cbwDest);<br />
      m_localWorkMap.insert(map<int, CoreWorkUnit*>::value_type(m_threadPool->Process(cbwGeneric), cWorkUnit));<br />
   }<br />


Note that I commented out the first argument to the CoreWorkUnit constructor as I didn't know what to put here.

The calling sequence is slightly different, as you pass the type as a template parameter, and the address of the MainWindow routine as the first argument - the call would look something like:

<br />
   Process<int>( &MainWindow::DoSomething, 1 );<br />

GeneralRe: Forced scoping as a programming technique? [modified] Pin
Cyrilix15-Jun-07 3:45
Cyrilix15-Jun-07 3:45 
AnswerRe: Forced scoping as a programming technique? Pin
Nemanja Trifunovic14-Jun-07 6:27
Nemanja Trifunovic14-Jun-07 6:27 
AnswerRe: Forced scoping as a programming technique? Pin
bob1697214-Jun-07 8:12
bob1697214-Jun-07 8:12 
Questionsetting executable icon Pin
R Thompson14-Jun-07 5:44
R Thompson14-Jun-07 5:44 
AnswerRe: setting executable icon Pin
R Thompson14-Jun-07 6:11
R Thompson14-Jun-07 6:11 
AnswerRe: setting executable icon Pin
Michael Dunn14-Jun-07 6:28
sitebuilderMichael Dunn14-Jun-07 6:28 
QuestionRe: setting executable icon Pin
Hamid_RT14-Jun-07 19:44
Hamid_RT14-Jun-07 19:44 
QuestionSave Screenshot Pin
CDRAIN14-Jun-07 4:54
CDRAIN14-Jun-07 4:54 
QuestionRe: Save Screenshot Pin
David Crow14-Jun-07 5:40
David Crow14-Jun-07 5:40 
AnswerRe: Save Screenshot Pin
Naveen14-Jun-07 14:30
Naveen14-Jun-07 14:30 
QuestionRe: Save Screenshot Pin
Hamid_RT14-Jun-07 19:41
Hamid_RT14-Jun-07 19:41 
AnswerRe: Save Screenshot [modified] Pin
CDRAIN15-Jun-07 0:46
CDRAIN15-Jun-07 0:46 
GeneralRe: Save Screenshot Pin
Hamid_RT15-Jun-07 2:56
Hamid_RT15-Jun-07 2:56 
GeneralRe: Save Screenshot Pin
CDRAIN15-Jun-07 3:28
CDRAIN15-Jun-07 3:28 
GeneralRe: Save Screenshot Pin
Hamid_RT15-Jun-07 5:29
Hamid_RT15-Jun-07 5:29 
GeneralRe: Save Screenshot Pin
Hamid_RT15-Jun-07 6:06
Hamid_RT15-Jun-07 6:06 
GeneralRe: Save Screenshot Pin
CDRAIN16-Jun-07 2:25
CDRAIN16-Jun-07 2:25 

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.