Back to index

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

Used to represent software (names and version) and comparison. More...

#include <Software.h>

Inheritance diagram for Arc::Software:
Inheritance graph
[legend]
Collaboration diagram for Arc::Software:
Collaboration graph
[legend]

List of all members.

Public Types

enum  ComparisonOperatorEnum {
  NOTEQUAL = 0, EQUAL = 1, GREATERTHAN = 2, LESSTHAN = 3,
  GREATERTHANOREQUAL = 4, LESSTHANOREQUAL = 5
}
 Comparison operator enum. More...
typedef bool(Software::* ComparisonOperator )(const Software &) const
 Definition of a comparison operator method pointer.

Public Member Functions

 Software ()
 Dummy constructor.
 Software (const std::string &name_version)
 Create a Software object.
 Software (const std::string &name, const std::string &version)
 Create a Software object.
 Software (const std::string &family, const std::string &name, const std::string &version)
 Create a Software object.
bool empty () const
 Indicates whether the object is empty.
bool operator== (const Software &sw) const
 Equality operator.
bool operator!= (const Software &sw) const
 Inequality operator (non-trivial behaviour).
bool operator> (const Software &sw) const
 Greater-than operator.
bool operator< (const Software &sw) const
 Less-than operator.
bool operator>= (const Software &sw) const
 Greater-than or equal operator.
bool operator<= (const Software &sw) const
 Less-than or equal operator.
std::string operator() () const
 Get string representation.
 operator std::string (void) const
 Cast to string.
const std::string & getFamily () const
 Get family.
const std::string & getName () const
 Get name.
const std::string & getVersion () const
 Get version.

Static Public Member Functions

static ComparisonOperator convert (const ComparisonOperatorEnum &co)
 Convert a ComparisonOperatorEnum value to a comparison method pointer.
static std::string toString (ComparisonOperator co)
 Convert Software::ComparisonOperator to a string.

Static Public Attributes

static const std::string VERSIONTOKENS = "-."
 Tokens used to split version string.

Private Attributes

std::string family
std::string name
std::string version
std::list< std::string > tokenizedVersion

Static Private Attributes

static Logger logger

Friends

std::ostream & operator<< (std::ostream &out, const Software &sw)
 Write Software string representation to a std::ostream.

Detailed Description

Used to represent software (names and version) and comparison.

The Software class is used to represent the name of a piece of software internally. Generally software are identified by a name and possibly a version number. Some software can also be categorized by type or family (compilers, operating system, etc.). A software object can be compared to other software objects using the comparison operators contained in this class. The basic usage of this class is to test if some specified software requirement (SoftwareRequirement) are fulfilled, by using the comparability of the class.

Internally the Software object is represented by a family and name identifier, and the software version is tokenized at the characters defined in VERSIONTOKENS, and stored as a list of tokens.

Definition at line 31 of file Software.h.


Member Typedef Documentation

typedef bool(Software::* Arc::Software::ComparisonOperator)(const Software &) const

Definition of a comparison operator method pointer.

This typedef defines a comparison operator method pointer.

See also:
operator==,
operator!=,
operator>,
operator<,
operator>=,
operator<=,
ComparisonOperatorEnum.

Definition at line 45 of file Software.h.


Member Enumeration Documentation

Comparison operator enum.

The ComparisonOperatorEnum enumeration is a 1-1 correspondance between the defined comparison method operators (Software::ComparisonOperator), and can be used in circumstances where method pointers are not supported.

Enumerator:
NOTEQUAL 

see operator!=

EQUAL 

see operator==

GREATERTHAN 

see operator>

LESSTHAN 

see operator<

GREATERTHANOREQUAL 

see operator>=

LESSTHANOREQUAL 

see operator<=

Definition at line 96 of file Software.h.


Constructor & Destructor Documentation

Dummy constructor.

This constructor creates a empty object.

Definition at line 51 of file Software.h.

: family(""), name(""), version("") {};
Arc::Software::Software ( const std::string &  name_version)

Create a Software object.

Create a Software object from a single string composed of a name and a version part. The created object will contain a empty family part. The name and version part of the string will be split at the first occurence of a dash (-) which is followed by a digit (0-9). If the string does not contain such a pattern, the passed string will be taken to be the name and version will be empty.

Parameters:
name_versionshould be a string composed of the name and version of the software to represent.

Definition at line 19 of file Software.cpp.

                                                : version(""), family("") {
  std::size_t pos = 0;

  while (pos != std::string::npos) {
    // Look for dashes in the input string.
    pos = name_version.find_first_of("-", pos);
    if (pos != std::string::npos) {
      // 'name' and 'version' is defined to be seperated at the first dash which
      // is followed by a digit.
      if (isdigit(name_version[pos+1])) {
        name = name_version.substr(0, pos);
        version = name_version.substr(pos+1);
        tokenize(version, tokenizedVersion, VERSIONTOKENS);
        return;
      }

      pos++;
    }
  }

  // If no version part is found from the input string set the input to be the name.
  name = name_version;
}

Here is the call graph for this function:

Arc::Software::Software ( const std::string &  name,
const std::string &  version 
)

Create a Software object.

Create a Software object with the specified name and version. The family part will be left empty.

Parameters:
namethe software name to represent.
versionthe software version to represent.

Definition at line 43 of file Software.cpp.

Here is the call graph for this function:

Arc::Software::Software ( const std::string &  family,
const std::string &  name,
const std::string &  version 
)

Create a Software object.

Create a Software object with the specified family, name and version.

Parameters:
familythe software family to represent.
namethe software name to represent.
versionthe software version to represent.

Definition at line 48 of file Software.cpp.

Here is the call graph for this function:


Member Function Documentation

Convert a ComparisonOperatorEnum value to a comparison method pointer.

The passed ComparisonOperatorEnum will be converted to a comparison method pointer defined by the Software::ComparisonOperator typedef.

This static method is not defined in language bindings created with Swig, since method pointers are not supported by Swig.

Parameters:
coa ComparisonOperatorEnum value.
Returns:
A method pointer to a comparison method is returned.

Definition at line 119 of file Software.cpp.

                                                                                     {
  switch (co) {
  case Software::EQUAL:
    return &Software::operator==;
  case Software::NOTEQUAL:
    return &Software::operator!=;
  case Software::GREATERTHAN:
    return &Software::operator>;
  case Software::LESSTHAN:
    return &Software::operator<;
  case Software::GREATERTHANOREQUAL:
    return &Software::operator>=;
  case Software::LESSTHANOREQUAL:
    return &Software::operator<=;
  };
}

Here is the caller graph for this function:

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

Indicates whether the object is empty.

Returns:
true if the name of this object is empty, otherwise false.

Definition at line 126 of file Software.h.

{ return name.empty(); }

Here is the caller graph for this function:

const std::string& Arc::Software::getFamily ( ) const [inline]

Get family.

Returns:
The family the represented software belongs to is returned.

Definition at line 262 of file Software.h.

{ return family; }

Here is the caller graph for this function:

const std::string& Arc::Software::getName ( ) const [inline]

Get name.

Returns:
The name of the represented software is returned.

Definition at line 267 of file Software.h.

{ return name; }

Here is the caller graph for this function:

const std::string& Arc::Software::getVersion ( ) const [inline]

Get version.

Returns:
The version of the represented software is returned.

Definition at line 272 of file Software.h.

{ return version; }

Here is the caller graph for this function:

Arc::Software::operator std::string ( void  ) const [inline]

Cast to string.

This casting operator behaves exactly as operator()() does. The cast is used like (std::string) <software-object>.

See also:
operator()().

Definition at line 255 of file Software.h.

{ return operator()(); }

Here is the call graph for this function:

bool Arc::Software::operator!= ( const Software sw) const [inline]

Inequality operator (non-trivial behaviour).

The inequality operator should be used to test if two Software objects are of different versions but share the same name and family. So it should not be used to test if two Software objects differ in either name, version or family. Two Software objects are inequal if they share the same name and family but have different versions and the versions are non-empty.

Parameters:
swis the RHS Software object.
Returns:
true when the two objects are inequal, otherwise false.

Definition at line 156 of file Software.h.

                                              { return family == sw.family &&
                                                       name   == sw.name &&
                                                       !(version == sw.version || version.empty() || sw.version.empty()); }
std::string Arc::Software::operator() ( ) const

Get string representation.

Returns the string representation of this object, which is 'family'-'name'-'version'.

Returns:
The string representation of this object is returned.
See also:
operator std::string().

Definition at line 53 of file Software.cpp.

                                     {
  if (empty()) return "";
  if (family.empty() && version.empty()) return name;
  if (family.empty()) return name + "-" + version;
  if (version.empty()) return family + "-" + name;
  return family + "-" + name + "-" + version;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool Arc::Software::operator< ( const Software sw) const [inline]

Less-than operator.

The behaviour of this less-than operator is equivalent to the greater-than operator (operator>()) with the LHS and RHS swapped.

Parameters:
swis the RHS object.
Returns:
true if the LHS is less than the RHS, otherwise false.
See also:
operator>().

Definition at line 199 of file Software.h.

{ return sw.operator>(*this); }
bool Arc::Software::operator<= ( const Software sw) const [inline]

Less-than or equal operator.

The LHS object is greater than or equal to the RHS object if the LHS equal the RHS (operator==()) or if the LHS is greater than the RHS (operator>()).

Parameters:
swis the RHS object.
Returns:
true if the LHS is less than or equal the RHS, otherwise false.
See also:
operator==(),
operator<().

Definition at line 225 of file Software.h.

{ return (*this == sw ? true : *this < sw); }
bool Arc::Software::operator== ( const Software sw) const [inline]

Equality operator.

Two Software objects are equal if they are of the same family, and if they have the same name. If BOTH objects specifies a version they must also equal, for the objects to be equal. Otherwise the two objects does not equal. This operator can also be represented by the Software::EQUAL ComparisonOperatorEnum value.

Parameters:
swis the RHS Software object.
Returns:
true when the two objects equals, otherwise false.

Definition at line 140 of file Software.h.

                                              { return family  == sw.family &&
                                                       name    == sw.name &&
                                                       (version.empty() || sw.version.empty() || version == sw.version); }
bool Arc::Software::operator> ( const Software sw) const

Greater-than operator.

For the LHS object to be greater than the RHS object they must first share the same family and name and have non-empty versions. Then, the first version token of each object is compared and if they are identical, the two next version tokens will be compared. If not identical, the two tokens will be parsed as integers, and if parsing fails the LHS is not greater than the RHS. If parsing succeeds and the integers equals, the two next tokens will be compared, otherwise the comparison is resolved by the integer comparison.

If the LHS contains more version tokens than the RHS, and the comparison have not been resolved at the point of equal number of tokens, then if the additional tokens contains a token which cannot be parsed to a integer the LHS is not greater than the RHS. If the parsed integer is not 0 then the LHS is greater than the RHS. If the rest of the additional tokens are 0, the LHS is not greater than the RHS.

If the RHS contains more version tokens than the LHS and comparison have not been resolved at the point of equal number of tokens, or simply if comparison have not been resolved at the point of equal number of tokens, then the LHS is not greater than the RHS.

Parameters:
swis the RHS object.
Returns:
true if the LHS is greater than the RHS, otherwise false.

Definition at line 61 of file Software.cpp.

                                                 {
  if (family != sv.family || name != sv.name ||
      version.empty() || sv.version.empty() ||
      version == sv.version) return false;

  int lhsInt, rhsInt;
  std::list<std::string>::const_iterator lhsIt, rhsIt;
  for (lhsIt  = tokenizedVersion.begin(), rhsIt  = sv.tokenizedVersion.begin();
       lhsIt != tokenizedVersion.end() && rhsIt != sv.tokenizedVersion.end();
       lhsIt++, rhsIt++) {
    if (*lhsIt == *rhsIt)
      continue;
    if (stringto(*lhsIt, lhsInt) && stringto(*rhsIt, rhsInt)) {
      if (lhsInt > rhsInt) {
        logger.msg(VERBOSE, "%s > %s => true", (std::string)*this, (std::string)sv);
        return true;
      }
      if (lhsInt == rhsInt)
        continue;
    }
    else {
      logger.msg(VERBOSE, "%s > %s => false: \%s contains non numbers in the version part.", (std::string)*this, (std::string)sv, (!stringto(*lhsIt, lhsInt) ? (std::string)*this : (std::string)sv));
      return false;
    }

    logger.msg(VERBOSE, "%s > %s => false", (std::string)*this, (std::string)sv);
    return false;
  }

  if (sv.tokenizedVersion.size() != tokenizedVersion.size()) {
    // Left side contains extra tokens. These must only contain numbers.
    for (; lhsIt != tokenizedVersion.end(); lhsIt++) {
      if (!stringto(*lhsIt, lhsInt)) { // Try to convert ot an integer.
        logger.msg(VERBOSE, "%s > %s => false: %s contains non numbers in the version part.", (std::string)*this, (std::string)sv, (std::string)*this);
        return false;
      }

      if (lhsInt != 0) {
        logger.msg(VERBOSE, "%s > %s => true", (std::string)*this, (std::string)sv);
        return true;
      }
    }
  }

  logger.msg(VERBOSE, "%s > %s => false", (std::string)*this, (std::string)sv);

  return false;
}

Here is the call graph for this function:

bool Arc::Software::operator>= ( const Software sw) const [inline]

Greater-than or equal operator.

The LHS object is greater than or equal to the RHS object if the LHS equal the RHS (operator==()) or if the LHS is greater than the RHS (operator>()).

Parameters:
swis the RHS object.
Returns:
true if the LHS is greated than or equal the RHS, otherwise false.
See also:
operator==(),
operator>().

Definition at line 212 of file Software.h.

{ return (*this == sw ? true : *this > sw); }
std::string Arc::Software::toString ( ComparisonOperator  co) [static]

Convert Software::ComparisonOperator to a string.

This method is not available in language bindings created by Swig, since method pointers are not supported by Swig.

Parameters:
cois a Software::ComparisonOperator.
Returns:
The string representation of the passed Software::ComparisonOperator is returned.

Definition at line 110 of file Software.cpp.

                                                  {
  if (co == &Software::operator==) return "==";
  if (co == &Software::operator<)  return "<";
  if (co == &Software::operator>)  return ">";
  if (co == &Software::operator<=) return "<=";
  if (co == &Software::operator>=) return ">=";
  return "!=";
}

Here is the caller graph for this function:


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  out,
const Software sw 
) [friend]

Write Software string representation to a std::ostream.

Write the string representation of a Software object to a std::ostream.

Parameters:
outis a std::ostream to write the string representation of the Software object to.
swis the Software object to write to the std::ostream.
Returns:
The passed std::ostream out is returned.

Definition at line 237 of file Software.h.

{ out << sw(); return out; }

Member Data Documentation

std::string Arc::Software::family [private]

Definition at line 295 of file Software.h.

Logger Arc::Software::logger [static, private]

Definition at line 300 of file Software.h.

std::string Arc::Software::name [private]

Definition at line 296 of file Software.h.

std::list<std::string> Arc::Software::tokenizedVersion [private]

Definition at line 298 of file Software.h.

std::string Arc::Software::version [private]

Definition at line 297 of file Software.h.

const std::string Arc::Software::VERSIONTOKENS = "-." [static]

Tokens used to split version string.

This string constant specifies which tokens will be used to split the version string.

Definition at line 292 of file Software.h.


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