Similar to Boost Preprocessor library for generating a set of types based on a list of basic types e.g. PointI32, PointF32 etc. in C++/CLI I am asking how to generate:
struct Point##TYPE_SUFFIX_NAME
{
TYPE X
{ get; set; }
TYPE Y;
{ get; set; }
// Other code
};
for different basic (POD) data types e.g.:
PointF32, PointF64, PointI32 etc.
using T4 (Text Template Transformation Toolkit) in Visual Studio 2008 or later.
See http://www.olegsych.com/2007/12/text-template-transformation-toolkit/ and http://msdn.microsoft.com/en-us/library/bb126445.aspx
Well, I have the answer my self. I have created the following T4 include files:
SignedIntegersSuffices.ttincludeUnsignedIntegersSuffices.ttincludeIntegersSuffices.ttincludeFloatsSuffices.ttincludeBasicTypesSuffices.ttincludeand then the actual T4 template is
PointTypes.tt. These files are simply added to a C# project and Visual Studio will detect the.ttand generate a matchingPointTypes.csfile, whenever the .tt file is saved.These files are listed in the following.
SignedIntegersSuffices.ttincludeUnsignedIntegersSuffices.ttincludeIntegersSuffices.ttincludeFloatsSuffices.ttincludeBasicTypesSuffices.ttincludeAnd finally the actual template file
PointTypes.tt:The output file
PointTypes.cswill then look like this:Pretty simple and quite effective. Now, of course, this could have been done using generics etc, but that is not the point here. This is meant as a simple example of code generation for multiple basic types.
Comments to improve this or similar are welcomed.