ATLAS Offline Software
CxxUtils/CxxUtils/ClassName.h
Go to the documentation of this file.
1 // This file's extension implies that it's C, but it's really -*- C++ -*-.
2 
3 /*
4  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
5 */
14 #ifndef CXXUTILS_CLASSNAME_H
15 #define CXXUTILS_CLASSNAME_H
16 
17 
18 #include <string>
19 #include <vector>
20 #include <map>
21 #include <stdexcept>
22 
23 
24 namespace CxxUtils {
25 
26 
101 {
102 public:
103 
108  : public std::runtime_error
109  {
110  public:
111  ExcBadClassName (const std::string& name);
112  };
113 
114 
119  : public std::runtime_error
120  {
121  public:
122  ExcMissingVariable (const std::string& var);
123  };
124 
125 
129  class Rules
130  {
131  public:
135  size_t size() const;
136 
137 
148  void add (const ClassName& pattern, const ClassName& replacement);
149 
150 
161  void add (ClassName&& pattern, ClassName&& replacement);
162 
163 
175  bool applyTo (ClassName& cn) const;
176 
177 
186  std::string apply (const std::string& name) const;
187 
188 
189  private:
191  typedef std::pair<ClassName, ClassName> pat_repl_t;
192 
194  typedef std::multimap<std::string, pat_repl_t> rulemap_t;
196  };
197 
198 
200  typedef std::map<std::string, ClassName> match_t;
201 
202 
208  ClassName ();
209 
210 
217  ClassName (const char* name);
218 
219 
226  ClassName (const std::string& name);
227 
228 
236  ClassName (const std::string& name, std::string::size_type& pos);
237 
238 
243  void swap (ClassName& other);
244 
245 
249  bool isConst() const;
250 
251 
255  void setConst();
256 
257 
263  const std::string& name() const;
264 
265 
271  std::string qualifiedName() const;
272 
273 
277  std::string fullName() const;
278 
279 
283  size_t ntargs() const;
284 
285 
290  const ClassName& targ (size_t i) const;
291 
292 
296  bool operator== (const ClassName& other) const;
297 
298 
302  bool operator!= (const ClassName& other) const;
303 
304 
315  bool match (const ClassName& pattern, match_t& matches) const;
316 
317 
329  void subst (const match_t& matches);
330 
331 
343  ClassName substCopy (const match_t& matches) const;
344 
345 
358  void applyRules (const Rules& rules);
359 
360 
374  static std::string applyRules (const std::string& name,
375  const Rules& rules);
376 
377 
378 private:
387  void parse (const std::string& name, std::string::size_type& pos);
388 
389 
401  std::string parsePrimary (const std::string& name,
402  std::string::size_type& pos);
403 
404 
418  void parseNamespace (const std::string& name, std::string::size_type& pos);
419 
420 
433  void parseTemplateArgs (const std::string& name, std::string::size_type& pos);
434 
435 
444  void skipSpaces (const std::string& name, std::string::size_type& pos);
445 
446 
458  bool match1 (const ClassName& pattern,
459  bool topLevel,
460  match_t& matches) const;
461 
462 
473  bool applyRules1 (const Rules& rules);
474 
475 
477  bool m_const;
478 
483  std::vector<ClassName> m_namespace;
484 
486  std::string m_name;
487 
489  std::vector<ClassName> m_targs;
490 };
491 
492 
493 } // namespace CxxUtils
494 
495 
496 #endif // not CXXUTILS_CLASSNAME_H
mergePhysValFiles.pattern
pattern
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:26
beamspotnt.var
var
Definition: bin/beamspotnt.py:1394
CxxUtils::ClassName::Rules::add
void add(const ClassName &pattern, const ClassName &replacement)
Add a new transformation rule.
Definition: ClassName.cxx:60
CxxUtils::ClassName::Rules::size
size_t size() const
Return the number of defined rules.
Definition: ClassName.cxx:44
CxxUtils::ClassName::isConst
bool isConst() const
Get the const flag for this expression.
Definition: ClassName.cxx:209
CxxUtils::ClassName::name
const std::string & name() const
Return the root name of the expression.
Definition: ClassName.cxx:229
CxxUtils::ClassName::subst
void subst(const match_t &matches)
Substitute variables into this expression.
Definition: ClassName.cxx:357
CxxUtils::ClassName::swap
void swap(ClassName &other)
Swap this expression with another one.
Definition: ClassName.cxx:197
CxxUtils::ClassName::ExcBadClassName::ExcBadClassName
ExcBadClassName(const std::string &name)
Exception to signal a malformed class name.
Definition: ClassName.cxx:23
CxxUtils::ClassName::setConst
void setConst()
Set the const flag for this expression.
Definition: ClassName.cxx:218
CxxUtils::ClassName::ExcMissingVariable
Exception to signal a missing variable.
Definition: CxxUtils/CxxUtils/ClassName.h:120
CxxUtils::ClassName::ExcMissingVariable::ExcMissingVariable
ExcMissingVariable(const std::string &var)
Exception to signal a missing variable.
Definition: ClassName.cxx:33
CxxUtils::ClassName::parse
void parse(const std::string &name, std::string::size_type &pos)
Parse a string into a ClassName.
Definition: ClassName.cxx:447
CxxUtils::ClassName::m_const
bool m_const
Is this expression const?
Definition: CxxUtils/CxxUtils/ClassName.h:477
CxxUtils::ClassName::parseNamespace
void parseNamespace(const std::string &name, std::string::size_type &pos)
Parse a namespace qualification.
Definition: ClassName.cxx:522
CxxUtils::ClassName::Rules::applyTo
bool applyTo(ClassName &cn) const
Apply the set of transformation rules to a class name object.
Definition: ClassName.cxx:99
CxxUtils::ClassName::skipSpaces
void skipSpaces(const std::string &name, std::string::size_type &pos)
Skip past spaces in a string.
Definition: ClassName.cxx:584
CxxUtils::ClassName::ntargs
size_t ntargs() const
Return number of template arguments.
Definition: ClassName.cxx:275
CxxUtils::ClassName
Recursively separate out template arguments in a C++ class name.
Definition: CxxUtils/CxxUtils/ClassName.h:101
lumiFormat.i
int i
Definition: lumiFormat.py:85
CxxUtils::ClassName::operator!=
bool operator!=(const ClassName &other) const
Test two expressions for inequality.
Definition: ClassName.cxx:323
CxxUtils::ClassName::m_namespace
std::vector< ClassName > m_namespace
The containing namespace.
Definition: CxxUtils/CxxUtils/ClassName.h:483
CxxUtils::ClassName::m_targs
std::vector< ClassName > m_targs
The template arguments for this name.
Definition: CxxUtils/CxxUtils/ClassName.h:489
CxxUtils::ClassName::operator==
bool operator==(const ClassName &other) const
Test two expressions for equality.
Definition: ClassName.cxx:294
CxxUtils::ClassName::parseTemplateArgs
void parseTemplateArgs(const std::string &name, std::string::size_type &pos)
Parse the template part of a name.
Definition: ClassName.cxx:554
CxxUtils
Definition: aligned_vector.h:29
CxxUtils::ClassName::fullName
std::string fullName() const
Return the full name of the expression.
Definition: ClassName.cxx:252
CxxUtils::ClassName::Rules::apply
std::string apply(const std::string &name) const
Apply transformations to a class name.
Definition: ClassName.cxx:127
CxxUtils::ClassName::Rules::m_rules
rulemap_t m_rules
Definition: CxxUtils/CxxUtils/ClassName.h:195
CxxUtils::ClassName::Rules
A set of transformation rules to use with ClassName.
Definition: CxxUtils/CxxUtils/ClassName.h:130
CxxUtils::ClassName::targ
const ClassName & targ(size_t i) const
Return one template argument.
Definition: ClassName.cxx:285
CxxUtils::ClassName::match1
bool match1(const ClassName &pattern, bool topLevel, match_t &matches) const
Match this expression against a pattern.
Definition: ClassName.cxx:603
CxxUtils::ClassName::Rules::rulemap_t
std::multimap< std::string, pat_repl_t > rulemap_t
Map from the root of a pattern to the pattern, replacement pair.
Definition: CxxUtils/CxxUtils/ClassName.h:194
CxxUtils::ClassName::applyRules1
bool applyRules1(const Rules &rules)
Apply a set of transformation rules to this object.
Definition: ClassName.cxx:674
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
CxxUtils::ClassName::Rules::pat_repl_t
std::pair< ClassName, ClassName > pat_repl_t
A pattern and replacement.
Definition: CxxUtils/CxxUtils/ClassName.h:191
CxxUtils::ClassName::applyRules
void applyRules(const Rules &rules)
Apply a set of transformation rules to this object.
Definition: ClassName.cxx:410
CxxUtils::ClassName::ExcBadClassName
Exception to signal a malformed class name.
Definition: CxxUtils/CxxUtils/ClassName.h:109
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
CxxUtils::ClassName::match_t
std::map< std::string, ClassName > match_t
Map used to hold variable assignments from matching.
Definition: CxxUtils/CxxUtils/ClassName.h:200
CxxUtils::ClassName::ClassName
ClassName()
Default constructor.
Definition: ClassName.cxx:138
CxxUtils::ClassName::parsePrimary
std::string parsePrimary(const std::string &name, std::string::size_type &pos)
Parse a primary part of the class name.
Definition: ClassName.cxx:488
CxxUtils::ClassName::substCopy
ClassName substCopy(const match_t &matches) const
Return a copy of this expression with variables substituted.
Definition: ClassName.cxx:390
CxxUtils::ClassName::m_name
std::string m_name
The primary name part of this expression.
Definition: CxxUtils/CxxUtils/ClassName.h:486
CxxUtils::ClassName::qualifiedName
std::string qualifiedName() const
Return the namespace-qualified name of the expression.
Definition: ClassName.cxx:240
CxxUtils::ClassName::match
bool match(const ClassName &pattern, match_t &matches) const
Match this expression against a pattern.
Definition: ClassName.cxx:339