MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | Protected Attributes | Friends
MFM::Atom< CC > Class Template Reference

#include <Atom.h>

Public Member Functions

bool IsSane () const
 
bool HasBeenRepaired ()
 
u32 GetType () const
 
void Print (ByteSink &ostream) const
 
void WriteStateBits (ByteSink &ostream) const
 
void ReadStateBits (const char *hexStr)
 
void ReadStateBits (const BitVector< BPA > &bv)
 
void WriteBits (ByteSink &ostream) const
 
void ReadBits (const char *hexStr)
 
void XRay (Random &rand, u32 bitOdds)
 
bool operator== (const Atom &rhs) const
 
bool operator!= (const Atom &rhs) const
 

Static Public Member Functions

static bool IsType (const T &atom, u32 type)
 
static bool IsSameType (const T &atom, const T &other)
 

Protected Attributes

BitVector< BPA > m_bits
 

Friends

class VD
 
class Element< CC >
 
class AtomSerializer< CC >
 
template<class BV , VD::Type , u32 , u32 >
class BitField
 

Detailed Description

template<class CC>
class MFM::Atom< CC >

An Atom is a fixed-size collection of bits, representing an instance of an Element in the Movable Feast Machine. The contents of a site is currently a single Atom.

In general, an Atom is the MFM analog to an 'object' in an object-oriented programming language, as Element is the MFM analog to a 'class'. Be warned, however, that the analogy is very loose! Atoms are both fixed size and very small, comprising dozens or perhaps hundreds of bits only.

The Atom class is abstract; subclasses are to provide details of atomic structure, but note Atom contains NO virtual methods. Our goal is to avoid incurring the cost of a vtable pointer on every Atom instance, so all Atom accesses must be by template type rather than by base class polymorphism.

In addition to the 'virtually virtual' methods that Atom subclasses must provide (i.e., the methods documented as 'This is to be defined only by a subclass of Atom'), Atom subclasses must also provide compile time constants: ATOM_CATEGORY and ATOM_FIRST_STATE_BIT.

Member Function Documentation

template<class CC>
u32 MFM::Atom< CC >::GetType ( ) const
inline

Gets the type of this Atom.

Returns
The type of this Atom.
Remarks
This delegates to GetTypeImpl in the subclass of Atom.
template<class CC>
bool MFM::Atom< CC >::HasBeenRepaired ( )
inline

Assuming IsSane has returned false, this attempts to correct the type of this atom, if it is possible to do.

Returns
true if this Atom now has a legal type, false if the type is so damaged it should just be destroyed
Remarks
This delegates to HasBeenRepairedImpl in the subclass of Atom.
template<class CC>
static bool MFM::Atom< CC >::IsSameType ( const T &  atom,
const T &  other 
)
inlinestatic

Checks to see if two atoms are of the same type.

Parameters
atomOne atom to check the type of
otherThe other atom to check the type of
Returns
true of both Atoms are the same type.
template<class CC>
bool MFM::Atom< CC >::IsSane ( ) const
inline

Checks to see if this Atom has a reasonable enough bit pattern within its BitVector to not be considered illegal.

Returns
true if this Atom is considered to be in a legal state, else false.
Remarks
This delegates to IsSaneImpl in the subclass of Atom.
template<class CC>
static bool MFM::Atom< CC >::IsType ( const T &  atom,
u32  type 
)
inlinestatic

Checks to see if a specified Atom is of a particular type.

Parameters
atomThe atom to check the type of.
typeThe Atomic type to check atom for membership of.
Returns
true if atom is of type type.
template<class CC>
void MFM::Atom< CC >::Print ( ByteSink ostream) const
inline

Prints this Atom in a semi-readable way to a ByteSink.

Remarks
This delegates to PrintImpl in the subclass of Atom.
template<class CC>
void MFM::Atom< CC >::ReadBits ( const char *  hexStr)
inline

Reads bits from a ByteSource in hex format, replacing the bits of this Atom with the read bits.

Parameters
inStreamThe ByteSource to read bits from.
template<class CC>
void MFM::Atom< CC >::ReadStateBits ( const char *  hexStr)
inline

Reads the State bits of this atom from a given hex-encoded char* .

Remarks
This delegates to ReadStateBits in the subclass of Atom.
template<class CC>
void MFM::Atom< CC >::ReadStateBits ( const BitVector< BPA > &  bv)
inline

Reads the State bits of this atom from a BitVector. Only the non-type bits are copied.

Remarks
This delegates to ReadStateBits in the subclass of Atom.
template<class CC>
void MFM::Atom< CC >::WriteBits ( ByteSink ostream) const
inline

Writes the internal bits of this Atom to a ByteSink in hex format.

Parameters
ostreamThe ByteSink to write the bits of this Atom to.
template<class CC>
void MFM::Atom< CC >::WriteStateBits ( ByteSink ostream) const
inline

Writes all bits of this Atom to a ByteSink. These bits must not include the type bits of this Atom.

Remarks
This delegates to WriteStateBits in the subclass of Atom.
template<class CC>
void MFM::Atom< CC >::XRay ( Random rand,
u32  bitOdds 
)
inline

Randomly flips some of the bits in this Atom's BitVector.

Parameters
randThe PRNG used to determine randomness of bit flipping.
bitOddsThe odds (one in these odds) that a particular bit will be flipped.

Field Documentation

template<class CC>
BitVector<BPA> MFM::Atom< CC >::m_bits
protected

The state of this Atom, in its entirety. All fields of this atom are contained in this BitVector.


The documentation for this class was generated from the following file: