User Manual, Developers Guide and API Documentation

Release.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * This file is part of openWNS (open Wireless Network Simulator)
00003  * _____________________________________________________________________________
00004  *
00005  * Copyright (C) 2004-2007
00006  * Chair of Communication Networks (ComNets)
00007  * Kopernikusstr. 16, D-52074 Aachen, Germany
00008  * phone: ++49-241-80-27910,
00009  * fax: ++49-241-80-22242
00010  * email: info@openwns.org
00011  * www: http://www.openwns.org
00012  * _____________________________________________________________________________
00013  *
00014  * openWNS is free software; you can redistribute it and/or modify it under the
00015  * terms of the GNU Lesser General Public License version 2 as published by the
00016  * Free Software Foundation;
00017  *
00018  * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
00019  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
00020  * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00021  * details.
00022  *
00023  * You should have received a copy of the GNU Lesser General Public License
00024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00025  *
00026  ******************************************************************************/
00027 
00028 #include <cstdlib>
00029 #include <WNS/module/Release.hpp>
00030 
00031 using namespace std;
00032 using namespace wns::module;
00033 
00035 Release::Release(const string s)
00036     : empty(s=="")
00037 {
00038     // archive is up to the first /
00039     archive = s.substr(0, s.find("/"));
00040 
00041     // the rest is the FQRN
00042     string fqrn = s.substr(s.find("/") + 1, s.size() - s.find("/") - 1);
00043 
00044     // category is up to the first --
00045     category = fqrn.substr(0, fqrn.find("--"));
00046     // remove category from fqrn
00047     fqrn = fqrn.substr(fqrn.find("--") + 2, fqrn.size() - fqrn.find("--") - 2);
00048 
00049     // branch is up to the first -- now, as category is removed
00050     branch = fqrn.substr(0, fqrn.find("--"));
00051     // remove branch
00052     fqrn = fqrn.substr(fqrn.find("--") + 2, fqrn.size() - fqrn.find("--") - 2);
00053 
00054     // version is up to the first --
00055     version = fqrn.substr(0, fqrn.find("--"));
00056     // revision is the remaining string
00057     revision = fqrn.substr(fqrn.find("--") + 2, fqrn.size() - fqrn.find("--") - 2);
00058 
00059     //  revision = fqrn.substr(0, fqrn.find("--"));
00060     //  fqrn = fqrn.substr(fqrn.find("--") + 2, fqrn.size() - fqrn.find("--") - 2);
00061 }
00062 
00064 Release::Release(const string archive, const string category,
00065          const string branch, const string version,
00066          const string revision)
00067     : empty((archive=="")&&(category=="")&&(branch=="")&&(version=="")&&(revision==""))
00068 {
00069     this->archive = archive;
00070     this->category = category;
00071     this->branch = branch;
00072     this->version = version;
00073     this->revision = revision;
00074 }
00075 
00076 // Operators
00077 
00079 bool Release::operator==(const Release b) const
00080 {
00081     // should we compare archive too?
00082     return empty || b.empty || (((category == b.category) &&
00083                      (branch == b.branch) &&
00084                      (version == b.version) &&
00085                      (revision == b.revision)));
00086 }
00087 
00089 bool Release::operator!=(const Release b) const
00090 {
00091     return empty || b.empty || (!(*this == b));
00092 }
00093 
00095 bool Release::operator<(const Release b) const throw (CategoryMatchError, BranchMatchError)
00096 {
00097     if (empty || b.empty) return true;
00098     else {
00099         // As we don't know what to do if category or branch
00100         // don't match, throw an exception if that's the case.
00101         if (category != b.category) {
00102             throw CategoryMatchError();
00103         }
00104         if (branch != b.branch) {
00105             throw BranchMatchError();
00106         }
00107     
00108         // Compare version and revision
00109         if (version != b.version) {
00110             return versionLowerThan(b.version);
00111         }
00112         else {
00113             return revisionLowerThan(b.revision);
00114         }
00115     }
00116 }
00117 
00119 bool Release::operator>(const Release b) const
00120 {
00121     return empty || b.empty || (((*this != b) && !(*this < b)));
00122 }
00123 
00125 bool Release::operator<=(const Release b) const
00126 {
00127     return empty || b.empty || (((*this == b) || (*this < b)));
00128 }
00129 
00131 bool Release::operator>=(const Release b) const
00132 {
00133     return empty || b.empty || (((*this == b) || (*this > b)));
00134 }
00135 
00136 // Public member functions
00137 
00138 string Release::getString() const
00139 {
00140     return empty ? "" : (archive + "/" + category + "--" + branch + "--" + version + "--" + revision);
00141 }
00142 
00143 string Release::getNiceString() const
00144 {
00145     return empty ? "" : (category + " (" + branch + ") " + version + " " + revision);
00146 }
00147 
00148 // Private member functions
00149 
00150 // Compare two versions
00151 bool Release::versionLowerThan(string s) const
00152 {
00153     // we assume that version is like "12.34"
00154     int ourMajorVersion = atoi(version.substr(0, version.find(".")).c_str());
00155     int ourMinorVersion = atoi(version.substr(version.find(".") + 1, version.size() - version.find(".") - 1).c_str());
00156     int hisMajorVersion = atoi(s.substr(0, s.find(".")).c_str());
00157     int hisMinorVersion = atoi(s.substr(s.find(".") + 1, s.size() - s.find(".") - 1).c_str());
00158 
00159     if (ourMajorVersion == hisMajorVersion)
00160     {
00161         return (ourMinorVersion < hisMinorVersion);
00162     }
00163     else
00164     {
00165         return (ourMajorVersion < hisMajorVersion);
00166     }
00167 }
00168 
00169 // Compare two revisions
00170 bool Release::revisionLowerThan(string s) const
00171 {
00172     // we assume that the revision contains the numbers after a "-" up to the end
00173     int ourPatchLevel = atoi(revision.substr(revision.find("-")).c_str());
00174     int hisPatchLevel = atoi(s.substr(s.find("-")).c_str());
00175 
00176     return (ourPatchLevel < hisPatchLevel);
00177 }
00178 
00179 

Generated on Fri May 25 03:31:48 2012 for openWNS by  doxygen 1.5.5