Skip to content

Commit

Permalink
[DOC] v1.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
rentzsch committed Mar 25, 2014
1 parent 0a52965 commit 2086303
Showing 1 changed file with 41 additions and 35 deletions.
76 changes: 41 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,51 +71,57 @@ You can also explicitly define enum integer values:

In the above scenario, `Stream_Disconnected`'s value will be `42`, `Stream_Connecting`'s will be `43` and so on.

## Bitwise enums: (NS_OPTIONS)

Same syntax as above… but exchange with

`JROptions(TYPE_NAME,…)` OR `JROptionsDeclare(TYPE_NAME,…)` + `JROptionsDefine(TYPE_NAME)`.
JROptions (Align, AlignLeft = 0x00000001,
AlignRight = 0x00000010,
AlignTop = 0x00000100,
AlignBottom = 0x00001000,
AlignTopLeft = 0x00000101,
AlignBottomLeft = 0x00001001,
AlignTopRight = 0x00000110,
AlignBottomRight = 0x00001010
);

NSLog(@"%@",AlignByValue()); -> { 256 = AlignTop;
4096 = AlignBottom;
257 = AlignTopLeft;
1 = AlignLeft;
4097 = AlignBottomLeft;
16 = AlignRight;
272 = AlignTopRight;
4112 = AlignBottomRight;
}


Combinations, like | Apple | does...
You can also use hex values:

Align botRight = AlignBottomRight;
Align botRightBitWise = AlignBottom | AlignRight;
JREnum(StreamState,
Stream_Disconnected = 0x2A,
Stream_Connecting,
Stream_Connected,
Stream_Disconnecting);

That's semantically identical to the above.

New in v1.1 you can use very simple bit-shift masks:

NSLog(@"Are They The Same: %@", (botRightBitWise == botRight) ? @"YES" : @"NO"); ->
> Are They The Same: YES
JREnum(Align,
AlignLeft = 1 << 0,
AlignRight = 1 << 1,
AlignTop = 1 << 2,
AlignBottom = 1 << 3,
AlignTopLeft = 0x05,
AlignBottomLeft = 0x09,
AlignTopRight = 0x06,
AlignBottomRight = 0x0A,
);

But better, because you can go to-and-fro string values
This helps where you want one variable to house a combination of flags:

NSLog(@"How is that combo aligned? %@", AlignToString(botRightBitWise)); ->
Align botRight = AlignBottomRight;
Align botRightBitWise = AlignBottom | AlignRight;

NSLog(@"Are They The Same: %@", (botRightBitWise == botRight) ? @"YES" : @"NO");
//=> Are They The Same: YES

> How is that combo aligned? AlignBottomRight
But better, because you can go to-and-fro string values:

NSLog(@"How is that combo aligned? %@", AlignToString(botRightBitWise));
//=> How is that combo aligned? AlignBottomRight

JREnum currently <s>only supports integer explicit values (bit shifts and masks won't work).</s> Patches welcome.
## TODO

- [Use NS_ENUM to declare enums](https://github.com/rentzsch/JREnum/issues/8)

## Version History

### v1.1: Mar 25 2014

* [NEW] Add support for hex constants. ([Alex Gray](https://github.com/rentzsch/JREnum/pull/5))
* [NEW] Add support for very simple bit-shifting constants. (rentzsch)

### v1.0.1: May 28 2013

* [FIX] Suppress local unused variable warnings. ([maniak-dobrii](https://github.com/rentzsch/JREnum/commit/918f24f9b098358d062bbbccd6c66e0304be8caa))

### v1.0: Apr 09 2013

* Minor bug fix from 0.2.
Expand Down

0 comments on commit 2086303

Please sign in to comment.