ATLAS Offline Software
Loading...
Searching...
No Matches
ChainString.h
Go to the documentation of this file.
1/* emacs: this is -*- c++ -*- */
12
13
14#ifndef TrigInDetAnalysisExample_ChainString_H
15#define TrigInDetAnalysisExample_ChainString_H
16
17
18#include <string>
19#include <vector>
20#include <iostream>
21
22
23class ChainString : public std::string {
24
25public:
26
27 ChainString( const std::string& s );
28
29 ChainString( const ChainString& s );
30
31 ChainString& operator=(const ChainString&) = default;
32
33 const std::string& head() const { return m_head; }
34 const std::string& tail() const { return m_tail; }
35 const std::string& roi() const { return m_roi; }
36 const std::string& vtx() const { return m_vtx; }
37 const std::string& element() const { return m_element; }
38 const std::string& extra() const { return m_extra; }
39
40 bool passed() const { return m_passed; }
41
42 const std::string& raw() const { return m_raw; }
43
47 std::string value( const std::string& key ) const {
48 int i=findkey(key);
49 if ( i>=0 ) return m_values[i];
50 return "";
51 }
52
57 std::string value(size_t i) const {
58 if ( i<m_values.size() ) return m_values[i];
59 return "";
60 }
61
62 size_t vsize() const { return m_values.size(); }
63
65 std::string postvalue( const std::string& key ) const {
66 if ( postcount() ) return value( key+"-post" );
67 return "";
68 }
69
70 const std::vector<std::string>& values() const { return m_values; }
71 const std::vector<std::string>& keys() const { return m_keys; }
72
73 std::string pre() const { return m_raw.substr( 0, m_raw.find(":post") ); }
74 const std::string& post() const { return m_post; }
75
76 size_t postcount() const { return m_postcount; }
77
78 std::string subs( std::string s ) const;
79
80public:
81
82 // chop tokens off the front of a string
83 static std::string chop(std::string& s1, const std::string& s2) {
84 std::string::size_type pos = s1.find_first_of(s2);
85 std::string s3;
86 if ( pos == std::string::npos ) {
87 s3 = s1;
88 s1.erase(0, s1.size());
89 }
90 else {
91 s3 = s1.substr(0, pos);
92 s1.erase(0, pos+1);
93 }
94 return s3;
95 }
96
97protected:
98
99 // chomp tokens off the end of a string
100 static std::string chomp(std::string& s1, const std::string& s2) {
101 // std::string::size_type pos = s1.find(s2);
102 std::string::size_type pos = s1.find_first_of(s2);
103 std::string s3;
104 if ( pos == std::string::npos ) return "";
105
106 s3 = s1.substr(pos+1, s1.size());
107 s1.erase(pos, s1.size());
108
109 return s3;
110 }
111
113 static char toupper( char c ) { return ( c>='a' && c<='z' ? c+'A'-'a' : c ); }
114
116 static std::string toupper( const std::string& s ) {
117 const char* c = s.c_str();
118 char tmp[512];
119 char* tp = tmp;
120 while (( *tp++ = toupper(*c++) ));
121 return tmp;
122 }
123
125 static char tolower( char c ) { return ( c>='A' && c<='Z' ? c-'A'+'a' : c ); }
126
128 static std::string tolower( const std::string& s ) {
129 const char* c = s.c_str();
130 char tmp[512];
131 char* tp = tmp;
132 while (( *tp++ = tolower(*c++) ));
133 return tmp;
134 }
135
136protected:
137
139
140 void parse( std::string s );
141
142 int findkey( const std::string& key ) const {
143 for ( int i=m_keys.size() ; i-- ; ) if ( key==m_keys[i] ) return i;
144 return -1;
145 }
146
147private:
148
149 std::string m_head;
150 std::string m_tail;
151 std::string m_roi;
152 std::string m_vtx;
153 std::string m_element;
154 std::string m_extra;
155
157
158 std::string m_raw;
159
160 std::string m_post;
162
163 std::vector<std::string> m_keys;
164 std::vector<std::string> m_values;
165
166};
167
168
169
170inline bool operator==( const ChainString& cs, const ChainString& s ) {
171 return cs.raw() == ChainString(s).raw();
172}
173
174inline bool operator==( const ChainString& cs, const std::string& s ) {
175 return cs.raw() == ChainString(s).raw();
176}
177
178inline bool operator==( const std::string& s, const ChainString& cs ) {
179 return cs.raw() == ChainString(s).raw();
180}
181
182
183
184#endif // TrigInDetAnalysisExample_ChainString_H
bool operator==(const ChainString &cs, const ChainString &s)
const std::string & extra() const
Definition ChainString.h:38
static std::string toupper(const std::string &s)
convert to upper case
const std::vector< std::string > & keys() const
Definition ChainString.h:71
const std::string & roi() const
Definition ChainString.h:35
size_t m_postcount
std::string m_post
std::string subs(std::string s) const
ChainString(const std::string &s)
const std::string & post() const
Definition ChainString.h:74
const std::vector< std::string > & values() const
Definition ChainString.h:70
void parse(std::string s)
parse the full specification string
std::string m_roi
const std::string & raw() const
Definition ChainString.h:42
std::vector< std::string > m_keys
size_t postcount() const
Definition ChainString.h:76
size_t vsize() const
Definition ChainString.h:62
std::string m_head
const std::string & head() const
Definition ChainString.h:33
std::string value(const std::string &key) const
can't make this return a reference in case there is no such key - could throw an exception then it wo...
Definition ChainString.h:47
static char tolower(char c)
convert to lower case
ChainString & operator=(const ChainString &)=default
const std::string & tail() const
Definition ChainString.h:34
std::string postvalue(const std::string &key) const
same here regarding returning a reference
Definition ChainString.h:65
int findkey(const std::string &key) const
bool passed() const
Definition ChainString.h:40
std::string value(size_t i) const
as above - should really return a const std::string& but we don't want to have to throw an exception ...
Definition ChainString.h:57
std::string pre() const
Definition ChainString.h:73
static std::string chop(std::string &s1, const std::string &s2)
Definition ChainString.h:83
static std::string tolower(const std::string &s)
convert to lower case
static std::string chomp(std::string &s1, const std::string &s2)
std::vector< std::string > m_values
std::string m_vtx
std::string m_tail
static char toupper(char c)
convert to upper case
const std::string & vtx() const
Definition ChainString.h:36
std::string m_extra
std::string m_raw
const std::string & element() const
Definition ChainString.h:37
std::string m_element