#include <cmt_pattern.h>
Collaboration diagram for Pattern:
Public Types | |
typedef cmt_vector< Pattern > | PatternVector |
typedef cmt_vector< Pattern * > | PatternPtrVector |
Public Member Functions | |
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 Member Functions | |
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 |
|
Definition at line 28 of file cmt_pattern.h. Referenced by PatternList::find(), PatternList::find_pattern(), and PatternList::get_patterns(). |
|
Definition at line 27 of file cmt_pattern.h. Referenced by add(), Use::apply_global_patterns(), clear_all(), pattern(), pattern_number(), patterns(), Database::patterns(), and show(). |
|
Definition at line 572 of file cmt_pattern.cxx.
00573 { 00574 } |
|
Definition at line 577 of file cmt_pattern.cxx.
00579 { 00580 } |
|
Definition at line 155 of file cmt_pattern.cxx. References add(), CmtSystem::cmt_string_vector, global, name, cmt_vector< T >::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 // <package> 00170 // <PACKAGE> 00171 // <version> 00172 // <path> 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 } |
|
Definition at line 222 of file cmt_pattern.cxx. References PatternList::add(), cmt_vector< T >::add(), PatternList::add_pattern(), clear(), CmtSystem::cmt_string_vector, cmt_string::find(), find(), global, line, name, pattern(), patterns(), PatternVector, cmt_vector< T >::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 <name, use> 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 } |
|
Applies a pattern to one particular use.
Definition at line 728 of file cmt_pattern.cxx. References expand(), SyntaxParser::parse_requirements_text(), Template::TemplateVector, 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 } |
|
Definition at line 718 of file cmt_pattern.cxx. References apply(), and Template::TemplateVector.
00719 { 00720 static Template::TemplateVector dummy_templates; 00721 00722 apply (context_use, dummy_templates); 00723 } |
|
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< T >::size(), PatternCache::update(), use, and Use::UsePtrVector. 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 } |
|
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 } |
|
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 } |
|
Definition at line 583 of file cmt_pattern.cxx. References global, line, name, and use. Referenced by add(), and clear_all().
|
|
Definition at line 323 of file cmt_pattern.cxx. References cmt_vector< T >::clear(), clear(), patterns(), PatternVector, and cmt_vector< T >::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 } |
|
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, Use::prefix, Use::real_path, cmt_string::replace_all(), cmt_vector< Template >::size(), Template::TemplateVector, 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 ("<package>", context_use->get_package_name ().c_str ()); 00764 replacement.replace_all ("<PACKAGE>", context_use->prefix.c_str ()); 00765 replacement.replace_all ("<version>", context_use->version.c_str ()); 00766 replacement.replace_all ("<path>", 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 } |
|
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 } |
|
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 } |
|
Get the index'th pattern in the database.
Definition at line 315 of file cmt_pattern.cxx. References patterns(), and PatternVector. Referenced by add().
00316 { 00317 static PatternVector& Patterns = patterns (); 00318 00319 return (Patterns[index]); 00320 } |
|
Get the number of registered patterns.
Definition at line 305 of file cmt_pattern.cxx. References patterns(), PatternVector, and cmt_vector< T >::size().
00306 { 00307 static PatternVector& Patterns = patterns (); 00308 00309 return (Patterns.size ()); 00310 } |
|
Definition at line 337 of file cmt_pattern.cxx. References Database::instance(), Database::patterns(), and PatternVector. 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 } |
|
Definition at line 592 of file cmt_pattern.cxx. References Use::get_package_name(), global, line, name, use, and Use::version. Referenced by Cmt::do_show_pattern().
|
|
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, patterns(), PatternVector, CmtError::set(), ApplyPattern::show(), cmt_vector< T >::size(), use, Use::UsePtrVector, 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 } |
|
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 } |
|
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< T >::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 } |
|
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 } |
|
Definition at line 68 of file cmt_pattern.h. Referenced by action(), add(), ApplyPattern::apply(), PatternList::apply_all_globals(), Use::apply_global_patterns(), clear(), and show(). |
|
Definition at line 67 of file cmt_pattern.h. Referenced by ApplyPattern::action(), add(), clear(), expand(), and show(). |
|
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(). |
|
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(). |