ATLAS Offline Software
ChainString.h
Go to the documentation of this file.
1 /* emacs: this is -*- c++ -*- */
14 #ifndef TrigInDetAnalysisExample_ChainString_H
15 #define TrigInDetAnalysisExample_ChainString_H
16 
17 
18 #include <string>
19 #include <vector>
20 #include <iostream>
21 
22 
23 class ChainString : public std::string {
24 
25 public:
26 
27  ChainString( const std::string& s );
28 
29  ChainString( const ChainString& s );
30 
31  ChainString& operator=(const ChainString&) = default;
32 
33  std::string head() const { return m_head; }
34  std::string tail() const { return m_tail; }
35  std::string roi() const { return m_roi; }
36  std::string vtx() const { return m_vtx; }
37  std::string element() const { return m_element; }
38  std::string extra() const { return m_extra; }
39 
40  bool passed() const { return m_passed; }
41 
42  // const std::string& head() const { return m_head; }
43 
44  // const std::string& tail() const { return m_tail; }
45  // const std::string& roi() const { return m_roi; }
46  // const std::string& vtx() const { return m_vtx; }
47 
48  // const std::string& element() const { return m_element; }
49  // const std::string& extra() const { return m_extra; }
50 
51  // const bool& passed() const { return m_passed; }
52 
53  std::string raw() const { return m_raw; }
54 
58  std::string value( const std::string& key ) const {
59  int i=findkey(key);
60  if ( i>=0 ) return m_values[i];
61  return "";
62  }
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 
80 public:
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 
97 protected:
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 
136 protected:
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 
147 private:
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 
156  bool m_passed;
157 
158  std::string m_raw;
159 
160  std::string m_post;
161  size_t m_postcount;
162 
163  std::vector<std::string> m_keys;
164  std::vector<std::string> m_values;
165 
166 };
167 
168 
169 
170 inline bool operator==( const ChainString& cs, const ChainString& s ) {
171  return cs.raw() == ChainString(s).raw();
172 }
173 
174 inline bool operator==( const ChainString& cs, const std::string& s ) {
175  return cs.raw() == ChainString(s).raw();
176 }
177 
178 inline 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
ChainString::m_passed
bool m_passed
Definition: ChainString.h:156
ChainString::postcount
size_t postcount() const
Definition: ChainString.h:76
ChainString::value
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:58
ReadCellNoiseFromCoolCompare.s1
s1
Definition: ReadCellNoiseFromCoolCompare.py:378
ChainString::tail
std::string tail() const
Definition: ChainString.h:34
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
ChainString::post
const std::string & post() const
Definition: ChainString.h:74
ChainString::m_roi
std::string m_roi
Definition: ChainString.h:151
ChainString::parse
void parse(std::string s)
parse the full specification string
Definition: ChainString.cxx:38
ChainString::postvalue
std::string postvalue(const std::string &key) const
same here regarding returning a reference
Definition: ChainString.h:65
ChainString::head
std::string head() const
Definition: ChainString.h:33
ParticleTest.tp
tp
Definition: ParticleTest.py:25
ChainString::m_vtx
std::string m_vtx
Definition: ChainString.h:152
ChainString
Definition: ChainString.h:23
ChainString::subs
std::string subs(std::string s) const
Definition: ChainString.cxx:127
ChainString::roi
std::string roi() const
Definition: ChainString.h:35
ChainString::m_element
std::string m_element
Definition: ChainString.h:153
ChainString::tolower
static std::string tolower(const std::string &s)
convert to lower case
Definition: ChainString.h:128
ChainString::pre
std::string pre() const
Definition: ChainString.h:73
ChainString::ChainString
ChainString(const std::string &s)
Definition: ChainString.cxx:16
ChainString::extra
std::string extra() const
Definition: ChainString.h:38
ChainString::m_extra
std::string m_extra
Definition: ChainString.h:154
lumiFormat.i
int i
Definition: lumiFormat.py:85
ChainString::m_tail
std::string m_tail
Definition: ChainString.h:150
ChainString::chop
static std::string chop(std::string &s1, const std::string &s2)
Definition: ChainString.h:83
ChainString::m_values
std::vector< std::string > m_values
Definition: ChainString.h:164
operator==
bool operator==(const ChainString &cs, const ChainString &s)
Definition: ChainString.h:170
ChainString::m_raw
std::string m_raw
Definition: ChainString.h:158
ChainString::passed
bool passed() const
Definition: ChainString.h:40
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
ChainString::m_post
std::string m_post
Definition: ChainString.h:160
ChainString::m_head
std::string m_head
Definition: ChainString.h:149
ChainString::values
const std::vector< std::string > & values() const
Definition: ChainString.h:70
ChainString::raw
std::string raw() const
Definition: ChainString.h:53
ChainString::chomp
static std::string chomp(std::string &s1, const std::string &s2)
Definition: ChainString.h:100
ChainString::element
std::string element() const
Definition: ChainString.h:37
ReadCellNoiseFromCoolCompare.s3
s3
Definition: ReadCellNoiseFromCoolCompare.py:380
ChainString::m_keys
std::vector< std::string > m_keys
Definition: ChainString.h:163
ChainString::findkey
int findkey(const std::string &key) const
Definition: ChainString.h:142
ChainString::keys
const std::vector< std::string > & keys() const
Definition: ChainString.h:71
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
ChainString::operator=
ChainString & operator=(const ChainString &)=default
ChainString::vtx
std::string vtx() const
Definition: ChainString.h:36
ChainString::tolower
static char tolower(char c)
convert to lower case
Definition: ChainString.h:125
ChainString::toupper
static std::string toupper(const std::string &s)
convert to upper case
Definition: ChainString.h:116
ReadCellNoiseFromCoolCompare.s2
s2
Definition: ReadCellNoiseFromCoolCompare.py:379
ChainString::toupper
static char toupper(char c)
convert to upper case
Definition: ChainString.h:113
python.compressB64.c
def c
Definition: compressB64.py:93
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
ChainString::m_postcount
size_t m_postcount
Definition: ChainString.h:161