Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Member Functions | Private Types | Private Attributes | Static Private Attributes
Arc::SoftwareRequirement Class Reference

Class used to express and resolve version requirements on software. More...

#include <Software.h>

Collaboration diagram for Arc::SoftwareRequirement:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 SoftwareRequirement (bool requiresAll=false)
 Create a empty SoftwareRequirement object.
 SoftwareRequirement (const Software &sw, Software::ComparisonOperator swComOp=&Software::operator==, bool requiresAll=false)
 Create a SoftwareRequirement object.
 SoftwareRequirement (const Software &sw, Software::ComparisonOperatorEnum co, bool requiresAll=false)
 Create a SoftwareRequirement object.
SoftwareRequirementoperator= (const SoftwareRequirement &sr)
 Assignment operator.
 SoftwareRequirement (const SoftwareRequirement &sr)
 Copy constructor.
void add (const Software &sw, Software::ComparisonOperator swComOp=&Software::operator==)
 Add a Software object a corresponding comparion operator to this object.
void add (const Software &sw, Software::ComparisonOperatorEnum co)
 Add a Software object a corresponding comparion operator to this object.
bool isRequiringAll () const
 Indicates whether all requirments has to be satisfied.
void setRequirement (bool all)
 Set relation between requirements.
bool isSatisfied (const Software &sw) const
 Test if requirements are satisfied.
bool isSatisfied (const std::list< Software > &swList) const
 Test if requirements are satisfied.
bool isSatisfied (const std::list< ApplicationEnvironment > &swList) const
 Test if requirements are satisfied.
bool selectSoftware (const Software &sw)
 Select software.
bool selectSoftware (const std::list< Software > &swList)
 Select software.
bool selectSoftware (const std::list< ApplicationEnvironment > &swList)
 Select software.
bool isResolved () const
 Indicates whether requirements have been resolved or not.
bool empty () const
 Test if the object is empty.
void clear ()
 Clear the object.
const std::list< Software > & getSoftwareList () const
 Get list of Software objects.
const std::list
< Software::ComparisonOperator > & 
getComparisonOperatorList () const
 Get list of comparison operators.

Private Types

typedef std::pair< Software
*, Software::ComparisonOperator
SWRelPair

Private Attributes

std::list< SoftwaresoftwareList
std::list
< Software::ComparisonOperator
comparisonOperatorList
std::list< std::list< SWRelPair > > orderedSoftwareList
bool requiresAll

Static Private Attributes

static Logger logger

Detailed Description

Class used to express and resolve version requirements on software.

A requirement in this class is defined as a pair composed of a Software object and either a Software::ComparisonOperator method pointer or equally a Software::ComparisonOperatorEnum enum value. A SoftwareRequirement object can contain multiple of such requirements, and then it can specified if all these requirements should be satisfied, or if it is enough to satisfy only one of them. The requirements can be satisfied by a single Software object or a list of either Software or ApplicationEnvironment objects, by using the method isSatisfied(). This class also contain a number of methods (selectSoftware()) to select Software objects which are satisfying the requirements, and in this way resolving requirements.

Definition at line 319 of file Software.h.


Member Typedef Documentation

Definition at line 607 of file Software.h.


Constructor & Destructor Documentation

Arc::SoftwareRequirement::SoftwareRequirement ( bool  requiresAll = false) [inline]

Create a empty SoftwareRequirement object.

The created SoftwareRequirement object will contain no requirements.

Parameters:
requiresAllindicates whether the all requirements have to be satisfied (true) or if only a single one (false), the default is that only a single requirement need to be satisfied.

Definition at line 331 of file Software.h.

Arc::SoftwareRequirement::SoftwareRequirement ( const Software sw,
Software::ComparisonOperator  swComOp = &Software::operator==,
bool  requiresAll = false 
)

Create a SoftwareRequirement object.

The created SoftwareRequirement object will contain one requirement specified by the Software object sw, and the Software::ComparisonOperator swComOp.

This constructor is not available in language bindings created by Swig, since method pointers are not supported by Swig, see SoftwareRequirement(const Software&, Software::ComparisonOperatorEnum, bool) instead.

Parameters:
swis the Software object of the requirement to add.
swComOpis the Software::ComparisonOperator of the requirement to add.
requiresAllindicates whether the all requirements have to be satisfied (true) or if only a single one (false), the default is that only a single requirement need to be satisfied.

Definition at line 143 of file Software.cpp.

  : softwareList(1, sw), comparisonOperatorList(1, swComOp), requiresAll(requiresAll),
    orderedSoftwareList(1, std::list<SWRelPair>(1, SWRelPair(&softwareList.front(), comparisonOperatorList.front())))
{}
Arc::SoftwareRequirement::SoftwareRequirement ( const Software sw,
Software::ComparisonOperatorEnum  co,
bool  requiresAll = false 
)

Create a SoftwareRequirement object.

The created SoftwareRequirement object will contain one requirement specified by the Software object sw, and the Software::ComparisonOperatorEnum co.

Parameters:
swis the Software object of the requirement to add.
cois the Software::ComparisonOperatorEnum of the requirement to add.
requiresAllindicates whether the all requirements have to be satisfied (true) or if only a single one (false), the default is that only a single requirement need to be satisfied.

Definition at line 136 of file Software.cpp.

Copy constructor.

Create a SoftwareRequirement object from another SoftwareRequirement object.

Parameters:
sris the SoftwareRequirement object to make a copy of.

Definition at line 392 of file Software.h.

{ *this = sr; }

Member Function Documentation

void Arc::SoftwareRequirement::add ( const Software sw,
Software::ComparisonOperator  swComOp = &Software::operator== 
)

Add a Software object a corresponding comparion operator to this object.

Adds software name and version to list of requirements and associates the comparison operator with it (equality by default).

This method is not available in language bindings created by Swig, since method pointers are not supported by Swig, see add(const Software&, Software::ComparisonOperatorEnum) instead.

Parameters:
swis the Software object to add as part of a requirement.
swComOpis the Software::ComparisonOperator method pointer to add as part of a requirement, the default operator will be Software::operator==().

Definition at line 176 of file Software.cpp.

                                                                                    {
  if (!sw.empty()) {
    softwareList.push_back(sw);
    comparisonOperatorList.push_back(swComOp);
    for (std::list< std::list<SWRelPair> >::iterator it = orderedSoftwareList.begin();
         it != orderedSoftwareList.end(); it++) {
      if (it->front().first->getName() == sw.getName() &&
          it->front().first->getFamily() == sw.getFamily()) {
        it->push_back(SWRelPair(&softwareList.back(), comparisonOperatorList.back()));
        return;
      }
    }

    orderedSoftwareList.push_back(std::list<SWRelPair>(1, SWRelPair(&softwareList.back(), comparisonOperatorList.back())));
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Add a Software object a corresponding comparion operator to this object.

Adds software name and version to list of requirements and associates the comparison operator with it (equality by default).

Parameters:
swis the Software object to add as part of a requirement.
cois the Software::ComparisonOperatorEnum value to add as part of a requirement, the default enum will be Software::EQUAL.

Definition at line 193 of file Software.cpp.

                                                                                   {
  add(sw, Software::convert(co));
}

Here is the call graph for this function:

void Arc::SoftwareRequirement::clear ( void  ) [inline]

Clear the object.

The requirements in this object will be cleared when invoking this method.

Definition at line 585 of file Software.h.

Here is the caller graph for this function:

bool Arc::SoftwareRequirement::empty ( ) const [inline]

Test if the object is empty.

Returns:
true if this object do no contain any requirements, otherwise false.

Definition at line 579 of file Software.h.

{ return softwareList.empty(); }

Here is the caller graph for this function:

Get list of comparison operators.

Returns:
The list of internally stored comparison operators is returned.
See also:
Software::ComparisonOperator,
getSoftwareList.

Definition at line 602 of file Software.h.

Here is the caller graph for this function:

const std::list<Software>& Arc::SoftwareRequirement::getSoftwareList ( ) const [inline]

Get list of Software objects.

Returns:
The list of internally stored Software objects is returned.
See also:
Software,
getComparisonOperatorList.

Definition at line 594 of file Software.h.

{ return softwareList; }

Here is the caller graph for this function:

Indicates whether all requirments has to be satisfied.

This method returns true if all requirements has to be satisfied. If only one requirement has to be satisfied, false is returned.

Returns:
true if all requirements has to be satisfied, otherwise false.
See also:
setRequirement.

Definition at line 433 of file Software.h.

{ return requiresAll; }

Here is the caller graph for this function:

Indicates whether requirements have been resolved or not.

If specified that only one requirement has to be satisfied, then for this object to be resolved it can only contain one requirement and it has use the equal operator (Software::operator==).

If specified that all requirements has to be satisfied, then for this object to be resolved each requirement must have a Software object with a unique family/name composition, i.e. no other requirements have a Software object with the same family/name composition, and each requirement must use the equal operator (Software::operator==).

If this object has been resolved then true is returned when invoking this method, otherwise false is returned.

Returns:
true if this object have been resolved, otherwise false.

Definition at line 292 of file Software.cpp.

                                           {
  if (!requiresAll)
    return softwareList.size() <= 1 && (softwareList.size() == 0 || comparisonOperatorList.front() == &Software::operator==);
  else {
    for (std::list< std::list<SWRelPair> >::const_iterator it = orderedSoftwareList.begin();
         it != orderedSoftwareList.end(); it++) {
      if (it->size() > 1 || it->front().second != &Software::operator==)
        return false;
    }

    return true;
  }
}

Here is the caller graph for this function:

bool Arc::SoftwareRequirement::isSatisfied ( const Software sw) const [inline]

Test if requirements are satisfied.

Returns true if the requirements are satisfied by the specified Software sw, otherwise false is returned.

Parameters:
swis the Software which should satisfy the requirements.
Returns:
true if requirements are satisfied, otherwise false.
See also:
isSatisfied(const std::list<Software>&) const,
isSatisfied(const std::list<ApplicationEnvironment>&) const,
selectSoftware(const Software&),
isResolved() const.

Definition at line 458 of file Software.h.

{ return isSatisfied(std::list<Software>(1, sw)); }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Arc::SoftwareRequirement::isSatisfied ( const std::list< Software > &  swList) const

Test if requirements are satisfied.

Returns true if stored requirements are satisfied by software specified in swList, otherwise false is returned.

Note that if all requirements must be satisfied and multiple requirements exist having identical name and family all these requirements should be satisfied by a single Software object.

Parameters:
swListis the list of Software objects which should be used to try satisfy the requirements.
Returns:
true if requirements are satisfied, otherwise false.
See also:
isSatisfied(const Software&) const,
isSatisfied(const std::list<ApplicationEnvironment>&) const,
selectSoftware(const std::list<Software>&),
isResolved() const.

Definition at line 197 of file Software.cpp.

                                                                           {
  // Compare Software objects in the 'versions' list with those in 'swList'.
  std::list< std::list<SWRelPair> >::const_iterator itOSL = orderedSoftwareList.begin();
  for (; itOSL != orderedSoftwareList.end(); itOSL++) {
    // Loop over 'swList'.
    std::list<Software>::const_iterator itSWList = swList.begin();
    for (; itSWList != swList.end(); itSWList++) {
      std::list<SWRelPair>::const_iterator itSRL = itOSL->begin();
      for (; itSRL != itOSL->end(); itSRL++) {
        if (((*itSWList).*itSRL->second)(*itSRL->first)) { // One of the requirements satisfied.
          logger.msg(VERBOSE, "Requirement satisfied. %s %s %s.", (std::string)*itSWList, Software::toString(itSRL->second), (std::string)*itSRL->first);
          if (!requiresAll) // Only one satisfied requirement is needed.
            return true;
        }
        else {
          logger.msg(VERBOSE, "Requirement NOT satisfied. %s %s %s.", (std::string)*itSWList, Software::toString(itSRL->second), (std::string)*itSRL->first);
          if (requiresAll) // If requiresAll == true, then a element from the swList have to satisfy all requirements for a unique software (family + name).
            break;
        }
      }

      if (requiresAll && itSRL == itOSL->end()) // All requirements in the group have been satisfied by a single software.
        break;
    }

    if (requiresAll && // All requirements have to be satisfied.
        itSWList == swList.end()) { // End of Software list reached, ie. requirement not satisfied.
      logger.msg(VERBOSE, "End of list reached requirement not met.");
      return false;
    }
  }

  if (requiresAll)
    logger.msg(VERBOSE, "Requirements satisfied.");
  else
    logger.msg(VERBOSE, "Requirements not satisfied.");

  return requiresAll;
}

Here is the call graph for this function:

bool Arc::SoftwareRequirement::isSatisfied ( const std::list< ApplicationEnvironment > &  swList) const

Test if requirements are satisfied.

This method behaves in exactly the same way as the isSatisfied(const Software&) const method does.

Parameters:
swListis the list of ApplicationEnvironment objects which should be used to try satisfy the requirements.
Returns:
true if requirements are satisfied, otherwise false.
See also:
isSatisfied(const Software&) const,
isSatisfied(const std::list<Software>&) const,
selectSoftware(const std::list<ApplicationEnvironment>&),
isResolved() const.

Definition at line 237 of file Software.cpp.

                                                                                         {
  return isSatisfied(reinterpret_cast< const std::list<Software>& >(swList));
}

Here is the call graph for this function:

SoftwareRequirement & Arc::SoftwareRequirement::operator= ( const SoftwareRequirement sr)

Assignment operator.

Set this object equal to that of the passed SoftwareRequirement object sr.

Parameters:
sris the SoftwareRequirement object to set object equal to.

Definition at line 150 of file Software.cpp.

                                                                                 {
  requiresAll = sr.requiresAll;
  softwareList = sr.softwareList;
  comparisonOperatorList = sr.comparisonOperatorList;

  orderedSoftwareList.clear();
  std::list<Software>::iterator itSW = softwareList.begin();
  std::list<Software::ComparisonOperator>::iterator itCO = comparisonOperatorList.begin();
  for (; itSW != softwareList.end(); itSW++, itCO++) {
    std::list< std::list<SWRelPair> >::iterator itRel = orderedSoftwareList.begin();
    for (; itRel != orderedSoftwareList.end(); itRel++) {
      if (itRel->front().first->getName() == itSW->getName() &&
          itRel->front().first->getFamily() == itSW->getFamily()) {
        itRel->push_back(SWRelPair(&*itSW, *itCO));
        break;
      }
    }

    if (itRel == orderedSoftwareList.end())
      orderedSoftwareList.push_back(std::list<SWRelPair>(1, SWRelPair(&*itSW, *itCO)));
  }

  return *this;
}
bool Arc::SoftwareRequirement::selectSoftware ( const Software sw) [inline]

Select software.

If the passed Software sw do not satisfy the requirements false is returned and this object is not modified. If however the Software object sw do satisfy the requirements true is returned and the requirements are set to equal the sw Software object.

Parameters:
swis the Software object used to satisfy requirements.
Returns:
true if requirements are satisfied, otherwise false.
See also:
selectSoftware(const std::list<Software>&),
selectSoftware(const std::list<ApplicationEnvironment>&),
isSatisfied(const Software&) const,
isResolved() const.

Definition at line 510 of file Software.h.

{ return selectSoftware(std::list<Software>(1, sw)); }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Arc::SoftwareRequirement::selectSoftware ( const std::list< Software > &  swList)

Select software.

If the passed list of Software objects swList do not satisfy the requirements false is returned and this object is not modified. If however the list of Software objects swList do satisfy the requirements true is returned and the Software objects satisfying the requirements will replace these with the equality operator (Software::operator==) used as the comparator for the new requirements.

Note that if all requirements must be satisfied and multiple requirements exist having identical name and family all these requirements should be satisfied by a single Software object and it will replace all these requirements.

Parameters:
swListis a list of Software objects used to satisfy requirements.
Returns:
true if requirements are satisfied, otherwise false.
See also:
selectSoftware(const Software&),
selectSoftware(const std::list<ApplicationEnvironment>&),
isSatisfied(const std::list<Software>&) const,
isResolved() const.

Definition at line 241 of file Software.cpp.

                                                                        {
  SoftwareRequirement sr(requiresAll);

  std::list< std::list<SWRelPair> >::const_iterator itOSL = orderedSoftwareList.begin();
  for (; itOSL != orderedSoftwareList.end(); itOSL++) {
    Software * currentSelectedSoftware = NULL; // Pointer to the current selected software from the argument list.
    for (std::list<Software>::const_iterator itSWList = swList.begin();
         itSWList != swList.end(); itSWList++) {
      std::list<SWRelPair>::const_iterator itSRP = itOSL->begin();
      for (; itSRP != itOSL->end(); itSRP++) {
        if (((*itSWList).*itSRP->second)(*itSRP->first)) { // Requirement is satisfied.
          if (!requiresAll)
            break;
        }
        else if (requiresAll)
          break;
      }

      if (requiresAll && itSRP == itOSL->end() || // All requirements satisfied by this software.
          !requiresAll && itSRP != itOSL->end()) { // One requirement satisfied by this software.
        if (currentSelectedSoftware == NULL) { // First software to satisfy requirement. Push it to the selected software.
          sr.softwareList.push_back(*itSWList);
          sr.comparisonOperatorList.push_back(&Software::operator ==);
        }
        else if (*currentSelectedSoftware < *itSWList) { // Select the software with the highest version still satisfying the requirement.
          sr.softwareList.back() = *itSWList;
        }

        currentSelectedSoftware = &sr.softwareList.back();
      }
    }

    if (!requiresAll && sr.softwareList.size() == 1) { // Only one requirement need to be satisfied.
      *this = sr;
      return true;
    }

    if (requiresAll && currentSelectedSoftware == NULL)
      return false;
  }

  if (requiresAll)
    *this = sr;

  return requiresAll;
}

Select software.

This method behaves exactly as the selectSoftware(const std::list<Software>&) method does.

Parameters:
swListis a list of ApplicationEnvironment objects used to satisfy requirements.
Returns:
true if requirements are satisfied, otherwise false.
See also:
selectSoftware(const Software&),
selectSoftware(const std::list<Software>&),
isSatisfied(const std::list<ApplicationEnvironment>&) const,
isResolved() const.

Definition at line 288 of file Software.cpp.

                                                                                      {
  return selectSoftware(reinterpret_cast< const std::list<Software>& >(swList));
}

Here is the call graph for this function:

void Arc::SoftwareRequirement::setRequirement ( bool  all) [inline]

Set relation between requirements.

Specifies if all requirements stored need to be satisfied or if it is enough to satisfy only one of them.

Parameters:
allis a boolean specifying if all requirements has to be satified.
See also:
isRequiringAll().

Definition at line 443 of file Software.h.

{ requiresAll = all; }

Here is the caller graph for this function:


Member Data Documentation

Definition at line 606 of file Software.h.

Definition at line 611 of file Software.h.

std::list< std::list<SWRelPair> > Arc::SoftwareRequirement::orderedSoftwareList [private]

Definition at line 608 of file Software.h.

Definition at line 609 of file Software.h.

Definition at line 605 of file Software.h.


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