User Manual, Developers Guide and API Documentation

DependencyList.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 <string>
00029 #include <iostream>
00030 
00031 #include <WNS/module/DependencyList.hpp>
00032 #include <WNS/module/Release.hpp>
00033 
00034 using namespace std;
00035 using namespace wns::module;
00036 
00037 DepListElem::DepListElem(const depModeType mode, const Version dep)
00038     : depMode(mode), dependency(dep)
00039 {
00040 }
00041 
00042 DepListElem::DepListElem(const string s) throw (DepListElemInvalidInitString)
00043     : dependency(Version(s.substr(1)))
00044 {
00045     switch (s[0]) {
00046     case '<':
00047         depMode = LessThan;
00048         break;
00049     case '=':
00050         depMode = EqualTo;
00051         break;
00052     case '>':
00053         depMode = GreaterThan;
00054         break;
00055     default:
00056         throw DepListElemInvalidInitString();
00057     }
00058 }
00059 
00060 DepListElem::depModeType DepListElem::getDepMode() const
00061 {
00062     return depMode;
00063 }
00064 
00065 
00066 Version DepListElem::getDependency() const
00067 {
00068     return dependency;
00069 }
00070 
00071 void DepListElem::setDepMode(const depModeType mode)
00072 {
00073     depMode = mode;
00074 }
00075 
00076 void DepListElem::setDependency(const Version dep)
00077 {
00078     dependency = dep;
00079 }
00080 
00081 bool DepListElem::dependencyMetBy(const Version ver) const
00082 {
00083     switch (depMode) {
00084     case LessThan:
00085         return (ver < dependency);
00086     case EqualTo:
00087         return (ver == dependency);
00088     case GreaterThan:
00089         return (ver > dependency);
00090     default:
00091         cout << "No valid comparison method for dependency checking defined!" << endl;
00092         return false;
00093     }
00094 }
00095 
00096 string DepListElem::getString() const
00097 {
00098     string mode;
00099     switch (depMode) {
00100     case LessThan:
00101         mode = '<';
00102         break;
00103     case EqualTo:
00104         mode = '=';
00105         break;
00106     case GreaterThan:
00107         mode = '>';
00108         break;
00109     }
00110     return mode + dependency.getString();
00111 }
00112 
00113 string DepListElem::getNiceString() const
00114 {
00115     string s = "    +--- ";
00116     switch (depMode) {
00117     case LessThan:
00118         s += "at least ";
00119         break;
00120     case EqualTo:
00121         s += "";
00122         break;
00123     case GreaterThan:
00124         s += "at most ";
00125         break;
00126     }
00127     return s + dependency.getNiceString(false, "    ");
00128 }
00129 
00130 DepList::DepList(const string& s)
00131 {
00132     string deps = s;
00133     while (deps.find("(") != deps.npos) {
00134         depListElements.push_back(DepListElem(deps.substr(deps.find("(") + 1, deps.find(")") - 1)));
00135         deps = deps.substr(deps.find(")") + 1);
00136     }
00137 }
00138 
00139 string DepList::getString() const
00140 {
00141     string s = "";
00142     for (size_t i = 0; i < depListElements.size(); i++) {
00143         s += "(" + depListElements[i].getString() + ")";
00144     }
00145     return s;
00146 }
00147 
00148 string DepList::getNiceString() const
00149 {
00150     string s = "  ";
00151     if(!depListElements.empty()) {
00152         s += "+--- depends on:\n";
00153         for(size_t i = 0; i < depListElements.size(); i++) {
00154             s += depListElements[i].getNiceString();
00155         }
00156     }
00157     return s;
00158 }
00159 

Generated on Wed May 23 03:31:44 2012 for openWNS by  doxygen 1.5.5