EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
Classes | Macros | Functions
egs_input.cpp File Reference

EGS_Input implementation. More...

#include "egs_input.h"
#include "egs_functions.h"
#include <sstream>
#include <algorithm>
#include <cctype>
#include <fstream>
#include <vector>
#include <string>

Go to the source code of this file.

Classes

class  EGS_InputLoopVariable
 A base class for input loops. Basic functionality for input loops is provided by this class. Input loops can be used whenever a large number of similar input blocks are needed. More...
 
class  EGS_IntegerInputLoopVariable
 A base class for integer valued input loops. Basic functionality for input loops is provided by this class. More...
 
class  EGS_FloatInputLoopVariable
 A base class for real valued input loops. Basic functionality for input loops is provided by this class. More...
 
class  EGS_ListInputLoopVariable
 

Macros

#define S_STREAM   std::istringstream
 

Functions

template<class T >
int EGS_LOCAL get_input (const EGS_InputPrivate *p, const string &key, vector< T > &values)
 
template<class T >
int EGS_LOCAL get_input (const EGS_InputPrivate *p, const string &key, T &value)
 
vector< string > egsTokenize (const string &str)
 Tokenize a string into individual tokens. More...
 
vector< int > egsParseIntegerRanges (vector< string >::const_iterator begin, vector< string >::const_iterator end)
 Parse integers and integer ranges from string tokens. More...
 

Detailed Description

EGS_Input implementation.

Author
Iwan Kawrakow, NRC

Definition in file egs_input.cpp.

Function Documentation

◆ egsTokenize()

vector<string> egsTokenize ( const string &  inp)

Tokenize a string into individual tokens.

Splits the input string into tokens separated by whitespace or commas. Multiple consecutive whitespace characters are treated as a single separator. Commas are converted to spaces before tokenization.

Parameters
strThe input string to tokenize
Returns
A vector of strings containing the individual tokens
Note
Returns an empty vector if the input string is empty

Example:

auto tokens = egsTokenize("1,2 3-5, 6");
// Result: {"1", "2", "3-5", "6"}
vector< string > egsTokenize(const string &str)
Tokenize a string into individual tokens.
Definition: egs_input.cpp:1184

Definition at line 1184 of file egs_input.cpp.

Referenced by EGS_BaseGeometry::getLabelRegions(), and EGS_BaseGeometry::getNumberRegions().

◆ egsParseIntegerRanges()

vector<int> egsParseIntegerRanges ( vector< string >::const_iterator  begin,
vector< string >::const_iterator  end 
)

Parse integers and integer ranges from string tokens.

Parses a sequence of string tokens, where each token can be either:

  • A single integer (e.g., "42")
  • An integer range using hyphen notation (e.g., "10-15")

Ranges are expanded to include all integers between the bounds (inclusive). The order of range bounds doesn't matter (e.g., "15-10" works the same as "10-15").

Parameters
beginIterator to the first token to parse
endIterator one past the last token to parse
Returns
Sorted vector of unique integers with duplicates removed
Note
Invalid tokens (non-numeric strings) are silently ignored
The returned vector is automatically sorted and deduplicated

Examples:

vector<string> tokens = {"5", "10-12", "8", "10"};
auto result = egsParseIntegerRanges(tokens.begin(), tokens.end());
// Result: {5, 8, 10, 11, 12}
vector<string> tokens2 = {"20-15", "invalid", "18"};
auto result2 = egsParseIntegerRanges(tokens2.begin(), tokens2.end());
// Result: {15, 16, 17, 18, 19, 20}
vector< int > egsParseIntegerRanges(vector< string >::const_iterator begin, vector< string >::const_iterator end)
Parse integers and integer ranges from string tokens.
Definition: egs_input.cpp:1207

Definition at line 1207 of file egs_input.cpp.