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

# BestFitSelector Class Reference

Inheritance diagram for BestFitSelector

[legend]
Collaboration diagram for BestFitSelector:

[legend]
List of all members.

## Public Methods
Use* | operate (Use* ref_use, Use* new_use)

## Member Function Documentation

Use * BestFitSelector::operate ( | Use * ref_use,
| Use * new_use )`[virtual]`

| Reimplemented from VersionSelector. Definition at line 2349 of file cmt_use.cxx.
    02350 {
    02351   Use* selected = ref_use;
    02352
    02353   int old_v = -1;
    02354   int old_r = -1;
    02355   int old_p = -1;
    02356   cmt_string old_pp;
    02357
    02358   int new_v = -1;
    02359   int new_r = -1;
    02360   int new_p = -1;
    02361   cmt_string new_pp;
    02362
    02363   int alias_v = -1;
    02364   int alias_r = -1;
    02365   int alias_p = -1;
    02366   cmt_string alias_pp;
    02367
    02368   enum { no_alias, new_has_alias, ref_has_alias } has_alias = no_alias;
    02369
    02370   CmtSystem::is_version_directory (ref_use->version, old_v, old_r, old_p);
    02371   old_pp = ref_use->path;
    02372
    02373   CmtSystem::is_version_directory (new_use->version, new_v, new_r, new_p);
    02374   new_pp = new_use->path;
    02375
    02376   if (new_use->version_alias != "")
    02377     {
    02378       has_alias = new_has_alias;
    02379       CmtSystem::is_version_directory (new_use->version_alias,
    02380                                        alias_v, alias_r, alias_p);
    02381       alias_pp = new_use->path_alias;
    02382     }
    02383   else if (ref_use->version_alias != "")
    02384     {
    02385       has_alias = ref_has_alias;
    02386       CmtSystem::is_version_directory (ref_use->version_alias,
    02387                                        alias_v, alias_r, alias_p);
    02388       alias_pp = ref_use->path_alias;
    02389     }
    02390
    02391   ref_use->undiscard ();
    02392   new_use->undiscard ();
    02393
    02394   if (new_v != old_v)
    02395     {
    02396       if (has_alias != no_alias)
    02397         {
    02398           if (has_alias == new_has_alias)
    02399             {
    02400               new_v = alias_v;
    02401               new_r = alias_r;
    02402               new_p = alias_p;
    02403               new_pp = alias_pp;
    02404             }
    02405           else if (has_alias == ref_has_alias)
    02406             {
    02407               old_v = alias_v;
    02408               old_r = alias_r;
    02409               old_p = alias_p;
    02410               old_pp = alias_pp;
    02411             }
    02412         }
    02413     }
    02414
    02415   if (new_v != old_v)
    02416     {
    02417       if (!Cmt::get_quiet ())
    02418         cout << "# Required version " << new_use->version <<
    02419           " of package " << ref_use->package <<
    02420           " incompatible with selected version " << ref_use->version <<
    02421           endl;
    02422
    02423       CmtError::set (CmtError::version_conflict, "BestFitSelector::operate> ");
    02424
    02425       if (ref_use != new_use) new_use->discard ();
    02426     }
    02427   else if (new_r < old_r)
    02428     {
    02429       //
    02430       // we plan to discard new_use, but if it was specified as explicit
    02431       // and ref_use was wildcarded then new_use will win !!
    02432       //
    02433       // So then we'll have to understand where are the wild
    02434       // cards... If they are on v or r, then we consider them.
    02435       //
    02436       //
    02437
    02438
    02439       bool new_is_wildcarded = false;
    02440       bool ref_is_wildcarded = false;
    02441
    02442       if (new_use->specified_version.find ("*") != cmt_string::npos)
    02443         {
    02444           int nv = -1;
    02445           int nr = -1;
    02446           int np = -1;
    02447
    02448           CmtSystem::is_version_directory (new_use->specified_version, nv, nr, np);
    02449           if ((nv == -1) || (nr == -1)) new_is_wildcarded = true;
    02450         }
    02451
    02452       if (ref_use->specified_version.find ("*") != cmt_string::npos)
    02453         {
    02454           int nv = -1;
    02455           int nr = -1;
    02456           int np = -1;
    02457
    02458           CmtSystem::is_version_directory (ref_use->specified_version, nv, nr, np);
    02459           if ((nv == -1) || (nr == -1)) new_is_wildcarded = true;
    02460         }
    02461
    02462       if (!ref_is_wildcarded && new_is_wildcarded)
    02463         {
    02464           if (ref_use != new_use) ref_use->discard ();
    02465           selected = new_use;
    02466           selected->done = false; // Will read the new requirements
    02467         }
    02468       else
    02469         {
    02470           if (!Cmt::get_quiet ())
    02471             cout << "# keep release " << ref_use->version <<
    02472               " of package " << ref_use->package <<
    02473               " (ignore release " << new_use->version << ")" <<
    02474               endl;
    02475
    02476           if (ref_use != new_use) new_use->discard ();
    02477         }
    02478     }
    02479   else if (new_r > old_r)
    02480     {
    02481       if (!Cmt::get_quiet ())
    02482         {
    02483           cout << "# Select release " << new_use->version <<
    02484             " of package " << ref_use->package <<
    02485             " instead of existing " << ref_use->version <<
    02486             endl;
    02487         }
    02488
    02489       if (ref_use != new_use) ref_use->discard ();
    02490       selected = new_use;
    02491       selected->done = false; // Will read the new requirements
    02492     }
    02493   else if (new_p > old_p)
    02494     {
    02495       if (!Cmt::get_quiet ())
    02496         {
    02497           cout << "# Select patch " << new_use->version <<
    02498             " of package " << ref_use->package <<
    02499             " instead of existing " << ref_use->version <<
    02500             endl;
    02501         }
    02502
    02503       if (ref_use != new_use) ref_use->discard ();
    02504       selected = new_use;
    02505       selected->done = false; // Will read the new requirements
    02506     }
    02507   else if (new_pp != old_pp) // same version-r-p but from different path
    02508     {
    02509       if (ref_use != new_use) ref_use->discard ();
    02510       selected = new_use;
    02511       selected->done = false; // Will read the new requirements
    02512     }
    02513
    02514   return (selected);
    02515 }

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

- cmt_use.cxx