ATLAS Offline Software
|
Recursively separate out template arguments in a C++ class name. More...
#include <ClassName.h>
Classes | |
class | ExcBadClassName |
Exception to signal a malformed class name. More... | |
class | ExcMissingVariable |
Exception to signal a missing variable. More... | |
class | Rules |
A set of transformation rules to use with ClassName . More... | |
Public Types | |
typedef std::map< std::string, ClassName > | match_t |
Map used to hold variable assignments from matching. More... | |
Public Member Functions | |
ClassName () | |
Default constructor. More... | |
ClassName (const char *name) | |
Parse a class name into component parts. More... | |
ClassName (const std::string &name) | |
Parse a class name into component parts. More... | |
ClassName (const std::string &name, std::string::size_type &pos) | |
Parse a class name into component parts. More... | |
void | swap (ClassName &other) |
Swap this expression with another one. More... | |
bool | isConst () const |
Get the const flag for this expression. More... | |
void | setConst () |
Set the const flag for this expression. More... | |
const std::string & | name () const |
Return the root name of the expression. More... | |
std::string | qualifiedName () const |
Return the namespace-qualified name of the expression. More... | |
std::string | fullName () const |
Return the full name of the expression. More... | |
size_t | ntargs () const |
Return number of template arguments. More... | |
const ClassName & | targ (size_t i) const |
Return one template argument. More... | |
bool | operator== (const ClassName &other) const |
Test two expressions for equality. More... | |
bool | operator!= (const ClassName &other) const |
Test two expressions for inequality. More... | |
bool | match (const ClassName &pattern, match_t &matches) const |
Match this expression against a pattern. More... | |
void | subst (const match_t &matches) |
Substitute variables into this expression. More... | |
ClassName | substCopy (const match_t &matches) const |
Return a copy of this expression with variables substituted. More... | |
void | applyRules (const Rules &rules) |
Apply a set of transformation rules to this object. More... | |
Static Public Member Functions | |
static std::string | applyRules (const std::string &name, const Rules &rules) |
Apply a set of transformation rules a class name. More... | |
Private Member Functions | |
void | parse (const std::string &name, std::string::size_type &pos) |
Parse a string into a ClassName . More... | |
std::string | parsePrimary (const std::string &name, std::string::size_type &pos) |
Parse a primary part of the class name. More... | |
void | parseNamespace (const std::string &name, std::string::size_type &pos) |
Parse a namespace qualification. More... | |
void | parseTemplateArgs (const std::string &name, std::string::size_type &pos) |
Parse the template part of a name. More... | |
void | skipSpaces (const std::string &name, std::string::size_type &pos) |
Skip past spaces in a string. More... | |
bool | match1 (const ClassName &pattern, bool topLevel, match_t &matches) const |
Match this expression against a pattern. More... | |
bool | applyRules1 (const Rules &rules) |
Apply a set of transformation rules to this object. More... | |
Private Attributes | |
bool | m_const |
Is this expression const? More... | |
std::vector< ClassName > | m_namespace |
The containing namespace. More... | |
std::string | m_name |
The primary name part of this expression. More... | |
std::vector< ClassName > | m_targs |
The template arguments for this name. More... | |
Recursively separate out template arguments in a C++ class name.
This class allows making some simple transformations of C++ class names. For example, given these rules:
then rules.apply
can make transformations like this:
In slightly more detail: this class analyzes C++ class names. A name like
is broken down like this:
B
.A
.int
and double
.This is done recursively; both the namespace and template argument pieces can be further broken down like this. A name can also be marked as ‘const’, but no other parsing of C-like declarators is done.
Parsed names can be matched against simple patterns like this:
and the variable T
gets set to the corresponding piece of the type being matched. For example, given the above pattern,
If the pattern were A::B<const $T>
, then A::B<const int>
would match with T
set to int
, but A::B<int>
would not match.
However, the root name of a pattern may not be a variable; for example, you can't use A::$T<int>
as a pattern.
You can also substitute variables back into a pattern; for example,
T=int
into A::B<$T>
gives A::B<int>
.T=const int
into A::B<$T>
gives A::B<const int>
.T=const int
into A::B<const int>
gives A::B<const int>
. Definition at line 100 of file CxxUtils/CxxUtils/ClassName.h.
typedef std::map<std::string, ClassName> CxxUtils::ClassName::match_t |
Map used to hold variable assignments from matching.
Definition at line 200 of file CxxUtils/CxxUtils/ClassName.h.
Parse a class name into component parts.
name | The name to parse. |
Raises a BadClassName
exception if the name isn't completely parsed.
name | The name to parse. |
Raises a ExcBadClassName
exception if the name isn't completely parsed.
Definition at line 150 of file ClassName.cxx.
Parse a class name into component parts.
name | The name to parse. |
Raises a BadClassName
exception if the name isn't completely parsed.
name | The name to parse. |
Raises a ExcBadClassName
exception if the name isn't completely parsed.
Definition at line 168 of file ClassName.cxx.
Parse a class name into component parts.
name | String containing the name to parse. |
pos | Position in the string at which parsing should start. |
pos
is updated to point to past the point where parsing stopped.
Definition at line 186 of file ClassName.cxx.
Apply a set of transformation rules to this object.
rules | The set of rules to apply. |
Recursively walk this expression, trying to apply the transformation rules in rules
. If any matches are found, this expression is modified in-place and the walk is repeated. This function terminates when no further matches are found.
Warning: An infinite loop is possible if the replacement for a pattern can always be matched by another pattern.
Definition at line 410 of file ClassName.cxx.
Apply a set of transformation rules a class name.
param The name of the class to transform.
rules | The set of rules to apply. |
This is just shorthand for
Definition at line 430 of file ClassName.cxx.
Apply a set of transformation rules to this object.
rules | The set of rules to apply. |
Recursively walk this expression, trying to apply the transformation rules in rules
. If any matches are found, this expression is modified in-place.
Returns true if any matches were found.
Definition at line 674 of file ClassName.cxx.
std::string ClassName< T >::fullName | ( | ) | const |
bool ClassName< T >::isConst | ( | ) | const |
Get the const flag for this expression.
Definition at line 209 of file ClassName.cxx.
Match this expression against a pattern.
pattern | The pattern to match. | |
[out] | matches | Dictionary of pattern substitutions. |
Return true if pattern
matches the current expression. pattern
may contain dummy variables of the form $T
. On a successful return, the map matches
contains the variable assignments needed for the match.
Definition at line 339 of file ClassName.cxx.
|
private |
Match this expression against a pattern.
pattern | The pattern to match. | |
topLevel | True if this is the outermost level of matching. | |
[out] | matches | Dictionary of pattern substitutions. |
Return true if pattern
matches the current expression. pattern
may contain dummy variables of the form $T
. On a successful return, the map matches
contains the variable assignments needed for the match.
Definition at line 603 of file ClassName.cxx.
Return the root name of the expression.
In A::B<C>
, the root name is B
.
Definition at line 229 of file ClassName.cxx.
size_t ClassName< T >::ntargs | ( | ) | const |
Return number of template arguments.
Definition at line 275 of file ClassName.cxx.
Test two expressions for inequality.
Definition at line 323 of file ClassName.cxx.
Parse a string into a ClassName
.
name | The string containing the name. |
pos | Position in the string to start parsing. |
On return, pos
will be updated to point just past the last character consumed.
Definition at line 447 of file ClassName.cxx.
|
private |
Parse a namespace qualification.
name | The string containing the name. |
pos | Position in the string to start parsing. |
When this is called, the namespace part has already been parsed, and the next two characters in name
are ::
. This reads in the remainder of the string as a ClassName
, and then moves it inside the namespace given by the current object.
On return, pos
will be updated to point just past the last character consumed.
Definition at line 522 of file ClassName.cxx.
|
private |
Parse a primary part of the class name.
name | The string containing the name. |
pos | Position in the string to start parsing. |
The primary part of the class name is a string without namespace and template delimiters.
On return, pos
will be updated to point just past the last character consumed.
Definition at line 488 of file ClassName.cxx.
|
private |
Parse the template part of a name.
name | The string containing the name. |
pos | Position in the string to start parsing. |
When this is called, the qualified name part of the name has already been parsed, and the next character in name
is ::
. This reads in template arguments from name
.
On return, pos
will be updated to point just past the last character consumed.
Definition at line 554 of file ClassName.cxx.
std::string ClassName< T >::qualifiedName | ( | ) | const |
Return the namespace-qualified name of the expression.
Return the root name of the expression.
In A::B<C>
, this is A::B
.
In A::B<C>
, the root name is B
.
Definition at line 240 of file ClassName.cxx.
void ClassName< T >::setConst | ( | ) |
Set the const flag for this expression.
Definition at line 218 of file ClassName.cxx.
Skip past spaces in a string.
name | The string containing the name. |
pos | Position in the string to start skipping. |
On return, pos
will be updated to point just past the last character consumed.
Definition at line 584 of file ClassName.cxx.
Substitute variables into this expression.
The | dictionary of variables to substitute. |
If this expression contains variables like $T
, they are replaced with the corresponding values from matches
. If a variable is present in the expression but is not in matches
, ExcMissingVariable
is thrown.
The substitutions are made in-place.
Definition at line 357 of file ClassName.cxx.
Return a copy of this expression with variables substituted.
The | dictionary of variables to substitute. |
If this expression contains variables like $T
, they are replaced with the corresponding values from matches
. If a variable is present in the expression but is not in matches
, ExcMissingVariable
is thrown.
The substitutions are made in a copy of the expression, which is returned.
Definition at line 390 of file ClassName.cxx.
Swap this expression with another one.
other | The other expression with which to swap. |
Definition at line 197 of file ClassName.cxx.
Return one template argument.
i | Index of the argument to return. |
Definition at line 285 of file ClassName.cxx.
|
private |
Is this expression const?
Definition at line 477 of file CxxUtils/CxxUtils/ClassName.h.
|
private |
The primary name part of this expression.
Definition at line 486 of file CxxUtils/CxxUtils/ClassName.h.
|
private |
The containing namespace.
This vector is always either 0 or 1 elements long; this is a way of getting something sort of like a pointer but with completely automatic management.
Definition at line 483 of file CxxUtils/CxxUtils/ClassName.h.
|
private |
The template arguments for this name.
Definition at line 489 of file CxxUtils/CxxUtils/ClassName.h.