Some X-Macros Usages

Clever use of X-Macros ( ) allow  to decorrelate a set of data from the code which will handle them. For example,  I had recently to implement a parser, which would  analyse an incoming stream, isolate the embedded command and act upon.

So in this typical situation, you generally get the stream matched against some predefined-strings, arranged in an ordered way. Then, you get an ID, parameters and call a specific handler. Nothing fancy.

However, if you want this code to be maintainable (for example, you decide to change the handler name), and upgradable (adding new commands ID), you certainly would like some mechanism which would gather all the changeable bits (the commands, the ID’s, etc ..) from the pure parser structure. This is where X-Macros become handy.

Continue reading “Some X-Macros Usages”