PDA

View Full Version : A good system on header files



baray98
22nd January 2009, 06:23
We define our errors in a header files. This file is shared to all apps and firmwares, now I am looking for a good way or system so the error viewer can be updated whenever there are changes in the definitions.
This header file contains all the info that the viewer should show


#define MYerror 1 /* hot unplug missed */
#define yourerror 2 /*just do it error */


All suggestion is welcome

jacek
22nd January 2009, 20:23
You could use enum instead of macros. This way you can use Qt facilities like QMetaEnum.

baray98
22nd January 2009, 22:32
Its a good idea but changing it to enums will affect lots of project (firmwares) that are not Qt some are C codes....

The thing that i can think of is building a parser that outputs some .cpp file , in this file would be an initialized an



map <int /*errorCode*/,string/*description*/> errorMap;
map <int /*errorCode*/,string/*description*/> possibleCauseMap;

//since i have so many devices that has its own error code then this means another map
// say....

map <int /*deviceId*/,map <int /*errorCode*/,string/*description*/> > deviceMapError;
map <int /*deviceId*/,map <int /*errorCode*/,string/*description*/> > deviceMapPossibleCause;



parser is the only way i can think of .. but its a lot of work

what do you think?

baray98

wysota
22nd January 2009, 23:17
Its a good idea but changing it to enums will affect lots of project (firmwares) that are not Qt some are C codes....
Not quite. Values of enums are integers, so you can map between the two systems without a problem.

In your case I would compile all error codes and messages into a global binary array and include it directly from within a header file to all projects.
Of course the array would have to be constructed by some tool based on the parsed file (xml would be best, probably).