|
guts
|
Public API for the gutilities namespace. More...
#include <vector>#include <string>#include <map>#include <string_view>#include <optional>#include "G4Colour.hh"#include "G4UImanager.hh"#include <filesystem>

Go to the source code of this file.
Namespaces | |
| namespace | gutilities |
Functions | |
| std::filesystem::path | gutilities::executable_path () |
| Get the absolute canonical path to the current executable. | |
| std::filesystem::path | gutilities::gemc_root () |
| Infer the GEMC installation root directory from the executable location. | |
| bool | gutilities::is_unset (std::string_view s) |
| Determine whether a string should be treated as "unset". | |
| std::string | gutilities::success_or_fail (bool condition) |
| Convert a boolean condition to a stable status string. | |
| void | gutilities::apply_uimanager_commands (const std::string &commands) |
| Apply a single Geant4 UI command if a UI manager is available. | |
String normalization and tokenization | |
| string | gutilities::removeLeadingAndTrailingSpacesFromString (const std::string &input) |
| Removes leading and trailing spaces and tabs from a string. | |
| std::string_view | gutilities::removeLeadingAndTrailingSpacesFromString (const std::string_view input) |
| Removes leading and trailing whitespace from a string view (no allocation). | |
| string | gutilities::removeAllSpacesFromString (const std::string &str) |
| Removes all spaces from a string. | |
| vector< std::string > | gutilities::getStringVectorFromString (const std::string &input) |
| Splits a string into a vector of strings using whitespace as delimiters. | |
| string | gutilities::replaceCharInStringWithChars (const std::string &input, const std::string &toReplace, const std::string &replacement) |
| Replaces all occurrences of specified characters in a string with another string. | |
| string | gutilities::replaceAllStringsWithString (const string &source, const string &from, const string &to) |
| Replaces all occurrences of a substring with another string. | |
| string | gutilities::fillDigits (const string &word, const string &c, int ndigits) |
| Pads a string with a specified character until it reaches a desired length. | |
Path and filesystem helpers | |
| string | gutilities::getFileFromPath (const std::string &path) |
| Extracts the filename from a given file path. | |
| string | gutilities::getDirFromPath (const std::string &path) |
| Extracts the directory path from a given file path. | |
| std::optional< std::string > | gutilities::searchForFileInLocations (const std::vector< std::string > &locations, std::string_view filename) |
| Search for a regular file across candidate locations. | |
| bool | gutilities::directoryExists (const std::string &path) |
| Checks if a directory exists at the given path. | |
| string | gutilities::searchForDirInLocations (const string &dirName, const vector< string > &possibleLocations) |
| Searches for a directory within a list of possible locations. | |
| bool | gutilities::hasExtension (const string &filename, const vector< string > &extensions) |
| Checks if a filename has one of the specified extensions. | |
| vector< string > | gutilities::getListOfFilesInDirectory (const string &dirName, const vector< string > &extensions) |
| Retrieves a list of files with specific extensions from a directory. | |
Numeric parsing with optional units | |
| double | gutilities::getG4Number (const string &v, bool warnIfNotUnit=false) |
| Converts a string representation of a number with optional units to a double. | |
| double | gutilities::getG4Number (double input, const string &unit) |
| Converts a numeric value with a unit into a Geant4-number string and parses it. | |
| vector< double > | gutilities::getG4NumbersFromStringVector (const vector< string > &vstring, bool warnIfNotUnit=false) |
| Converts a vector of strings representing numbers with units to a vector of doubles. | |
| vector< double > | gutilities::getG4NumbersFromString (const string &vstring, bool warnIfNotUnit=false) |
| Converts a comma-separated string of numbers with units to a vector of doubles. | |
Text file parsing and substring extraction | |
| string | gutilities::parseFileAndRemoveComments (const string &filename, const string &commentChars="#", int verbosity=0) |
| Parses a file and removes all lines containing specified comment characters. | |
| string | gutilities::retrieveStringBetweenChars (const string &input, const string &firstDelimiter, const string &secondDelimiter) |
| Retrieves a substring between two specified delimiters in a string. | |
| vector< string > | gutilities::getStringVectorFromStringWithDelimiter (const string &input, const string &x) |
| Splits a string into a vector of substrings using a specified delimiter. | |
Miscellaneous helpers | |
| enum | gutilities::randomModel { gutilities::uniform , gutilities::gaussian , gutilities::cosine , gutilities::sphere } |
| Enumeration of random models. More... | |
| string | gutilities::convertToLowercase (const string &str) |
| Converts a string to lowercase. | |
| template<class KEY , class VALUE > | |
| vector< KEY > | gutilities::getKeys (const map< KEY, VALUE > &map) |
| Retrieves all keys from a map. | |
| randomModel | gutilities::stringToRandomModel (const std::string &str) |
| Converts a string to a corresponding randomModel enum value. | |
| constexpr const char * | gutilities::to_string (randomModel m) noexcept |
| Convert a randomModel enum value to a stable string token. | |
| G4Colour | gutilities::makeG4Colour (std::string_view code, double opacity) |
Convert a hex colour string to G4Colour. | |
This header declares a set of small utility functions used throughout the codebase. Most functions are pure helpers (string/path manipulation, parsing), with a few Geant4-adjacent conveniences (e.g., UI command application and G4Colour construction).
Documentation strategy:
Definition in file gutilities.h.