digitalmars.D.learn - bitfields - Default values?
- Era Scarecrow (6/6) Jun 04 2012 The documentation for bitfields doesn't go into detail if you
- bearophile (5/7) Jun 04 2012 I think you can't. See:
- Era Scarecrow (22/29) Jun 12 2012 K, I think I have a fix for this done. Now if I bother to get
- bearophile (4/19) Jun 12 2012 Bye,
- Dmitry Olshansky (10/18) Jun 12 2012 Or iff bitfields is a mixin template:
- Era Scarecrow (18/35) Jun 12 2012 That does look cleaner and better IMO. At this second I'm not
- Era Scarecrow (4/16) Jun 12 2012 Good news, I _can_ do that very format. Not too much complexity
The documentation for bitfields doesn't go into detail if you can put any default values into it. Can you? It makes sense if you can that it would convert the whole thing into a single number (or or-ing the results into a single expression with shifting and all). From what I can tell it all defaults to 0...
Jun 04 2012
Era Scarecrow:The documentation for bitfields doesn't go into detail if you can put any default values into it. Can you?I think you can't. See: http://d.puremagic.com/issues/show_bug.cgi?id=4425 Bye, bearophile
Jun 04 2012
On Tuesday, 5 June 2012 at 00:17:08 UTC, bearophile wrote:Era Scarecrow:K, I think I have a fix for this done. Now if I bother to get GitHub to work with me at all... Here's a sample, thoughts of naming or other changes before I try and add this back in? (I'm not the best with naming things) //T is a array of strings of name=value. //returns a replacement string from bitfields with the defaults in place string bitfields_D(string bitf, T...)(); struct defs { mixin(bitfields_D!( bitfields!( //borrowed from std.bitmanip bool, "b", 1, uint, "i", 3, short, "s", 4), "i=2", "s=5")); } defs s; assert(!s.b); assert(s.i == 2); assert(s.s == 5);The documentation for bitfields doesn't go into detail if you can put any default values into it. Can you?I think you can't. See: http://d.puremagic.com/issues/show_bug.cgi?id=4425 Bye, bearophile
Jun 12 2012
Era Scarecrow:struct defs { mixin(bitfields_D!( bitfields!( //borrowed from std.bitmanip bool, "b", 1, uint, "i", 3, short, "s", 4), "i=2", "s=5")); }Are you able to support a syntax like:struct defs { mixin(bitfields!( bool, "b", 1, uint, "i=2", 3, short, "s=5", 4)); }Bye, bearophile
Jun 12 2012
On 12.06.2012 17:05, bearophile wrote:Era Scarecrow:Are you able to support a syntax like:Or iff bitfields is a mixin template: struct defs { mixin bitfields!( bool, "b", 1, uint, "i=2", 3, short, "s=5", 4); } -- Dmitry Olshanskystruct defs { mixin(bitfields!( bool, "b", 1, uint, "i=2", 3, short, "s=5", 4)); }
Jun 12 2012
On Tuesday, 12 June 2012 at 13:05:26 UTC, bearophile wrote:Era Scarecrow:That does look cleaner and better IMO. At this second I'm not sure. I was trying not to interfere with the original bitfield generator. I'm not as competent with templates as I'd like to be so having it go through and separate the data out seems a lot more difficult than simply replacing the end of the string as I currently have it. The bitfields as it is creates enums (min/max values), the get, the set, and then at the end has a 'private xxx valname;'. My little function is just a wrapper that builds on it by making the calculations as specified and then modifying the very end of the bitfields string with the answer, in my example that was '84'. I can try and make it as you have it, but I'm not sure how much harder that will be compared to what it is now; would probably end up as 'private xxx valname = (2<<1) | (5<<4);, which makes sense without adding too much complexity.. unless you go negative numbers, then you have to add a mask... Hmmm.... 'private xxx valname = ((2 & 7) << 1) | ((5 & 15) << 4);'struct defs { mixin(bitfields_D!( bitfields!( //borrowed from std.bitmanip bool, "b", 1, uint, "i", 3, short, "s", 4), "i=2", "s=5")); }Are you able to support a syntax like:struct defs { mixin(bitfields!( bool, "b", 1, uint, "i=2", 3, short, "s=5", 4)); }
Jun 12 2012
On Tuesday, 12 June 2012 at 15:51:31 UTC, Era Scarecrow wrote:On Tuesday, 12 June 2012 at 13:05:26 UTC, bearophile wrote:Good news, I _can_ do that very format. Not too much complexity and it seems to work okay, and it's definitely cleaner. Got some testing yet to do, but it looks good to me..Are you able to support a syntax like:That does look cleaner and better IMO. At this second I'm not sure. I was trying not to interfere with the original bitfield generator.struct defs { mixin(bitfields!( bool, "b", 1, uint, "i=2", 3, short, "s=5", 4)); }
Jun 12 2012