Empirical
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT > Class Template Reference

InstLib maintains a set of instructions for use in virtual hardware. More...

#include <InstLib.h>

Inheritance diagram for emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >:
emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >

Classes

struct  InstDef
 

Public Types

using hardware_t = HARDWARE_T
 
using inst_t = typename hardware_t::inst_t
 
using genome_t = emp::vector< inst_t >
 
using arg_t = ARG_T
 
using fun_t = std::function< void(hardware_t &, const inst_t &)>
 
using inst_properties_t = std::unordered_set< std::string >
 

Public Member Functions

 InstLib ()
 Default Constructor. More...
 
 InstLib (const InstLib &)=default
 Copy Constructor. More...
 
 InstLib (InstLib &&)=default
 Move Constructor. More...
 
 ~InstLib ()
 Destructor. More...
 
InstLiboperator= (const InstLib &)=default
 Copy Operator. More...
 
InstLiboperator= (InstLib &&)=default
 Move Operator. More...
 
const std::string & GetName (size_t id) const
 Return the name associated with the specified instruction ID. More...
 
const fun_tGetFunction (size_t id) const
 Return the function associated with the specified instruction ID. More...
 
size_t GetNumArgs (size_t id) const
 Return the number of arguments expected for the specified instruction ID. More...
 
const std::string & GetDesc (size_t id) const
 Return the provided description for the provided instruction ID. More...
 
ScopeType GetScopeType (size_t id) const
 What type of scope does this instruction state? ScopeType::NONE is default. More...
 
size_t GetScopeArg (size_t id) const
 If this instruction alters scope, identify which argument does so. More...
 
const inst_properties_tGetProperties (size_t id) const
 Return the set of properties for the provided instruction ID. More...
 
bool HasProperty (size_t id, std::string property) const
 Does the given instruction ID have the given property value? More...
 
size_t GetSize () const
 Get the number of instructions in this set. More...
 
bool IsInst (const std::string name) const
 
size_t GetID (const std::string &name) const
 Return the ID of the instruction that has the specified name. More...
 
arg_t GetArg (const std::string &name)
 Return the argument value associated with the provided keyword. More...
 
void AddInst (const std::string &name, const fun_t &fun_call, size_t num_args=0, const std::string &desc="", ScopeType scope_type=ScopeType::NONE, size_t scope_arg=(size_t)-1, const inst_properties_t &inst_properties=inst_properties_t())
 Add a new instruction to the set. More...
 
void AddArg (const std::string &name, arg_t value)
 Specify a keyword and arg value. More...
 
void ProcessInst (hardware_t &hw, const inst_t &inst) const
 Process a specified instruction in the provided hardware. More...
 
template<typename IN_HW >
void ProcessInst (emp::Ptr< IN_HW > hw, const inst_t &inst) const
 Process a specified instruction on hardware that can be converted to the correct type. More...
 
void WriteGenome (const genome_t &genome, std::ostream &os=std::cout) const
 Write out a full genome to the provided ostream. More...
 
void ReadInst (genome_t &genome, std::string info) const
 Read the instruction in the provided info and append it to the provided genome. More...
 

Static Public Member Functions

static constexpr char GetSymbol (size_t id)
 Retrieve a unique letter associared with the specified instruction ID. More...
 
static constexpr size_t GetID (char symbol)
 Return the ID of the instruction associated with the specified symbol. More...
 

Protected Attributes

emp::vector< InstDefinst_lib
 Full definitions for instructions. More...
 
emp::vector< fun_tinst_funs
 Map of instruction IDs to their functions. More...
 
std::map< std::string, size_t > name_map
 How do names link to instructions? More...
 
std::map< std::string, arg_targ_map
 How are different arguments named? More...
 

Detailed Description

template<typename HARDWARE_T, typename ARG_T = size_t, size_t ARG_COUNT = 3>
class emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >

InstLib maintains a set of instructions for use in virtual hardware.

Parameters
HARDWARE_TType of the virtual hardware class to track instructions.
ARG_TWhat types of arguments are associated with instructions.
ARG_COUNTMax number of arguments on an instruction.

Member Typedef Documentation

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
using emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::arg_t = ARG_T
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
using emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::fun_t = std::function<void(hardware_t &, const inst_t &)>
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
using emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::genome_t = emp::vector<inst_t>
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
using emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::hardware_t = HARDWARE_T
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
using emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::inst_properties_t = std::unordered_set<std::string>
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
using emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::inst_t = typename hardware_t::inst_t

Constructor & Destructor Documentation

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::InstLib ( )
inline

Default Constructor.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::InstLib ( const InstLib< HARDWARE_T, ARG_T, ARG_COUNT > &  )
default

Copy Constructor.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::InstLib ( InstLib< HARDWARE_T, ARG_T, ARG_COUNT > &&  )
default

Move Constructor.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::~InstLib ( )
inline

Destructor.

Member Function Documentation

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
void emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::AddArg ( const std::string &  name,
arg_t  value 
)
inline

Specify a keyword and arg value.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
void emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::AddInst ( const std::string &  name,
const fun_t fun_call,
size_t  num_args = 0,
const std::string &  desc = "",
ScopeType  scope_type = ScopeType::NONE,
size_t  scope_arg = (size_t) -1,
const inst_properties_t inst_properties = inst_properties_t() 
)
inline

Add a new instruction to the set.

Parameters
nameA unique string name for this instruction.
fun_callThe function that should be called when this instruction is executed.
num_argsHow many arguments does this function require? (default=0)
descA description of how this function operates. (default="")
scope_typeType of scope does this instruction creates. (default=ScopeType::NONE)
scope_argIf instruction changes scope, which argument specified new scope? (defualt=-1)
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
arg_t emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::GetArg ( const std::string &  name)
inline

Return the argument value associated with the provided keyword.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
const std::string& emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::GetDesc ( size_t  id) const
inline

Return the provided description for the provided instruction ID.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
const fun_t& emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::GetFunction ( size_t  id) const
inline

Return the function associated with the specified instruction ID.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
size_t emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::GetID ( const std::string &  name) const
inline

Return the ID of the instruction that has the specified name.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
static constexpr size_t emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::GetID ( char  symbol)
inlinestatic

Return the ID of the instruction associated with the specified symbol.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
const std::string& emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::GetName ( size_t  id) const
inline

Return the name associated with the specified instruction ID.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
size_t emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::GetNumArgs ( size_t  id) const
inline

Return the number of arguments expected for the specified instruction ID.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
const inst_properties_t& emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::GetProperties ( size_t  id) const
inline

Return the set of properties for the provided instruction ID.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
size_t emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::GetScopeArg ( size_t  id) const
inline

If this instruction alters scope, identify which argument does so.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
ScopeType emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::GetScopeType ( size_t  id) const
inline

What type of scope does this instruction state? ScopeType::NONE is default.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
size_t emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::GetSize ( ) const
inline

Get the number of instructions in this set.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
static constexpr char emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::GetSymbol ( size_t  id)
inlinestatic

Retrieve a unique letter associared with the specified instruction ID.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
bool emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::HasProperty ( size_t  id,
std::string  property 
) const
inline

Does the given instruction ID have the given property value?

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
bool emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::IsInst ( const std::string  name) const
inline
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
InstLib& emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::operator= ( const InstLib< HARDWARE_T, ARG_T, ARG_COUNT > &  )
default

Copy Operator.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
InstLib& emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::operator= ( InstLib< HARDWARE_T, ARG_T, ARG_COUNT > &&  )
default

Move Operator.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
void emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::ProcessInst ( hardware_t hw,
const inst_t inst 
) const
inline

Process a specified instruction in the provided hardware.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
template<typename IN_HW >
void emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::ProcessInst ( emp::Ptr< IN_HW >  hw,
const inst_t inst 
) const
inline

Process a specified instruction on hardware that can be converted to the correct type.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
void emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::ReadInst ( genome_t genome,
std::string  info 
) const
inline

Read the instruction in the provided info and append it to the provided genome.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
void emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::WriteGenome ( const genome_t genome,
std::ostream &  os = std::cout 
) const
inline

Write out a full genome to the provided ostream.

Member Data Documentation

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
std::map<std::string, arg_t> emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::arg_map
protected

How are different arguments named?

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
emp::vector<fun_t> emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::inst_funs
protected

Map of instruction IDs to their functions.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
emp::vector<InstDef> emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::inst_lib
protected

Full definitions for instructions.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
std::map<std::string, size_t> emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::name_map
protected

How do names link to instructions?


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