Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Member Functions | Private Member Functions | Private Attributes
RTE Class Reference

Interface for handling runtime environments. More...

#include <rte.h>

Collaboration diagram for RTE:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 RTE (const std::string &re)
 Constructs a new runtime environemt.
 ~RTE ()
 Destructor.
std::string str () const
 Returns a string representation of the runtime environment.
std::string Name () const
 Returns the name of the runtime environment.
std::string Version () const
 Returns the version of the runtime environment.
bool operator== (const RTE &other) const
 Equliaty operator.
bool operator!= (const RTE &other) const
 Inequility operator.
bool operator> (const RTE &other) const
 Greater than operator.
bool operator< (const RTE &other) const
 Less than operator.
bool operator>= (const RTE &other) const
 Greater or equal operator.
bool operator<= (const RTE &other) const
 Less than or equal operator.

Private Member Functions

std::vector< std::string > SplitVersion (const std::string &version) const
 Internally used method for splitting a version string into numeric tokens.

Private Attributes

std::string runtime_environment
std::string name
std::string version

Detailed Description

Interface for handling runtime environments.

RTE class. It represents a runtime environment, and provides functionality for getting information about them.

Definition at line 14 of file rte.h.


Constructor & Destructor Documentation

RTE::RTE ( const std::string &  re)

Constructs a new runtime environemt.

String should in general be of the type: STRING-VERSION. Where version consists of numbers with . between them.

Definition at line 9 of file rte.cpp.

                            {

       runtime_environment = re;

       name = runtime_environment;
       version = "";

       /* This has some assumptions, but holds for all the sane ones */
       std::string::size_type pos = re.find_first_of(" -");
       while ((pos != std::string::npos) && !(isdigit(re[pos+1])))
              pos = re.find_first_of(" -", pos+1);
       if (pos != std::string::npos) {
              name = re.substr (0, pos);
              version = re.substr(pos+1);
       }
}
RTE::~RTE ( )

Destructor.

Not that much to say.

Definition at line 27 of file rte.cpp.

{ }

Member Function Documentation

std::string RTE::Name ( void  ) const

Returns the name of the runtime environment.

Definition at line 35 of file rte.cpp.

                          {
       return name;
}

Here is the caller graph for this function:

bool RTE::operator!= ( const RTE other) const

Inequility operator.

Return the opsite of ==

Definition at line 53 of file rte.cpp.

                                           {
       return !(*this == other);
}
bool RTE::operator< ( const RTE other) const

Less than operator.

Returns false if the other is equal, otherwise it returns the opposite of >

Definition at line 94 of file rte.cpp.

                                          {
       if (*this == other) return false;
       return !(*this > other);
}
bool RTE::operator<= ( const RTE other) const

Less than or equal operator.

Returns the oppsite of >

Definition at line 105 of file rte.cpp.

                                           {
       return !(*this > other);
}
bool RTE::operator== ( const RTE other) const

Equliaty operator.

Returns true if the runtime environments have the string representation.

Definition at line 45 of file rte.cpp.

                                           {
       if (runtime_environment==other.str())
              return true;
       else
              return false;
}

Here is the call graph for this function:

bool RTE::operator> ( const RTE other) const

Greater than operator.

Returns true if the compared runtime environment is greater than the current.

Definition at line 58 of file rte.cpp.

                                          {

       if (name!=other.Name()) return (name>other.Name());

       // Get version
       std::vector<std::string> my_version = SplitVersion(version);
       std::vector<std::string> other_version = SplitVersion(other.Version());

       // Ensure common length
       int ml = my_version.size();
       int ol = other_version.size();
       unsigned int max_size = std::max(ml, ol);

       while (my_version.size()<max_size)
              my_version.push_back("0");
       while (other_version.size()<max_size)
              other_version.push_back("0");

       // Start comparing
       for (unsigned int i=0; i<max_size; i++) {
              if (my_version[i]==other_version[i]) continue;
              // first try to compare as integers
                char* my_e;
                char* other_e;
                int my_v = strtol(my_version[i].c_str(),&my_e,0);
                int other_v = strtol(other_version[i].c_str(),&other_e,0);
                if((*my_e == 0) && (*other_e == 0)) return (my_v > other_v);
              // otherwise compare as strings
              return my_version[i]>other_version[i];
       }

       // If we are here the versions are the same.
       return false;
}

Here is the call graph for this function:

bool RTE::operator>= ( const RTE other) const

Greater or equal operator.

Returns the opposite of <

Definition at line 100 of file rte.cpp.

                                           {
       return !(*this < other);
}
std::vector< std::string > RTE::SplitVersion ( const std::string &  version) const [private]

Internally used method for splitting a version string into numeric tokens.

Definition at line 110 of file rte.cpp.

               {

       std::vector<std::string> tokens;
       if (version.empty()) return tokens;

       std::string::size_type pos = 0;
       std::string::size_type last = 0;

       while ((pos = version.find_first_of(".-", last)) != std::string::npos) {
              std::string token = version.substr(last, pos-last);
              tokens.push_back(token);
              last = pos + 1;
       }

       std::string lasttoken = version.substr(last, version.size()-last);
       tokens.push_back(lasttoken);

       return tokens;
}

Here is the caller graph for this function:

std::string RTE::str ( void  ) const

Returns a string representation of the runtime environment.

This is usually the same as given in the constructor.

Definition at line 30 of file rte.cpp.

                         {
       return runtime_environment;
}

Here is the caller graph for this function:

std::string RTE::Version ( ) const

Returns the version of the runtime environment.

Definition at line 40 of file rte.cpp.

                             {
       return version;
}

Here is the caller graph for this function:


Member Data Documentation

std::string RTE::name [private]

Definition at line 80 of file rte.h.

std::string RTE::runtime_environment [private]

Definition at line 79 of file rte.h.

std::string RTE::version [private]

Definition at line 81 of file rte.h.


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