Click here to Skip to main content
15,922,419 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: what function will convert a char to its number value Pin
Terry O'Nolley11-Jul-03 9:27
Terry O'Nolley11-Jul-03 9:27 
GeneralRe: Whoops Pin
John R. Shaw11-Jul-03 10:15
John R. Shaw11-Jul-03 10:15 
GeneralRe: Whoops Pin
Terry O'Nolley12-Jul-03 3:58
Terry O'Nolley12-Jul-03 3:58 
GeneralRe: what function will convert a char to its number value Pin
johnstonsk11-Jul-03 10:26
johnstonsk11-Jul-03 10:26 
GeneralRe: what function will convert a char to its number value Pin
John R. Shaw14-Jul-03 7:23
John R. Shaw14-Jul-03 7:23 
AnswerRe: what function will convert a char to its number value Pin
Mike Dimmick11-Jul-03 9:47
Mike Dimmick11-Jul-03 9:47 
GeneralRe: what function will convert a char to its number value Pin
Daniel Turini11-Jul-03 10:15
Daniel Turini11-Jul-03 10:15 
GeneralRe: what function will convert a char to its number value Pin
Mike Dimmick11-Jul-03 12:19
Mike Dimmick11-Jul-03 12:19 
I'm sure they do. I meant from a code maintenance point of view: it's a lot easier to maintain (I think) a set of moderately simple functions than it is to maintain a 500-line function with a huge switch statement in it.

Of course, you can still code the dispatching mechanism like:

switch ( iValue )
{
   case 0:
      HandleCase0();
      break;
 
   case 1:
      HandleCase1();
      break;
 
   // ...etc...
 
   default:
      assert( !"Error in case statement!" );
      break;
}
but that gets very boring, very quickly. Unless there was some clear profiling indication that the table version was too slow for a given code path, I'd stick to that.

As for how common libraries implement it: in Win32 programming, you typically write a big switch statement. MFC's message maps are table-based (complicated somewhat by supporting ranges). ATL's BEGIN_MSG_MAP family of macros mask a honking great if/else if chain.

The hash table implementation is probably nicer if you have a fixed set and can calculate it all in advance, and either know that you can't get false-positives or check that there's a match before you jump. For general, intelligible coding, I use the array. The threshold is obviously Wink | ;) because the hash table has an overhead in the hash function and the extra check in any case.

MFC has, IIRC, a small hash table for each class with a message map which contains the most recently used message map entries, so it doesn't have to search the whole table (and potentially the base class's table, and its base class, and so on down) every time a common message arrives.

My solution does require that all your operations will take the same parameters. This ain't necessarily so. One of my implementations was for a varargs function where you had command identifiers, and each command could take 0, 1 or 2 parameters. So I had to have a parameter count field as part of my jump table structure which indicated what you needed to cast the function pointer to. Again, MFC does something similar for its message maps.

--
Mike Dimmick
GeneralRe: what function will convert a char to its number value Pin
Daniel Turini11-Jul-03 23:48
Daniel Turini11-Jul-03 23:48 
GeneralRe: what function will convert a char to its number value Pin
Mike Dimmick12-Jul-03 1:16
Mike Dimmick12-Jul-03 1:16 
AnswerRe: what function will convert a char to its number value Pin
drabudawood13-Jul-03 20:12
drabudawood13-Jul-03 20:12 
QuestionWhy is the constructor protected ? Pin
Shay Harel11-Jul-03 7:25
Shay Harel11-Jul-03 7:25 
AnswerRe: Why is the constructor protected ? Pin
John M. Drescher11-Jul-03 7:40
John M. Drescher11-Jul-03 7:40 
GeneralRe: Why is the constructor protected ? Pin
Shay Harel11-Jul-03 7:43
Shay Harel11-Jul-03 7:43 
GeneralRe: Why is the constructor protected ? Pin
John M. Drescher11-Jul-03 7:50
John M. Drescher11-Jul-03 7:50 
GeneralRe: Why is the constructor protected ? Pin
Shay Harel11-Jul-03 7:52
Shay Harel11-Jul-03 7:52 
GeneralRe: Why is the constructor protected ? Pin
John M. Drescher11-Jul-03 7:55
John M. Drescher11-Jul-03 7:55 
GeneralRe: Why is the constructor protected ? Pin
Anthony_Yio15-Jul-03 1:27
Anthony_Yio15-Jul-03 1:27 
QuestionI don’t’ know how I can find the character set like it? Pin
Alice8011-Jul-03 7:20
Alice8011-Jul-03 7:20 
AnswerRe: I don’t’ know how I can find the character set like it? Pin
Mike Dimmick11-Jul-03 10:02
Mike Dimmick11-Jul-03 10:02 
GeneralRe: I don’t’ know how I can find the character set like it? Pin
Alice8012-Jul-03 1:54
Alice8012-Jul-03 1:54 
GeneralRe: I don’t’ know how I can find the character set like it? Pin
Mike Dimmick12-Jul-03 2:12
Mike Dimmick12-Jul-03 2:12 
AnswerRe: I don’t’ know how I can find the character set like it? Pin
Anthony_Yio15-Jul-03 1:33
Anthony_Yio15-Jul-03 1:33 
GeneralLinked list Pin
DaveE9th11-Jul-03 6:57
DaveE9th11-Jul-03 6:57 
GeneralRe: Linked list Pin
David Crow11-Jul-03 7:06
David Crow11-Jul-03 7:06 

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.