![]() |
User Manual, Developers Guide and API Documentation |
![]() |
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 #ifndef WNS_MODULE_DEPENDENCY_LIST_HPP 00029 #define WNS_MODULE_DEPENDENCY_LIST_HPP 00030 00031 #include <WNS/module/Version.hpp> 00032 #include <vector> 00033 00034 namespace wns { namespace module { 00038 class DepListError 00039 { 00040 public: 00041 virtual 00042 ~DepListError() 00043 {} 00044 }; 00045 00053 class DepListElemInvalidInitString : 00054 public DepListError 00055 {}; 00056 00061 class DepListElem 00062 { 00063 public: 00067 enum depModeType { LessThan, EqualTo, GreaterThan }; 00068 00078 DepListElem(const depModeType mode, const Version dep); 00079 00090 DepListElem(const std::string s) throw (DepListElemInvalidInitString); 00091 00098 depModeType getDepMode() const; 00099 00104 Version getDependency() const; 00105 00112 void setDepMode(const depModeType depMode); 00113 00118 void setDependency(const Version dependency); 00119 00125 bool dependencyMetBy(const Version ver) const; 00126 00132 std::string getString() const; 00138 std::string getNiceString() const; 00139 00140 private: 00144 depModeType depMode; 00145 00149 Version dependency; 00150 }; 00151 00160 class DepList 00161 { 00162 typedef std::vector<DepListElem> DepListPredecessor; 00163 public: 00167 DepList() : 00168 depListElements() 00169 {} 00170 00181 explicit 00182 DepList(const std::string& s); 00183 00184 // public member functions 00185 00199 template<class VerList> 00200 bool 00201 dependenciesMetBy(const VerList vers, const VerList end) const; 00202 00206 std::string getString() const; 00211 std::string getNiceString() const; 00212 private: 00213 // The following function exists only to make dependeciesMetBy() look 00214 // a bit nicer and is not needed anywhere else, thus should be a nested 00215 // function, if that was possible. But as it isn't, it's where it is now... 00220 bool projectDoesMatch(const Version v1, const Version v2) const 00221 { 00222 return (v1.getBuildRelease().getCategory() == v2.getBuildRelease().getCategory()) 00223 && (v1.getBuildRelease().getBranch() == v2.getBuildRelease().getBranch()); 00224 } 00225 00226 DepListPredecessor depListElements; 00227 }; 00228 00233 template<class VerList> 00234 bool 00235 DepList::dependenciesMetBy(const VerList vers, const VerList end) const 00236 { 00237 // go through all dependencies 00238 for (size_t i = 0; i < depListElements.size(); ++i) { 00239 // ... and for each dependency try to find a matching version in the list 00240 VerList vi = vers; 00241 00242 while ((vi != end) && !projectDoesMatch(depListElements[i].getDependency(), vi->getVersion())) ++vi; 00243 // abort, if no matching version was found... 00244 if ((vi == end) || !depListElements[i].dependencyMetBy(vi->getVersion())) return false; 00245 // ... otherwise continue 00246 } 00247 // all dependencies are met 00248 return true; 00249 } 00250 } // module 00251 } // wns 00252 00253 #endif // NOT defined WNS_MODULE_DEPENDENCY_LIST_HPP
1.5.5