ATLAS Offline Software
Loading...
Searching...
No Matches
CxxUtils::ClassName::Rules Class Reference

A set of transformation rules to use with ClassName. More...

#include <ClassName.h>

Collaboration diagram for CxxUtils::ClassName::Rules:

Public Member Functions

size_t size () const
 Return the number of defined rules.
void add (const ClassName &pattern, const ClassName &replacement)
 Add a new transformation rule.
void add (ClassName &&pattern, ClassName &&replacement)
 Add a new transformation rule (move version).
bool applyTo (ClassName &cn) const
 Apply the set of transformation rules to a class name object.
std::string apply (const std::string &name) const
 Apply transformations to a class name.

Private Types

typedef std::pair< ClassName, ClassNamepat_repl_t
 A pattern and replacement.
typedef std::multimap< std::string, pat_repl_trulemap_t
 Map from the root of a pattern to the pattern, replacement pair.

Private Attributes

rulemap_t m_rules

Detailed Description

A set of transformation rules to use with ClassName.

Definition at line 129 of file CxxUtils/CxxUtils/ClassName.h.

Member Typedef Documentation

◆ pat_repl_t

A pattern and replacement.

Definition at line 191 of file CxxUtils/CxxUtils/ClassName.h.

◆ rulemap_t

typedef std::multimap<std::string, pat_repl_t> CxxUtils::ClassName::Rules::rulemap_t
private

Map from the root of a pattern to the pattern, replacement pair.

Definition at line 194 of file CxxUtils/CxxUtils/ClassName.h.

Member Function Documentation

◆ add() [1/2]

void CxxUtils::ClassName::Rules::add ( ClassName && pattern,
ClassName && replacement )

Add a new transformation rule (move version).

Parameters
patternThe pattern to match.
replacementThe expression with which to replace it.

The pattern may contain variables that are then substituted into the replacement; for example, given a pattern of A<$T, $T> and a replacement of B<$T>, then A<Foo<int>, Foo<int> > would be transformed to ‘B<Foo<int> >’.

Definition at line 78 of file CxxUtils/Root/ClassName.cxx.

80{
81 std::string name = pattern.name();
82 m_rules.insert (std::make_pair (name,
83 std::make_pair (std::move(pattern),
84 std::move(replacement))));
85}
const std::string & name() const
Return the root name of the expression.

◆ add() [2/2]

void CxxUtils::ClassName::Rules::add ( const ClassName & pattern,
const ClassName & replacement )

Add a new transformation rule.

Parameters
patternThe pattern to match.
replacementThe expression with which to replace it.

The pattern may contain variables that are then substituted into the replacement; for example, given a pattern of A<$T, $T> and a replacement of B<$T>, then A<Foo<int>, Foo<int> > would be transformed to ‘B<Foo<int> >’.

Definition at line 60 of file CxxUtils/Root/ClassName.cxx.

62{
63 m_rules.insert (std::make_pair (pattern.name(),
64 std::make_pair (pattern, replacement)));
65}

◆ apply()

std::string CxxUtils::ClassName::Rules::apply ( const std::string & name) const

Apply transformations to a class name.

Parameters
nameThe class name to transform.

Returns the transformed class name.

This is just shorthand for calling ClassName::applyRules.

Definition at line 127 of file CxxUtils/Root/ClassName.cxx.

128{
129 return ClassName::applyRules (name, *this);
130}
void applyRules(const Rules &rules)
Apply a set of transformation rules to this object.

◆ applyTo()

bool CxxUtils::ClassName::Rules::applyTo ( ClassName & cn) const

Apply the set of transformation rules to a class name object.

Parameters
cnThe object to which the rules should be applied. Will be modified in place.

All transformation rules are matched against cn. If any match, the object is replaced with the replacement portion of the rule with match results substituted.

Returns true if any matches were made and false otherwise.

Definition at line 99 of file CxxUtils/Root/ClassName.cxx.

100{
101 bool ret = false;
102 rulemap_t::const_iterator it = m_rules.find (cn.name());
103 while (it != m_rules.end() && it->first == cn.name()) {
104 ClassName::match_t matches;
105 if (cn.match (it->second.first, matches)) {
106 bool const_save = cn.isConst();
107 cn = it->second.second.substCopy (matches);
108 if (const_save) {
109 cn.setConst();
110 }
111 ret = true;
112 }
113 ++it;
114 }
115 return ret;
116}
static std::string name()
Return the name of class T as a string.
std::map< std::string, ClassName > match_t
Map used to hold variable assignments from matching.

◆ size()

size_t CxxUtils::ClassName::Rules::size ( ) const

Return the number of defined rules.

Definition at line 44 of file CxxUtils/Root/ClassName.cxx.

45{
46 return m_rules.size();
47}

Member Data Documentation

◆ m_rules

rulemap_t CxxUtils::ClassName::Rules::m_rules
private

Definition at line 195 of file CxxUtils/CxxUtils/ClassName.h.


The documentation for this class was generated from the following files: