Gromacs
2024.3
|
#include <gromacs/utility/programcontext.h>
Provides context information about the program that is calling the library.
This class provides access to information about the program that is currently running. This information is used to provide better information to the user, and to locate the GROMACS data files.
setProgramContext() should be called before any other GROMACS calls in a program (except for gmx::init()). This avoids thread safety issues, and allows nicely formatted error messages.
For thread safety, the implementations of the interface should ensure that the returned strings remain valid until the end of the program (see getProgramContext() for discussion on deinitialization). Callers of the interface within GROMACS are prepared for exceptions, but generally terminate the program on any exception. Implementations should avoid exception except for truly fatal conditions.
The destructor is protected to signify that the context is never destroyed through the interface.
Public Member Functions | |
virtual const char * | programName () const =0 |
Returns the name of the binary as it was invoked without any path. More... | |
virtual const char * | displayName () const =0 |
Returns a display name for the program. More... | |
virtual std::filesystem::path | fullBinaryPath () const =0 |
Returns the full path of the running binary. More... | |
virtual InstallationPrefixInfo | installationPrefix () const =0 |
Returns the installation prefix for GROMACS. More... | |
virtual const char * | commandLine () const =0 |
Returns the full command line used to invoke the binary. More... | |
|
pure virtual |
Returns the full command line used to invoke the binary.
The implementation can provide an empty string if no command line is available.
Implemented in gmx::CommandLineProgramContext, gmx::test::anonymous_namespace{testinit.cpp}::TestProgramContext, and gmx::anonymous_namespace{programcontext.cpp}::DefaultProgramContext.
|
pure virtual |
Returns a display name for the program.
For simple programs, this can equal programName(). For the GROMACS gmx
wrapper binary, this includes the name of the module (e.g., gmx angle
). This is used only for informational purposes, and there are no constraints on contents, except that it should not be NULL
.
Implemented in gmx::CommandLineProgramContext, gmx::test::anonymous_namespace{testinit.cpp}::TestProgramContext, and gmx::anonymous_namespace{programcontext.cpp}::DefaultProgramContext.
|
pure virtual |
Returns the full path of the running binary.
This is mainly used for informational purposes. There are no constraints on contents, except that it should not be NULL
. Currently, this is also used for sanity checks in checkpointing.
The implementation can provide an empty string if the path to the binary is not available. In such a case, the information is not shown.
Implemented in gmx::CommandLineProgramContext, gmx::test::anonymous_namespace{testinit.cpp}::TestProgramContext, and gmx::anonymous_namespace{programcontext.cpp}::DefaultProgramContext.
|
pure virtual |
Returns the installation prefix for GROMACS.
This path is used to locate the data files that are in share/top/
in the source directory. The implementation can provide an empty string if the path is not available; in such a case, functions that require data files may fail.
The returned structure also contains a flag to indicate whether the prefix actually points to the source tree. This is used for tests and to support running binaries directly from the build tree.
Implemented in gmx::CommandLineProgramContext, gmx::test::anonymous_namespace{testinit.cpp}::TestProgramContext, and gmx::anonymous_namespace{programcontext.cpp}::DefaultProgramContext.
|
pure virtual |
Returns the name of the binary as it was invoked without any path.
This is typically argv[0]
with any leading directory stripped. Currently, this should be a valid file name.
Implemented in gmx::CommandLineProgramContext, gmx::test::anonymous_namespace{testinit.cpp}::TestProgramContext, and gmx::anonymous_namespace{programcontext.cpp}::DefaultProgramContext.