Templates for structures

novice2 via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Nov 2 04:10:45 PST 2014


Hello.

I need write some wrapper around legacy data structure.
May be it should be class. May be structure with methods.
The problem is writing repetitive code for underlying data.
For example:
  - code to read length-byte-prefixed string to D string for every 
field in every structure;
  - code to write D string back to length-byte-prefixed string;

Is it possible to write some template or mixin, and then just 
write
myStruct.addFiled(type=ByteLengthString, name="name")
myStruct.addFiled(type=ShortLengthString, name="filed2")
myStruct.addFiled(type=WeirdStoredInteger, name="counter")

May be it can be done with template, mixin, UDA, ...?

May be something already realized, and i can see sources as 
example?

Any ideas or examples please.
Just show direction for me )

Thanx.


More information about the Digitalmars-d-learn mailing list