musrfit 1.10.0
PStringNumberList Class Reference

#include <PMusr.h>

Public Member Functions

 PStringNumberList (char *str)
 
 PStringNumberList (std::string str)
 
virtual ~PStringNumberList ()
 
virtual bool Parse (std::string &errorMsg, bool ignoreFirstToken=false)
 
virtual PUIntVector GetList ()
 

Private Member Functions

virtual bool IsNumber (std::string &str)
 
virtual void StripSpaces ()
 

Private Attributes

std::string fString
 
bool fIsValid
 
PUIntVector fList
 

Detailed Description

Parser for flexible number list specifications.

This utility class parses string representations of number lists that combine three different notations:

  • (i) Space-separated integers: "1 3 7 14"
  • (ii) Range notation: "13-27" generates 13, 14, 15, ..., 26, 27
  • (iii) Sequence notation: "10:20:2" generates 10, 12, 14, 16, 18, 20

These forms can be combined in a single string, e.g., "1 5-8 10:20:2" produces [1, 5, 6, 7, 8, 10, 12, 14, 16, 18, 20].

Use cases: Specifying run numbers, histogram lists, or parameter indices on command line or in configuration files.

Definition at line 1399 of file PMusr.h.

Constructor & Destructor Documentation

◆ PStringNumberList() [1/2]

PStringNumberList::PStringNumberList ( char * str)
inline

Constructor from C string

Parameters
strString to parse

Definition at line 1403 of file PMusr.h.

References fString.

◆ PStringNumberList() [2/2]

PStringNumberList::PStringNumberList ( std::string str)
inline

Constructor from std::string

Parameters
strString to parse

Definition at line 1407 of file PMusr.h.

References fString.

◆ ~PStringNumberList()

virtual PStringNumberList::~PStringNumberList ( )
inlinevirtual

Definition at line 1409 of file PMusr.h.

References fList.

Member Function Documentation

◆ GetList()

virtual PUIntVector PStringNumberList::GetList ( )
inlinevirtual

Returns the parsed list of numbers

Returns
Vector of unsigned integers extracted from input string

Definition at line 1422 of file PMusr.h.

References fList.

Referenced by addRun_filter_runList(), and main().

◆ IsNumber()

virtual bool PStringNumberList::IsNumber ( std::string & str)
inlineprivatevirtual

Definition at line 1429 of file PMusr.h.

Referenced by Parse().

◆ Parse()

bool PStringNumberList::Parse ( std::string & errorMsg,
bool ignoreFirstToken = false )
virtual

Parses the input string and generates the number list.

Parameters
errorMsgReference to string that will contain error message if parsing fails
ignoreFirstTokenIf true, skips the first space-separated token (useful when first token is a label)
Returns
true if parsing succeeded, false on error

Helper class which parses list of numbers of the following 3 forms and its combination. (i) list of integers separted by spaces, e.g. 1 3 7 14 (ii) a range of integers of the form nS-nE, e.g. 13-27 which will generate 13, 14, 15, .., 26, 27 (iii) a sequence of integers of the form nS:nE:nStep, e.g. 10:20:2 which will generate 10, 12, 14, .., 18, 20

Parameters
errorMsgerror message
ignoreFirstTokenif true, the first parse token will be ignored
Returns
true if parse has been successful, otherwise false

Definition at line 2007 of file PMusr.cpp.

References fList, fString, IsNumber(), and StripSpaces().

Referenced by addRun_filter_runList(), and main().

◆ StripSpaces()

void PStringNumberList::StripSpaces ( )
privatevirtual

This routine removes arbitray number of spaces between '-' and ':', e.g. 123 - 125 will be converted to 123-125, etc.

Definition at line 2119 of file PMusr.cpp.

References fString.

Referenced by Parse().

Member Data Documentation

◆ fIsValid

bool PStringNumberList::fIsValid
private

Definition at line 1426 of file PMusr.h.

◆ fList

PUIntVector PStringNumberList::fList
private

Definition at line 1427 of file PMusr.h.

Referenced by GetList(), Parse(), and ~PStringNumberList().

◆ fString

std::string PStringNumberList::fString
private

Definition at line 1425 of file PMusr.h.

Referenced by Parse(), PStringNumberList(), PStringNumberList(), and StripSpaces().


The documentation for this class was generated from the following files: