dev:atomic_parameters
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| dev:atomic_parameters [2014/09/09 18:42] – created tsmall1 | dev:atomic_parameters [2014/09/21 17:54] (current) – [Make Getter and Setter] tsmall1 | ||
|---|---|---|---|
| Line 5: | Line 5: | ||
| ===== Declare Compilation Constants ===== | ===== Declare Compilation Constants ===== | ||
| - | First, we need to describe in the Element how big of a field we want to use, and where to place it inside the atom. We need to use the bits on the right hand part of the atom first, since a number of ones on the left hand side are already used. For instance, let's declare a small field storing | + | First, we need to describe in the Element how big of a field we want to use, and where to place it inside the atom. We need to use the bits on the right hand part of the atom first, since a number of ones on the left hand side are already used. For instance, let's declare a small field which can hold a byte: |
| < | < | ||
| Line 12: | Line 12: | ||
| BITS = P:: | BITS = P:: | ||
| | | ||
| - | | + | |
| - | | + | |
| - | } | + | }; |
| </ | </ | ||
| Line 20: | Line 20: | ||
| < | < | ||
| - | typedef BitField< | + | typedef BitField< |
| </ | </ | ||
| + | make sure that BitField is included in the file by adding: | ||
| + | |||
| + | < | ||
| + | #include " | ||
| + | </ | ||
| + | |||
| + | to the top of the file. | ||
| + | |||
| + | ===== Make Getter and Setter ===== | ||
| + | |||
| + | We now need methods which access these bits. In the public section of your elemenet, place: | ||
| + | |||
| + | < | ||
| + | u32 GetByteBits(const T& us) const | ||
| + | { | ||
| + | return AFByteBits:: | ||
| + | } | ||
| + | |||
| + | void SetByteBits(T& | ||
| + | { | ||
| + | AFByteBits:: | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Now we are able to Get and Set these bits. | ||
| + | |||
| + | ===== Set Default Value ===== | ||
| + | |||
| + | We should also set some sort of default value for these bits. This is done by overriding the **GetDefaultAtom()** method. Place in the public section of your element: | ||
| + | |||
| + | < | ||
| + | |||
| + | static const u32 TYPE() | ||
| + | { | ||
| + | return THE_INSTANCE.GetType(); | ||
| + | } | ||
| + | |||
| + | virtual const T& GetDefaultAtom() const | ||
| + | { | ||
| + | static T defaultAtom(TYPE(), | ||
| + | this-> | ||
| + | | ||
| + | return defaultAtom; | ||
| + | } | ||
| + | </ | ||
| + | In this example, the default atom has its bitfield set to 0. We can use this call during the behavior method as well to read or write bits of other atoms. | ||
dev/atomic_parameters.1410288156.txt.gz · Last modified: 2014/09/09 18:42 by tsmall1
