Main Page Class Hierarchy Compound List File List Compound Members File Members

# ApplyPattern Class Reference

`#include <cmt_pattern.h>`

Collaboration diagram for ApplyPattern:

[legend]
List of all members.

## Public Types
typedef cmt_vector<ApplyPattern> | ApplyPatternVector
## Public Methods
| ApplyPattern ()
| ~ApplyPattern ()
void | show () const
void | apply_globals () const
void | apply () const
## Public Attributes
cmt_string | name
Use* | use
cmt_vector<Template> | replacements
## Static Public Methods
void | action (const CmtSystem::cmt_string_vector& words, Use* use)
ApplyPattern* | add (const cmt_string& name, Use* use)

## Member Typedef Documentation

typedef cmt_vector<ApplyPattern> ApplyPattern::ApplyPatternVector

| Definition at line 66 of file cmt_pattern.h.

## Constructor & Destructor Documentation

ApplyPattern::ApplyPattern ( | )

| Definition at line 588 of file cmt_pattern.cxx.
    00589 {
    00590 }

ApplyPattern::~ApplyPattern ( | )

| Definition at line 593 of file cmt_pattern.cxx.
    00594 {
    00595 }

## Member Function Documentation

void ApplyPattern::action ( | const CmtSystem::cmt_string_vector & words,
| Use * use )`[static]`

| Definition at line 532 of file cmt_pattern.cxx. Referenced by Cmt::select().
    00533 {
    00534     //
    00535     // Expected syntax is
    00536     //
    00537     // apply_pattern <pattern-name> [ <template>=<value> ... ]
    00538     //
    00539
    00540   if (words.size () < 2) return;
    00541
    00542   if (use == 0) use = &(Use::current());
    00543
    00544   cmt_string& name = words[1];
    00545
    00546   ApplyPattern* apply_pattern = add (name, use);
    00547
    00548   for (int i = 2; i < words.size (); i++)
    00549     {
    00550       cmt_string s = words[i];
    00551       int pos = s.find ("=");
    00552       if (pos == cmt_string::npos) break;
    00553       if (pos == 0) break;
    00554
    00555       Template& t = apply_pattern->replacements.add ();
    00556
    00557       s.substr (0, pos, t.name);
    00558       s.substr (pos + 1, t.value);
    00559
    00560       int size = t.value.size ();
    00561
    00562       if (size >= 2)
    00563         {
    00564           if (((t.value[0] == '"') && (t.value[size - 1] == '"')) ||
    00565               ((t.value[0] == '\'') && (t.value[size - 1] == '\'')))
    00566             {
    00567               t.value.erase (size - 1);
    00568               t.value.erase (0, 1);
    00569             }
    00570         }
    00571     }
    00572
    00573   apply_pattern->apply ();
    00574 }

ApplyPattern * ApplyPattern::add ( | const cmt_string & name,
| Use * use )`[static]`

| Definition at line 577 of file cmt_pattern.cxx. Referenced by action().
    00578 {
    00579   ApplyPattern& a = use->apply_patterns.add ();
    00580
    00581   a.name = name;
    00582   a.use  = use;
    00583
    00584   return (&a);
    00585 }

void ApplyPattern::apply ( | ) const

| Definition at line 618 of file cmt_pattern.cxx. Referenced by action().
    00619 {
    00620   cmt_string line;
    00621
    00622   if (CmtSystem::testenv ("CMTTESTPATTERN"))
    00623     {
    00624       cout << "ApplyPattern::apply> " << name << endl;
    00625     }
    00626
    00627   line = "";
    00628   Pattern* p = Pattern::find (name);
    00629   if (p == 0)
    00630     {
    00631       if (CmtSystem::testenv ("CMTTESTPATTERN"))
    00632         {
    00633           cout << "ApplyPattern::apply> " << name << " not found" << endl;
    00634         }
    00635
    00636       return;
    00637     }
    00638
    00639   if (p->global) return;
    00640
    00641   Use* u = use;
    00642   if (u == 0) u = &(Use::current ());
    00643
    00644   p->apply (u, replacements);
    00645 }

void ApplyPattern::apply_globals ( | ) const

void ApplyPattern::show ( | ) const

| Definition at line 598 of file cmt_pattern.cxx. Referenced by Pattern::show(), Pattern::show_all(), and Pattern::show_all_applied_patterns().
    00599 {
    00600   cmt_string line;
    00601
    00602   line = "";
    00603   Pattern* p = Pattern::find (name);
    00604   if (p == 0) return;
    00605
    00606   Use* u = use;
    00607   if (u == 0) u = &(Use::current ());
    00608
    00609   p->expand (u, replacements, line);
    00610
    00611   if (line != "")
    00612     {
    00613       cout << "[" << line << "]" << endl;
    00614     }
    00615 }

## Member Data Documentation

cmt_string ApplyPattern::name

| Definition at line 81 of file cmt_pattern.h.

cmt_vector< Template > ApplyPattern::replacements

| Definition at line 83 of file cmt_pattern.h.

Use * ApplyPattern::use

| Definition at line 82 of file cmt_pattern.h.

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

- cmt_pattern.h
- cmt_pattern.cxx