Table of Contents

Atomic Parameters

This tutorial describes the current procedure for adding a parameter to an Atom. This is used when an Atom needs to use its bits for some kind of information.

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 which can hold a byte:

enum
{
    BITS = P::BITS_PER_ATOM,
    
    BYTE_BITS_LENGTH = 8,
    BYTE_BITS_POSITION = BITS - BYTE_BITS_LENGTH - 1
};

These constants are then used to describe a BitField, like so:

typedef BitField<BitVector<BITS>, BYTE_BITS_LENGTH, BYTE_BITS_POSITION> AFByteBits;

make sure that BitField is included in the file by adding:

#include "BitField.h"

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::Read(this->GetBits(us));
}

void SetByteBits(T& us, u32 bits) const
{
    AFByteBits::Write(this->GetBits(us), bits & 0xff);
}

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(), 0, 0, 0);
    this->SetByteBits(defaultAtom, 0 /* Or other default value */);
    
    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.