guts
Loading...
Searching...
No Matches
gutilities.cc File Reference
#include "gutilities.h"
#include "gutsConventions.h"
#include "CLHEP/Units/PhysicalConstants.h"
#include "G4UImanager.hh"
#include <dirent.h>
#include <locale.h>
#include <sys/stat.h>
#include <algorithm>
#include <sstream>
#include <unordered_map>
#include <iostream>
#include <fstream>
#include <vector>
#include <charconv>
#include <filesystem>
Include dependency graph for gutilities.cc:

Go to the source code of this file.

Namespaces

namespace  gutilities

Functions

bool gutilities::hasExtension (const std::string &filename, const std::vector< std::string > &extensions)
bool gutilities::is_unset (std::string_view s)
 Determine whether a string should be treated as "unset".
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.
bool gutilities::directoryExists (const std::string &path)
 Checks if a directory exists at the given path.
std::optional< std::filesystem::path > gutilities::searchForDirInLocations (const string &dirName, const vector< string > &possibleLocations)
 Searches for a directory within a list of possible locations.
vector< string > gutilities::getListOfFilesInDirectory (const string &dirName, const vector< string > &extensions)
 Retrieves a list of files with specific extensions from a directory.
std::optional< std::string > gutilities::searchForFileInLocations (const std::vector< std::string > &locations, std::string_view filename)
 Search for a regular file across candidate locations.
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
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.
G4Colour gutilities::makeG4Colour (std::string_view code, double opacity)
 Convert a hex colour string to G4Colour.