NxLibCommand

class NxLibCommand

This class simplifies the execution of NxLib commands. The parameters() and result() functions provide access to the corresponding parameter and result nodes of the tree. The execute() method starts the command by writing the command name to the tree and allows for synchronous and asynchronous command execution.

Public Functions

NxLibCommand(std::string const &_commandName, std::string const nodeName = "")

Parameters
  • _commandName: Name of the command to execute. This can be overwritten by the execute() methods.

  • nodeName: Name of the execution slot the command should run in. By default the class will create a temporary slot used only by this instance of NxLibCommand, which is automatically deleted in the destructor.

NxLibItem const &slot() const

The slot returns the NxLibItem the NxLibCommand is running on.

Return

NxLibItem the command runs on.

NxLibItem const parameters() const

The command’s parameters , that will be fetched before the commands executes.

Return

NxLibItem, where the parameters are stored.

NxLibItem const result() const

The command’s result node after the command finishes.

Return

NxLibItem, in which the results are stored.

void cancel(bool wait = true) const

Cancels the current current command. Only works on commands, that support the Break command.

Parameters
  • wait: If true, the function waits until execution of the command is finished. If set to true, the function will also throw an NxLibException if the command finished with an error.

void cancel(int *returnCode, bool wait = true) const

Cancels the current execution of the command.

Parameters
  • returnCode: The error code of the cancel operation.

  • wait: If true, the function waits until execution of the command is finished. If set to true, the function will also throw an NxLibException if the command finished with an error.

void execute(bool wait = true) const

Executes the current command.

Parameters
  • wait: If true, the function waits until execution of the command is finished. If set to true, the function will also throw an NxLibException if the command finished with an error.

void execute(int *returnCode, bool wait = true) const

Executes the current command.

Parameters
  • returnCode: The error code of the execution.

  • wait: If true, the function waits until execution of the command is finished. If set to true, the function will also throw an NxLibException if the command finished with an error.

void execute(char *_commandName, bool wait = true) const

Executes the command with the given name.

Parameters
  • _commandName: Name of the command to execute. This overwrites the command name from the constructor.

  • wait: If true, the function waits until execution of the command is finished. If set to true, the function will also throw an NxLibException if the command finished with an error.

void execute(int *returnCode, char *_commandName, bool wait = true) const

Executes the command with the given name.

Parameters
  • returnCode: The error code of the execution.

  • _commandName: Name of the command to execute. This overwrites the command name from the constructor.

  • wait: If true, the function waits until execution of the command is finished. If set to true, the function will also throw an NxLibException if the command finished with an error.

void execute(char const *_commandName, bool wait = true) const

Executes the command with the given name.

Parameters
  • _commandName: Name of the command to execute. This overwrites the command name from the constructor.

  • wait: If true, the function waits until execution of the command is finished. If set to true, the function will also throw an NxLibException if the command finished with an error.

void execute(int *returnCode, char const *_commandName, bool wait = true) const

Executes the command with the given name.

Parameters
  • returnCode: The error code of the execution.

  • _commandName: Name of the command to execute. This overwrites the command name from the constructor.

  • wait: If true, the function waits until execution of the command is finished. If set to true, the function will also throw an NxLibException if the command finished with an error.

void execute(std::string const &_commandName, bool wait = true) const

Executes the command with the given name.

Parameters
  • _commandName: Name of the command to execute. This overwrites the command name from the constructor.

  • wait: If true, the function waits until execution of the command is finished. If set to true, the function will also throw an NxLibException if the command finished with an error.

void execute(int *returnCode, std::string const &_commandName, bool wait = true) const

Executes the command with the given name.

Parameters
  • returnCode: The error code of execution.

  • _commandName: Name of the command to execute. This overwrites the command name from the constructor.

  • wait: If true, the function waits until execution of the command is finished. If set to true, the function will also throw an NxLibException if the command finished with an error.

bool finished() const

Checks whether the command execution has already finished.

Return

true, when NxLib is not currently executing a command, i.e. the command node is Null. Otherwise false.

bool finished(int *returnCode) const

Checks whether the command execution has already finished.

Return

true, when NxLib is not currently executing a command, i.e. the command node is Null. Otherwise false.

Parameters

void assertSuccessful() const

Checks whether the previous command execution is finished and was successful and throws an NxLibException if not.

bool successful() const

Checks whether the previous command execution was successful.

Return

true, when the previous NxLib command execution was successful, i.e. there is no ErrorSymbol node under the Result node. Otherwise false.

bool successful(int *returnCode) const

Checks whether the previous command execution was successful.

Return

true, when the previous NxLib command execution was successful, i.e. there is no ErrorSymbol node under the Result node. Otherwise false.

Parameters

Public Members

std::string commandName

Name of the command to execute.