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

EGS_Input class header file. More...

#include "egs_libconfig.h"
#include <string>
#include <vector>
#include <iostream>

Go to the source code of this file.

Classes

class  EGS_Input
 A class for storing information in a tree-like structure of key-value pairs. This class is used throughout the egspp class library for passing information to the various objects. More...
 

Functions

vector< string > egsTokenize (const string &inp)
 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 class header file.

Author
Iwan Kawrakow, NRC

Definition in file egs_input.h.

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.