Class AgentDescription

Class Documentation

class AgentDescription

Within the model hierarchy, this class represents the definition of an agent for a FLAMEGPU model This class is used to configure external elements of agents, such as variables and functions

See

AgentData The internal data store for this class

See

ModelDescription::newAgent(const std::string&) For creating instances of this class

Public Functions

bool operator==(const AgentDescription &rhs) const

Equality operator, checks whether AgentDescription hierarchies are functionally the same

Note

Instead compare pointers if you wish to check that they are the same instance

Returns

True when agents are the same

bool operator!=(const AgentDescription &rhs) const

Equality operator, checks whether AgentDescription hierarchies are functionally different

Note

Instead compare pointers if you wish to check that they are not the same instance

Returns

True when agents are not the same

void newState(const std::string &state_name)

Adds a new state to the possible states this agent can enter State’s only exist as strings and have no additional configuration

Accessors

Parameters

state_name – Name of the state

Throws

InvalidStateName – If the agent already has a state with the same name

void setInitialState(const std::string &initial_state)

Sets the initial state which new agents begin in

Parameters

initial_state – Name of the desired state

Throws

InvalidStateName – If the named state is not found within the agent

template<typename T, ModelData::size_type N>
void newVariable(const std::string &variable_name, const std::array<T, N> &default_value = {})

Adds a new variable to the agent

Template implementation

Parameters
  • variable_name – Name of the variable

  • default_value – Default value of variable for new agents if unset, defaults to 0

Template Parameters
  • T – Type of the agent variable, this must be an arithmetic type

  • N – The length of the variable array (1 if not an array, must be greater than 0)

Throws
template<typename T>
void newVariable(const std::string &variable_name, const T &default_value = 0)
template<typename AgentFunction>
AgentFunctionDescription &newFunction(const std::string &function_name, AgentFunction a = AgentFunction())

Adds a new (device) function to the agent

Note

The same agent function can be passed to the same agent twice

Parameters
  • function_name – Name of the functions

  • a – Instance of the agent function, used to implicitly set the template arg Should be declared using FLAMEGPU_AGENT_FUNCTION notation

Template Parameters

AgentFunction – The agent function’s containing struct type

Throws

InvalidAgentFunc – If a variable already exists within the agent with the same name

Returns

A mutable reference to the new AgentFunctionDescription

AgentFunctionDescription &newRTCFunction(const std::string &function_name, const char *func_src)

Adds a new runtime (device) function to the agent

Note

The same agent function can be passed to the same agent twice

Parameters
  • function_name – Name of the functions

  • func_src – representation of an agent function Should be declared using FLAMEGPU_AGENT_FUNCTION notation

Throws

InvalidAgentFunc – If a variable already exists within the agent with the same name

Returns

A mutable reference to the new AgentFunctionDescription

AgentFunctionDescription &Function(const std::string &function_name)

Returns a mutable reference to the named agent function, which can be used to configure the function

See

AgentDescription::getFunction(const std::string &) for the immutable version

Parameters

function_name – Name used to refer to the desired agent function

Throws

InvalidAgentFunc – If a functions with the name does not exist within the agent

Returns

A mutable reference to the specified AgentFunctionDescription

std::string getName() const

Const Accessors

Returns

The agent’s name

ModelData::size_type getStatesCount() const
Returns

The number of possible states agents of this type can enter

std::string getInitialState() const
Returns

The state which newly created agents of this type begin in

const std::type_index &getVariableType(const std::string &variable_name) const
Parameters

variable_name – Name used to refer to the desired variable

Throws

InvalidAgentVar – If a variable with the name does not exist within the agent

Returns

The type of the named variable

size_t getVariableSize(const std::string &variable_name) const
Parameters

variable_name – Name used to refer to the desired variable

Throws

InvalidAgentVar – If a variable with the name does not exist within the agent

Returns

The size of the named variable’s type

ModelData::size_type getVariableLength(const std::string &variable_name) const
Parameters

variable_name – Name used to refer to the desired variable

Throws

InvalidAgentVar – If a variable with the name does not exist within the agent

Returns

The number of elements in the name variable (1 if it isn’t an array)

ModelData::size_type getVariablesCount() const

The total number of variables within the agent

const AgentFunctionDescription &getFunction(const std::string &function_name) const

Returns an immutable reference to the named agent function

See

AgentDescription::Function(const std::string &) for the mutable version

Parameters

function_name – Name used to refer to the desired agent function

Throws

InvalidAgentFunc – If a function with the name does not exist within the agent

Returns

An immutable reference to the specified AgentFunctionDescription

ModelData::size_type getFunctionsCount() const

The total number of functions within the agent

ModelData::size_type getAgentOutputsCount() const

The total number of agent functions, within the model hierarchy, which create new agents of this type

See

AgentDescription::isOutputOnDevice()

bool hasState(const std::string &state_name) const
Parameters

state_name – Name of the state to check

Returns

True when a state with the specified name exists within the agent

bool hasVariable(const std::string &variable_name) const
Parameters

variable_name – Name of the variable to check

Returns

True when a variable with the specified name exists within the agent

bool hasFunction(const std::string &function_name) const
Parameters

function_name – Name of the function to check

Returns

True when a function with the specified name exists within the agent

bool isOutputOnDevice() const
const std::set<std::string> &getStates() const