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

Pattern Class Reference

#include <cmt_pattern.h>

Collaboration diagram for Pattern:

[legend]
List of all members.

Public Types

typedef cmt_vector< Pattern >? PatternVector
typedef cmt_vector< Pattern * >? PatternPtrVector

Public Methods

? Pattern ()
? ~Pattern ()
void? clear ()
void? apply () const
? Applies a pattern to all uses (except CMT itself) between current and the use that declared the pattern.

void? apply (Use *constext_use) const
void? apply (Use *constext_use, const Template::TemplateVector &templates) const
? Applies a pattern to one particular use.

void? expand (Use *constext_use, const Template::TemplateVector &templates, cmt_string &line) const
void? show () const

Static Public Methods

void? action (const CmtSystem::cmt_string_vector &words, Use *use)
Pattern *? find (const cmt_string &name)
? Patterns are stored with two keys : and .

Pattern *? find (const cmt_string &name, Use *use)
void? add (const cmt_string &name, const CmtSystem::cmt_string_vector &words, int start_index, bool global, Use *use)
int? pattern_number ()
? Get the number of registered patterns.

Pattern &? pattern (int index)
? Get the index'th pattern in the database.

void? clear_all ()
PatternVector &? patterns ()
void? apply_all_globals ()
? Applies all global patterns to all uses.

void? apply_all_globals (Use *use)
? Applies all global patterns to a given Use.

void? show_all_names ()
void? show_all ()
? this is the cmt show patterns command It just shows the pattern declarations.

void? show_all_applied_patterns ()
? this is the cmt show applied_patterns command It just shows the pattern applications.

void? show (const cmt_string &name)
? This is the cmt show pattern command It shows both the pattern definition(s) and the places where it is explicitly applied.


Public Attributes

cmt_string? name
cmt_string? line
bool? global
Use *? use

Member Typedef Documentation

typedef cmt_vector Pattern::PatternPtrVector
?

Definition at line 28 of file cmt_pattern.h.

typedef cmt_vector Pattern::PatternVector
?

Definition at line 27 of file cmt_pattern.h.


Constructor & Destructor Documentation

Pattern::Pattern (? ? )?
?

Definition at line 572 of file cmt_pattern.cxx.

00573 {
00574 }

Pattern::~Pattern (? ? )?
?

Definition at line 577 of file cmt_pattern.cxx.

00579 {
00580 }

Member Function Documentation

void Pattern::action (? const CmtSystem::cmt_string_vector &? ? words,
Use *? ? use
)? [static]
?

Definition at line 155 of file cmt_pattern.cxx.

References add(), global, name, cmt_vector< cmt_string >::size(), and CmtSystem::testenv().

Referenced by KwdPattern::action().

00156 {
00157   bool global = false;
00158   int start_index;
00159 
00160   if (words.size () < 2) return;
00161 
00162     //
00163     // expected syntax is:
00164     //
00165     //  pattern [-global] pattern-name any-cmt-statement
00166     //
00167     // where any-cmt-statement may contain "templates"
00168     //
00169     //      
00170     //      
00171     //      
00172     //      
00173     //
00174 
00175   cmt_string& option = words[1];
00176 
00177   if (option == "-global")
00178     {
00179       global = true;
00180       start_index = 2;
00181     }
00182   else
00183     {
00184       start_index = 1;
00185     }
00186 
00187   cmt_string& name = words[start_index];
00188 
00189   start_index++;
00190 
00191   add (name, words, start_index, global, use);
00192 
00193   if (CmtSystem::testenv ("CMTTESTPATTERN"))
00194     {
00195       cout << "Pattern::action> add " << name << endl;
00196     }
00197 }

void Pattern::add (? const cmt_string &? ? name,
const CmtSystem::cmt_string_vector &? ? words,
int? ? start_index,
bool? ? global,
Use *? ? use
)? [static]
?

Definition at line 222 of file cmt_pattern.cxx.

References PatternList::add(), cmt_vector< Pattern >::add(), PatternList::add_pattern(), clear(), cmt_string::find(), find(), global, line, name, cmt_string::npos, pattern(), patterns(), cmt_vector< cmt_string >::size(), and use.

Referenced by action().

00227 {
00228   static PatternVector& Patterns = patterns ();
00229 
00230   Pattern* pattern;
00231 
00232   pattern = find (name, use);
00233 
00234   if (pattern == 0)
00235     {
00236         // No pattern for the pair  exist yet.
00237         // create one.
00238       Pattern& p = Patterns.add ();
00239 
00240       p.clear ();
00241 
00242       p.name = name;
00243       p.use  = use;
00244 
00245       PatternList* pl = PatternList::add (name);
00246       pl->add_pattern (&p);
00247 
00248       pattern = &p;
00249     }
00250   else
00251     {
00252       Pattern& p = *pattern;
00253 
00254       p.clear ();
00255 
00256       p.name = name;
00257       p.use  = use;
00258     }
00259 
00260   pattern->line = "";
00261 
00262   int first_word = start_index;
00263 
00264     //
00265     // Install the cmt-statement both as a vector of words and as a single line
00266     //
00267   for (int i = start_index; i < words.size (); i++)
00268     {
00269       bool need_quotes = (i > (first_word + 1));
00270       //bool need_quotes = true;
00271 
00272       cmt_string& s = words[i];
00273 
00274       if (i > start_index) pattern->line += " ";
00275 
00276       if (s == ";") first_word = i+1;
00277 
00278       if ((s == "\n") | (s == ";"))
00279         {
00280           pattern->line += "\n  ";
00281         }
00282       else
00283         {
00284           cmt_string sep = "\"";
00285 
00286           if (s.find (sep) != cmt_string::npos)
00287             {
00288               sep = "\'";
00289             }
00290 
00291           if (!need_quotes) sep = "";
00292 
00293           pattern->line += sep;
00294           pattern->line += s;
00295           pattern->line += sep;
00296         }
00297     }
00298 
00299   pattern->global = global;
00300 }

void Pattern::apply (? Use *? ? context_use,
const Template::TemplateVector &? ? templates
)? const
?

Applies a pattern to one particular use.

Definition at line 728 of file cmt_pattern.cxx.

References expand(), SyntaxParser::parse_requirements_text(), and CmtSystem::testenv().

00730 {
00731   cmt_string replacement;
00732 
00733   expand (context_use, templates, replacement);
00734 
00735   if (CmtSystem::testenv ("CMTTESTPATTERN"))
00736     {
00737       cout << "Pattern::apply> replacement=[" << replacement << "]" << endl;
00738     }
00739 
00740   if (replacement != "")
00741     {
00742       SyntaxParser::parse_requirements_text (replacement, "", context_use);
00743     }
00744 }

void Pattern::apply (? Use *? ? constext_use )? const
?

Definition at line 718 of file cmt_pattern.cxx.

References apply().

00719 {
00720   static Template::TemplateVector dummy_templates;
00721 
00722   apply (context_use, dummy_templates);
00723 }

void Pattern::apply (? ? )? const
?

Applies a pattern to all uses (except CMT itself) between current and the use that declared the pattern.

Definition at line 688 of file cmt_pattern.cxx.

References Use::current(), IgnorePattern::find(), Cmt::get_debug(), PatternCache::get_list(), Use::get_ordered_uses(), Use::get_package_name(), name, cmt_vector< Use * >::size(), PatternCache::update(), and use.

Referenced by ApplyPattern::apply(), apply(), PatternList::apply_all_globals(), and Use::apply_global_patterns().

00689 {
00690   Use::UsePtrVector& uses = Use::get_ordered_uses ();
00691 
00692   Use* current = &(Use::current());
00693 
00694   if (Cmt::get_debug ())
00695     {
00696       cout << "Pattern(" << name << "::apply> " << " defined in " << use->get_package_name () << endl;
00697     }
00698 
00699   if (!PatternCache::update (current, use)) return;
00700 
00701   Use::UsePtrVector& list = PatternCache::get_list ();
00702 
00703   for (int i = 0; i < list.size (); i++)
00704     {
00705       Use* u = list[i];
00706 
00707       if (Cmt::get_debug ())
00708         {
00709           cout << "Pattern(" << name << "::apply> " << " to package " << u->get_package_name () << endl;
00710         }
00711 
00712       if ((u->get_package_name () != "CMT") && 
00713           (IgnorePattern::find (name, u) == 0)) apply (u);
00714     }
00715 }

void Pattern::apply_all_globals (? Use *? ? use )? [static]
?

Applies all global patterns to a given Use.

Definition at line 466 of file cmt_pattern.cxx.

References PatternList::apply_all_globals().

00467 {
00468   PatternList::apply_all_globals ();
00469 }

void Pattern::apply_all_globals (? ? )? [static]
?

Applies all global patterns to all uses.

Definition at line 458 of file cmt_pattern.cxx.

References PatternList::apply_all_globals().

Referenced by Cmt::load(), and Cmt::reach_current_package().

00459 {
00460   PatternList::apply_all_globals ();
00461 }

void Pattern::clear (? ? )?
?

Definition at line 583 of file cmt_pattern.cxx.

References global, line, name, and use.

Referenced by add(), and clear_all().

00584 {
00585   global = false;
00586   name = "";
00587   use = 0;
00588   line = "";
00589 }

void Pattern::clear_all (? ? )? [static]
?

Definition at line 323 of file cmt_pattern.cxx.

References cmt_vector< Pattern >::clear(), clear(), patterns(), and cmt_vector< Pattern >::size().

Referenced by Database::clear().

00324 {
00325   static PatternVector& Patterns = patterns ();
00326 
00327   for (int i = 0; i < Patterns.size (); i++)
00328     {
00329       Pattern& p = Patterns[i];
00330       p.clear ();
00331     }
00332 
00333   Patterns.clear ();
00334 }

void Pattern::expand (? Use *? ? constext_use,
const Template::TemplateVector &? ? templates,
cmt_string &? ? line
)? const
?

Definition at line 747 of file cmt_pattern.cxx.

References cmt_string::c_str(), Use::current(), cmt_string::erase(), cmt_string::find(), Use::get_package_name(), line, Template::name, cmt_string::npos, Use::prefix, Use::real_path, cmt_string::replace_all(), cmt_vector< Template >::size(), CmtSystem::testenv(), Template::value, and Use::version.

Referenced by apply(), and ApplyPattern::show().

00750 {
00751   if (context_use == 0) context_use = &(Use::current ());
00752 
00753   if (CmtSystem::testenv ("CMTTESTPATTERN"))
00754     {
00755       cout << "Pattern::expand1> line=[" << line << "]" << endl;
00756     }
00757 
00758   replacement = line;
00759 
00760   if (replacement != "")
00761     {
00762         // Substitute templates from the cmt statement
00763       replacement.replace_all ("", context_use->get_package_name ().c_str ());
00764       replacement.replace_all ("", context_use->prefix.c_str ());
00765       replacement.replace_all ("", context_use->version.c_str ());
00766       replacement.replace_all ("",    context_use->real_path.c_str ());
00767 
00768       for (int j = 0; j < templates.size (); j++)
00769         {
00770           Template& t = templates[j];
00771           cmt_string s;
00772           s = "<";
00773           s += t.name;
00774           s += ">";
00775           replacement.replace_all (s, t.value);
00776         }
00777 
00778       for (;;)
00779         {
00780           int begin = replacement.find ("<");
00781           if (begin == cmt_string::npos) break;
00782           int end = replacement.find (begin, ">");
00783           if (end == cmt_string::npos) break;
00784           // Do not erase XML constructs
00785           if (replacement[end-1] == '/') break;
00786           replacement.erase (begin, end - begin + 1);
00787         }
00788 
00789       if (CmtSystem::testenv ("CMTTESTPATTERN"))
00790         {
00791           cout << "Pattern::expand2> repl=[" << replacement << "]" << endl;
00792         }
00793 
00794     }
00795 }

Pattern * Pattern::find (? const cmt_string &? ? name,
Use *? ? use
)? [static]
?

Definition at line 214 of file cmt_pattern.cxx.

References PatternList::find().

00215 {
00216   Pattern* p = PatternList::find (name, use);
00217 
00218   return (p);
00219 }

Pattern * Pattern::find (? const cmt_string &? ? name )? [static]
?

Patterns are stored with two keys : and .

thus search must done against these two keys.

Definition at line 206 of file cmt_pattern.cxx.

References PatternList::find_pattern().

Referenced by ApplyPattern::action(), add(), ApplyPattern::apply(), SyntaxParser::do_parse_words(), ApplyPattern::show(), and show().

00207 {
00208   Pattern* p = PatternList::find_pattern (name);
00209 
00210   return (p);
00211 }

Pattern & Pattern::pattern (? int? ? index )? [static]
?

Get the index'th pattern in the database.

Definition at line 315 of file cmt_pattern.cxx.

References patterns().

Referenced by add().

00316 {
00317   static PatternVector& Patterns = patterns ();
00318 
00319   return (Patterns[index]);
00320 }

int Pattern::pattern_number (? ? )? [static]
?

Get the number of registered patterns.

Definition at line 305 of file cmt_pattern.cxx.

References patterns(), and cmt_vector< Pattern >::size().

00306 {
00307   static PatternVector& Patterns = patterns ();
00308 
00309   return (Patterns.size ());
00310 }

Pattern::PatternVector & Pattern::patterns (? ? )? [static]
?

Definition at line 337 of file cmt_pattern.cxx.

References Database::instance(), and Database::patterns().

Referenced by add(), Use::apply_global_patterns(), clear_all(), pattern(), pattern_number(), and show().

00338 {
00339   static Database& db = Database::instance ();
00340   static PatternVector& Patterns = db.patterns ();
00341 
00342   return (Patterns);
00343 }

void Pattern::show (? ? )?
?

Definition at line 592 of file cmt_pattern.cxx.

References Use::get_package_name(), line, name, use, and Use::version.

Referenced by Cmt::do_show_pattern().

00593 {
00594   if (use != 0) cout << "# " << use->get_package_name () << " " << use->version;
00595   else cout << "# ?? ";
00596 
00597   cout  << " defines ";
00598 
00599   if (global) cout << "global ";
00600   
00601   cout << "pattern " << name << " as" << endl;
00602   cout << "  " << line << endl;
00603 }

void Pattern::show (? const cmt_string &? ? name )? [static]
?

This is the cmt show pattern command It shows both the pattern definition(s) and the places where it is explicitly applied.

Definition at line 511 of file cmt_pattern.cxx.

References Use::apply_patterns, Use::current(), find(), Use::get_ordered_uses(), Use::get_package_name(), ApplyPattern::name, CmtError::pattern_not_found, patterns(), CmtError::set(), ApplyPattern::show(), cmt_vector< ApplyPattern >::size(), cmt_vector< Use * >::size(), use, and Use::version.

Referenced by PatternList::show_all_patterns().

00512 {
00513   static PatternVector& Patterns = patterns ();
00514 
00515   int i;
00516   int j;
00517 
00518   bool found = false;
00519 
00520     // First show the definitions.
00521 
00522   Pattern* p = Pattern::find (name);
00523 
00524   if (p == 0)
00525     {
00526       CmtError::set (CmtError::pattern_not_found, name);
00527       return;
00528     }
00529 
00530   p->show ();
00531 
00532     //
00533     // Then show the packages which explicitly apply the pattern.
00534     //
00535   Use* use;
00536   ApplyPattern* apply_pattern = 0;
00537 
00538   Use::UsePtrVector& uses = Use::get_ordered_uses ();
00539 
00540   for (i = 0; i < uses.size (); i++)
00541     {
00542       use = uses[i];
00543       for (j = 0; j < use->apply_patterns.size (); j++)
00544         {
00545           apply_pattern = &(use->apply_patterns[j]);
00546             
00547           if (apply_pattern->name == name)
00548             {
00549               cout << "# applied by " << use->get_package_name () << " => " << endl;
00550               apply_pattern->show ();
00551               cout << endl;
00552             }
00553         }
00554     }
00555 
00556   use = &(Use::current ());
00557   for (j = 0; j < use->apply_patterns.size (); j++)
00558     {
00559       apply_pattern = &(use->apply_patterns[j]);
00560         
00561       if (apply_pattern->name == name)
00562         {
00563           cout << "# " << use->get_package_name () << " " << use->version << " applies pattern " << name;
00564           cout << " => " << endl;
00565           apply_pattern->show ();
00566           cout << endl;
00567         }
00568     }
00569 }

void Pattern::show_all (? ? )? [static]
?

this is the cmt show patterns command It just shows the pattern declarations.

Definition at line 475 of file cmt_pattern.cxx.

References show_all_applied_patterns(), and PatternList::show_all_patterns().

Referenced by Cmt::do_show_patterns().

00476 {
00477   PatternList::show_all_patterns ();
00478 
00479   show_all_applied_patterns ();
00480 }

void Pattern::show_all_applied_patterns (? ? )? [static]
?

this is the cmt show applied_patterns command It just shows the pattern applications.

Definition at line 486 of file cmt_pattern.cxx.

References Use::apply_patterns, Use::current(), Use::get_package_name(), ApplyPattern::name, ApplyPattern::show(), cmt_vector< ApplyPattern >::size(), and use.

Referenced by Cmt::do_show_applied_patterns(), and show_all().

00487 {
00488   Use* use = &(Use::current ());
00489   for (int i = 0; i < use->apply_patterns.size (); i++)
00490     {
00491       const ApplyPattern& apply_pattern = use->apply_patterns[i];
00492 
00493       cout << "# " << use->get_package_name ()
00494            << " applies pattern " << apply_pattern.name << " => " << endl;
00495       apply_pattern.show ();
00496       cout << endl;
00497     }
00498 }

void Pattern::show_all_names (? ? )? [static]
?

Definition at line 501 of file cmt_pattern.cxx.

References PatternList::show_all_pattern_names().

Referenced by Cmt::do_show_pattern_names().

00502 {
00503   PatternList::show_all_pattern_names ();
00504 }

Member Data Documentation

bool Pattern::global
?

Definition at line 68 of file cmt_pattern.h.

Referenced by action(), add(), ApplyPattern::apply(), PatternList::apply_all_globals(), Use::apply_global_patterns(), and clear().

cmt_string Pattern::line
?

Definition at line 67 of file cmt_pattern.h.

Referenced by ApplyPattern::action(), add(), clear(), expand(), and show().

cmt_string Pattern::name
?

Definition at line 66 of file cmt_pattern.h.

Referenced by action(), add(), apply(), PatternList::apply_all_globals(), clear(), show(), and PatternList::show_all_pattern_names().

Use* Pattern::use
?

Definition at line 69 of file cmt_pattern.h.

Referenced by add(), PatternList::add_pattern(), apply(), clear(), PatternList::find(), show(), and show_all_applied_patterns().


The documentation for this class was generated from the following files:
Generated on Wed Sep 1 11:00:48 2004 for CMT by 1.2.18