helics  3.5.2
Public Member Functions | List of all members
helics::apps::Player Class Reference

#include <Player.hpp>

+ Inheritance diagram for helics::apps::Player:

Public Member Functions

 Player ()=default
 
 Player (std::vector< std::string > args)
 
 Player (int argc, char *argv[])
 
 Player (std::string_view name, const FederateInfo &fi)
 
 Player (std::string_view name, const std::shared_ptr< Core > &core, const FederateInfo &fi)
 
 Player (std::string_view name, CoreApp &core, const FederateInfo &fi)
 
 Player (std::string_view appName, const std::string &configString)
 
 Player (Player &&other_player)=default
 
Playeroperator= (Player &&fed)=default
 
virtual void initialize () override
 
virtual void runTo (Time stopTime_input) override
 
void addPublication (std::string_view name, DataType type, std::string_view pubUnits=std::string_view())
 
template<class valType >
std::enable_if_t< helicsType< valType >) !=DataType::HELICS_CUSTOM > addPublication (std::string_view key, std::string_view pubUnits=std::string_view())
 
void addEndpoint (std::string_view endpointName, std::string_view endpointType=std::string_view())
 
template<class valType >
void addPoint (Time pubTime, std::string_view key, const valType &val)
 
template<class valType >
void addPoint (Time pubTime, int iteration, std::string_view key, const valType &val)
 
void addMessage (Time sendTime, std::string_view src, std::string_view dest, std::string_view payload)
 
void addMessage (Time sendTime, Time actionTime, std::string_view src, std::string_view dest, std::string_view payload)
 
auto pointCount () const
 
auto messageCount () const
 
auto publicationCount () const
 
auto endpointCount () const
 
const auto & getPoint (int index) const
 
const auto & getMessage (int index) const
 
- Public Member Functions inherited from helics::apps::App
 App ()=default
 
 App (std::string_view defaultAppName, std::vector< std::string > args)
 
 App (std::string_view defaultAppName, int argc, char *argv[])
 
 App (std::string_view appName, const FederateInfo &fedInfo)
 
 App (std::string_view appName, const std::shared_ptr< Core > &core, const FederateInfo &fedInfo)
 
 App (std::string_view appName, CoreApp &core, const FederateInfo &fedInfo)
 
 App (std::string_view appName, const std::string &configString)
 
 App (App &&other_app)=default
 
 App (const App &other_app)=delete
 
Appoperator= (App &&app)=default
 
Appoperator= (const App &app)=delete
 
void loadFile (const std::string &filename, bool enableFederateInterfaceRegistration=true)
 
virtual void run ()
 
virtual void finalize ()
 
bool isActive () const
 
const CombinationFederateaccessUnderlyingFederate () const
 

Additional Inherited Members

- Protected Member Functions inherited from helics::apps::App
void loadJsonFileConfiguration (const std::string &appName, const std::string &jsonString, bool enableFederateInterfaceRegistration)
 
void loadInputFiles ()
 
void loadConfigOptions (AppTextParser &aparser)
 
- Protected Attributes inherited from helics::apps::App
std::shared_ptr< CombinationFederatefed
 the federate created for the App
 
Time stopTime = Time::maxVal()
 the time the App should stop
 
std::string configFileName
 name of the config file used for constructing the federate
 
std::string inputFileName
 the name of the app input file
 
bool useLocal {false}
 
bool fileLoaded {false}
 
bool deactivated {false}
 
bool quietMode {false}
 
bool helpMode {false}
 
std::vector< std::string > remArgs
 

Detailed Description

class implementing a Player object, which is capable of reading a file and generating interfaces and sending signals at the appropriate times

the Player class is not thread-safe, don't try to use it from multiple threads without external protection, that will result in undefined behavior

Constructor & Destructor Documentation

◆ Player() [1/8]

helics::apps::Player::Player ( )
default

default constructor

◆ Player() [2/8]

helics::apps::Player::Player ( std::vector< std::string >  args)
explicit

construct from command line arguments in a vector

Parameters
argsthe command line arguments to pass in a reverse vector

◆ Player() [3/8]

helics::apps::Player::Player ( int  argc,
char *  argv[] 
)

construct from command line arguments

Parameters
argcthe number of arguments
argvthe strings in the input

◆ Player() [4/8]

helics::apps::Player::Player ( std::string_view  name,
const FederateInfo fi 
)
explicit

construct from a federate info object

Parameters
namethe name of the federate (can be empty to use defaults from fi)
fia pointer info object containing information on the desired federate configuration

◆ Player() [5/8]

helics::apps::Player::Player ( std::string_view  name,
const std::shared_ptr< Core > &  core,
const FederateInfo fi 
)

constructor taking a federate information structure and using the given core

Parameters
namethe name of the federate (can be empty to use defaults from fi)
corea pointer to core object which the federate can join
fia federate information structure

◆ Player() [6/8]

helics::apps::Player::Player ( std::string_view  name,
CoreApp &  core,
const FederateInfo fi 
)

constructor taking a federate information structure and using the given core

Parameters
namethe name of the federate (can be empty to use defaults from fi)
corea coreApp object that can be joined
fia federate information structure

◆ Player() [7/8]

helics::apps::Player::Player ( std::string_view  appName,
const std::string &  configString 
)

constructor taking a file with the required information

Parameters
appNamethe name of the app
configStringJSON, TOML or text file or JSON string defining the federate information and other configuration

◆ Player() [8/8]

helics::apps::Player::Player ( Player &&  other_player)
default

move construction

Member Function Documentation

◆ addEndpoint()

void helics::apps::Player::addEndpoint ( std::string_view  endpointName,
std::string_view  endpointType = std::string_view() 
)

add an endpoint to the Player

Parameters
endpointNamethe name of the endpoint
endpointTypethe named type of the endpoint

◆ addMessage() [1/2]

void helics::apps::Player::addMessage ( Time  sendTime,
std::string_view  src,
std::string_view  dest,
std::string_view  payload 
)

add a message to a Player queue

Parameters
sendTimethe time the message should be sent
srcthe source endpoint of the message
destthe destination endpoint of the message
payloadthe payload of the message

◆ addMessage() [2/2]

void helics::apps::Player::addMessage ( Time  sendTime,
Time  actionTime,
std::string_view  src,
std::string_view  dest,
std::string_view  payload 
)

add an event for a specific time to a Player queue

Parameters
sendTimethe time the message should be sent
actionTimethe eventTime listed for the message
srcthe source endpoint of the message
destthe destination endpoint of the message
payloadthe payload of the message

◆ addPoint() [1/2]

template<class valType >
void helics::apps::Player::addPoint ( Time  pubTime,
int  iteration,
std::string_view  key,
const valType &  val 
)
inline

add a data point to publish through a Player

Parameters
pubTimethe time of the publication
iterationthe iteration count on which the value should be published
keythe key for the publication
valthe value to publish

◆ addPoint() [2/2]

template<class valType >
void helics::apps::Player::addPoint ( Time  pubTime,
std::string_view  key,
const valType &  val 
)
inline

add a data point to publish through a Player

Parameters
pubTimethe time of the publication
keythe key for the publication
valthe value to publish

◆ addPublication() [1/2]

template<class valType >
std::enable_if_t<helicsType<valType>) != DataType::HELICS_CUSTOM> helics::apps::Player::addPublication ( std::string_view  key,
std::string_view  pubUnits = std::string_view() 
)
inline

add a publication to a Player

Parameters
keythe key of the publication to add
pubUnitsthe units associated with the publication

◆ addPublication() [2/2]

void helics::apps::Player::addPublication ( std::string_view  name,
DataType  type,
std::string_view  pubUnits = std::string_view() 
)

add a publication to a Player

Parameters
namethe identifier of the publication to add
typethe type of the publication
pubUnitsthe units associated with the publication

◆ endpointCount()

auto helics::apps::Player::endpointCount ( ) const
inline

get the number of endpoints

◆ getMessage()

const auto& helics::apps::Player::getMessage ( int  index) const
inline

get the messages from an index

◆ getPoint()

const auto& helics::apps::Player::getPoint ( int  index) const
inline

get the point from an index

◆ initialize()

void helics::apps::Player::initialize ( )
overridevirtual

initialize the Player federate

generate all the publications and organize the points, the final publication count will be available after this time and the Player will enter the initialization mode, which means it will not be possible to add more publications calling run will automatically do this if necessary

Reimplemented from helics::apps::App.

References helics::apps::App::fed, and helics::Federate::STARTUP.

Referenced by runTo().

◆ messageCount()

auto helics::apps::Player::messageCount ( ) const
inline

get the number of messages loaded

◆ operator=()

Player& helics::apps::Player::operator= ( Player &&  fed)
default

move assignment

◆ pointCount()

auto helics::apps::Player::pointCount ( ) const
inline

get the number of points loaded

◆ publicationCount()

auto helics::apps::Player::publicationCount ( ) const
inline

get the number of publications

◆ runTo()

void helics::apps::Player::runTo ( Time  stopTime_input)
overridevirtual

run the Player until the specified time

Parameters
stopTime_inputthe desired stop time

Implements helics::apps::App.

References helics::Federate::EXECUTING, helics::apps::App::fed, helics::FORCE_ITERATION, initialize(), helics::isValidIndex(), helics::Federate::STARTUP, and helics::timeZero.


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