Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
THaPrintOption.h
Go to the documentation of this file.
1#ifndef Podd_THaPrintOption_h_
2#define Podd_THaPrintOption_h_
3
5//
6// THaPrintOption
7//
9
10#include "Rtypes.h"
11#include <string>
12#include <vector>
13#include <ostream>
14
15Option_t* const kPRINTLINE = "LINE";
16Option_t* const kPRINTSTATS = "STATS";
17
19
20public:
21 THaPrintOption() = default;
22 THaPrintOption( std::string str ); // NOLINT(google-explicit-constructor,hicpp-explicit-conversions)
23 THaPrintOption( const char* str ); // NOLINT(google-explicit-constructor,hicpp-explicit-conversions)
24 THaPrintOption( const THaPrintOption& opt ) = default;
25 THaPrintOption( THaPrintOption&& opt ) = default;
26 THaPrintOption& operator=( const THaPrintOption& rhs ) = default;
28 THaPrintOption& operator=( std::string rhs );
29 THaPrintOption& operator=( const char* rhs );
30 virtual ~THaPrintOption() = default;
31
32 Bool_t Contains( const std::string& token ) const;
33 Int_t GetNOptions() const;
34 const char* GetOption( Int_t i=0 ) const;
35 const std::string& GetOptionStr( Int_t i=0 ) const;
36 Int_t GetValue( Int_t i=0 ) const;
37 Bool_t IsLine() const;
38 const char* Data() const { return fString.c_str(); }
39 virtual void Print() const;
40 void ToLower();
41 void ToUpper();
42 explicit operator const char*() const { return Data(); }
43 const char* operator[]( Int_t i ) const { return GetOption(i); }
44 const char* operator()( Int_t i ) const { return GetOption(i); }
45
46 friend std::ostream& operator<<( std::ostream& os, const THaPrintOption& opt );
47
48protected:
49 std::string fString; //Local copy of option string
50 std::vector<std::string> fTokens; //Parsed tokens
51 std::vector<Int_t> fParam; //Parsed token values
52 std::string fEmpty; //Empty string FIXME make static
53
54 virtual void Parse();
55
56 ClassDef(THaPrintOption,0) //Utility class to handle option strings
57};
58
59//__________ inline functions _________________________________________________
60inline
62{
63 return static_cast<Int_t>(fTokens.size());
64}
65
66//_____________________________________________________________________________
67inline
68const char* THaPrintOption::GetOption( Int_t i ) const
69{
70 // Get i-th token from string. Tokens are delimited by blanks or commas.
71
72 return ( i>=0 && i<GetNOptions() ) ? fTokens[i].c_str() : fEmpty.c_str();
73}
74
75//_____________________________________________________________________________
76inline
77const std::string& THaPrintOption::GetOptionStr( Int_t i ) const
78{
79 // Get i-th token from string as a std::string
80
81 return ( i>=0 && i<GetNOptions() ) ? fTokens[i] : fEmpty;
82}
83
84//_____________________________________________________________________________
85inline
87{
88 // Get integer value of the i-th token from string.
89 // Example:
90 //
91 // With "OPT,10,20,30" or "OPT 10 20 30", GetValue(2) returns 20.
92 //
93
94 return ( i>=0 && i<GetNOptions() ) ? fParam[i] : 0;
95}
96
97//_____________________________________________________________________________
98inline
100{
101 // True if "opt" is a request for printing on a single line
102
103 return (GetOptionStr() == kPRINTLINE || GetOptionStr() == kPRINTSTATS);
104}
105
106//_____________________________________________________________________________
107inline
108std::ostream& operator<<( std::ostream& os, const THaPrintOption& opt )
109{
110 return os << opt.fString;
111}
112
113#endif
int Int_t
bool Bool_t
const char Option_t
#define ClassDef(name, id)
std::ostream & operator<<(std::ostream &os, const THaPrintOption &opt)
Option_t *const kPRINTLINE
Option_t *const kPRINTSTATS
virtual ~THaPrintOption()=default
friend std::ostream & operator<<(std::ostream &os, const THaPrintOption &opt)
THaPrintOption(std::string str)
const char * Data() const
THaPrintOption & operator=(const THaPrintOption &rhs)=default
std::vector< Int_t > fParam
THaPrintOption(const THaPrintOption &opt)=default
const char * GetOption(Int_t i=0) const
Bool_t IsLine() const
std::string fEmpty
THaPrintOption & operator=(THaPrintOption &&rhs)=default
const char * operator[](Int_t i) const
Bool_t Contains(const std::string &token) const
THaPrintOption()=default
std::vector< std::string > fTokens
THaPrintOption(THaPrintOption &&opt)=default
virtual void Print() const
std::string fString
const std::string & GetOptionStr(Int_t i=0) const
const char * operator()(Int_t i) const
virtual void Parse()
THaPrintOption & operator=(std::string rhs)
Int_t GetNOptions() const
Int_t GetValue(Int_t i=0) const