Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
THaPrintOption.cxx
Go to the documentation of this file.
1//*-- Author : Ole Hansen 30/06/2000
2
3
5//
6// THaPrintOption
7//
8// Utility class to deal with print option strings. Supports blank- and
9// comma-separated lists of options and/or numerical arguments that are
10// contained in a single option string.
11//
13
14#include "THaPrintOption.h"
15#include "Helper.h"
16#include <iostream>
17#include <algorithm>
18#include <cctype> // ::tolower, ::toupper
19#include <cstdlib> // strtol
20#include <limits>
21
23
24using namespace std;
25
26//_____________________________________________________________________________
27THaPrintOption::THaPrintOption( string str ) : fString{std::move(str)}
28{
29 // Normal constructor
30
31 Parse();
32}
33
34//_____________________________________________________________________________
36 : THaPrintOption(string(str ? str : ""))
37{}
38
39//_____________________________________________________________________________
41{
42 fString = std::move(rhs);
43 Parse();
44 return *this;
45}
46
47//_____________________________________________________________________________
49{
50 // Initialize object with a string
51
52 if( rhs )
53 fString = rhs;
54 else
55 fString.clear();
56 Parse();
57 return *this;
58}
59
60//_____________________________________________________________________________
61Bool_t THaPrintOption::Contains( const string& token ) const
62{
63 // Test if option contains the given token 'tok'
64
65 return any_of(ALL(fTokens), [&token]( const string& tok ) {
66 return tok == token;
67 });
68}
69
70//_____________________________________________________________________________
72{
73 // Parse the string and put the results in the internal arrays.
74 // This function should never generate an error.
75
76 const char* const delim = ", "; // token delimiters
77
78 fTokens.clear();
79 fParam.clear();
80
81 string::size_type start = 0;
82 string::size_type stop = 0;
83 while( start != string::npos && stop != string::npos ) {
84 stop = fString.find_first_of(delim, start);
85 string tok = fString.substr(start, stop - start);
86 if( !tok.empty() ) {
87 Int_t val = 0;
88 const char* str = tok.c_str();
89 char* str_end = nullptr;
90 auto conv = strtol(str, &str_end, 10);
91 if( str + tok.length() == str_end
92 && conv <= numeric_limits<Int_t>::max()
93 && conv >= numeric_limits<Int_t>::min() )
94 val = static_cast<Int_t>(conv);
95 fTokens.push_back(std::move(tok));
96 fParam.push_back(val);
97 }
98 start = fString.find_first_not_of(delim, stop);
99 }
100}
101
102//_____________________________________________________________________________
104{
105 for( Int_t i = 0; i < GetNOptions(); i++ )
106 cout << "\"" << GetOptionStr(i) << "\" => " << GetValue(i) << endl;
107}
108
109//_____________________________________________________________________________
111{
112 transform(ALL(fString), fString.begin(), ::tolower);
113 for( auto& tok: fTokens )
114 transform(ALL(tok), tok.begin(), ::tolower);
115}
116
117//_____________________________________________________________________________
119{
120 transform(ALL(fString), fString.begin(), ::toupper);
121 for( auto& tok: fTokens )
122 transform(ALL(tok), tok.begin(), ::toupper);
123}
124
125//_____________________________________________________________________________
int Int_t
bool Bool_t
THaPrintOption & operator=(const THaPrintOption &rhs)=default
std::vector< Int_t > fParam
Bool_t Contains(const std::string &token) const
THaPrintOption()=default
std::vector< std::string > fTokens
virtual void Print() const
std::string fString
const std::string & GetOptionStr(Int_t i=0) const
virtual void Parse()
Int_t GetNOptions() const
Int_t GetValue(Int_t i=0) const
RModel Parse(std::string filename)
start
STL namespace.
ClassImp(TPyArg)