![]() |
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 #include <WNS/module/Version.hpp> 00029 00030 using namespace std; 00031 using namespace wns::module; 00032 00033 // Component constructor 00034 Version::Version(const Release bRelease, const DateTime bTime, 00035 const string bUser, const string bHost, 00036 const string bFlags, const DateTime mTime, 00037 const string mFile) 00038 : buildTime(bTime), 00039 buildUser(bUser), 00040 buildHost(bHost), 00041 buildFlags(bFlags), 00042 buildRelease(bRelease), 00043 modificationTime(mTime), 00044 modifiedFile(mFile) 00045 { 00046 } 00047 00048 // One string contructor 00049 Version::Version(const string s) 00050 : buildTime((long int)(atof(Syntax::extractTime(s).c_str()))), 00051 buildUser(Syntax::extractUser(s)), 00052 buildHost(Syntax::extractHost(s)), 00053 buildFlags(Syntax::extractFlags(s)), 00054 buildRelease(Syntax::extractRelease(s)), 00055 modificationTime(atol(Syntax::extractModificationTime(s).c_str())), 00056 modifiedFile(Syntax::extractModifiedFile(s)) 00057 { 00058 } 00059 00060 // Operators 00061 00062 // Equality operator 00063 bool Version::operator==(const Version b) const 00064 { 00065 return ((buildRelease == b.buildRelease) && 00066 ((modificationTime == b.modificationTime) || 00067 modificationTime.isEmpty() || b.modificationTime.isEmpty())); 00068 } 00069 00070 // Inequality operator 00071 bool Version::operator!=(const Version b) const 00072 { 00073 return !(*this == b); 00074 } 00075 00076 // Less operator 00077 bool Version::operator<(const Version b) const 00078 { 00079 if (buildRelease != b.buildRelease) 00080 { 00081 return (buildRelease < b.buildRelease); 00082 } 00083 else 00084 { 00085 return (modificationTime < b.modificationTime); 00086 } 00087 } 00088 00089 // Greater operator 00090 bool Version::operator>(const Version b) const 00091 { 00092 return ((*this != b) && !(*this < b)); 00093 } 00094 00095 // Less than or equal operator 00096 bool Version::operator<=(const Version b) const 00097 { 00098 return ((*this == b) || (*this < b)); 00099 } 00100 00101 // Greater than or equal operator 00102 bool Version::operator>=(const Version b) const 00103 { 00104 return ((*this == b) || (*this > b)); 00105 } 00106 00107 // Public member functions 00108 // Selectors / Accessors 00109 00110 wns::module::DateTime 00111 Version::getBuildTime() const 00112 { 00113 return buildTime; 00114 } 00115 00116 string Version::getBuildUser() const 00117 { 00118 return buildUser; 00119 } 00120 00121 string Version::getBuildHost() const 00122 { 00123 return buildHost; 00124 } 00125 00126 wns::module::Release 00127 Version::getBuildRelease() const 00128 { 00129 return buildRelease; 00130 } 00131 00132 string Version::getBuildFlags() const 00133 { 00134 return buildFlags; 00135 } 00136 00137 wns::module::DateTime 00138 Version::getModificationTime() const 00139 { 00140 return modificationTime; 00141 } 00142 00143 string Version::getModifiedFile() const 00144 { 00145 return modifiedFile; 00146 } 00147 00148 void Version::setBuildTime(const DateTime bTime) 00149 { 00150 buildTime = bTime; 00151 } 00152 00153 void Version::setBuildUser(const string bUser) 00154 { 00155 buildUser = bUser; 00156 } 00157 00158 void Version::setBuildHost(const string bHost) 00159 { 00160 buildHost = bHost; 00161 } 00162 00163 void Version::setBuildRelease(const Release bRelease) 00164 { 00165 buildRelease = bRelease; 00166 } 00167 00168 void Version::setBuildFlags(const string bFlags) 00169 { 00170 buildFlags = bFlags; 00171 } 00172 00173 void Version::setModificationTime(const DateTime mTime) 00174 { 00175 modificationTime = mTime; 00176 } 00177 00178 void Version::setModifiedFile(const string mFile) 00179 { 00180 modifiedFile = mFile; 00181 } 00182 00183 // other public member functions 00184 00185 // return Version as a machine readable string 00186 string Version::getString() const 00187 { 00188 return buildRelease.getString() + "," + buildTime.getString() + "," + 00189 buildUser + "," + buildHost + "," + buildFlags + "," + 00190 modificationTime.getString() + "," + modifiedFile; 00191 } 00192 00193 // return Version as a human readable string 00194 string Version::getNiceString(bool verbose, string offset) const 00195 { 00196 // release 00197 string s = "\033[00;1;32m" + buildRelease.getNiceString() + "\033[00m\n"; 00198 00199 // latest modification 00200 if ((modifiedFile.size() > 0) || 00201 (modificationTime.getString().size() > 0)) 00202 { 00203 s += offset+" +---\033[00;31m latest modification: " + modificationTime.getString() + "\n"; 00204 s += offset+" \033[00m|\033[00;31m " + modifiedFile + "\033[00m\n"; 00205 } 00206 if (verbose) 00207 { 00208 // build ... 00209 if ((buildTime.getString().size() > 0) || 00210 (buildUser.size() > 0) || 00211 (buildHost.size() > 0)) s += offset+" +---\033[00;33m built: "; 00212 // ... time 00213 if (buildTime.getString().size() > 0) s += " " + buildTime.getString(); 00214 s += '\n'; 00215 // ... user 00216 if (buildUser.size() > 0) s += offset+" \033[00m|\033[00;33m by " + buildUser; 00217 // ... host 00218 if (buildHost.size() > 0) s += " on " + buildHost; 00219 if ((buildTime.getString().size() > 0) || 00220 (buildUser.size() > 0) || 00221 (buildHost.size() > 0)) s += "\n"; 00222 00223 // flags 00224 if (buildFlags.size() > 0) 00225 { 00226 s += offset+" \033[00m+---\033[00;35m with flags: " + buildFlags + "\033[00m\n"; 00227 } 00228 } 00229 return s; 00230 } 00231 00232 // private member functions 00233 00235 string Version::cutAt(const string s, const string pattern, const int n) 00236 { 00237 string s2 = s.substr(s.find(pattern) + pattern.length()); 00238 for(int i=1; i<n; i++) { 00239 s2 = s2.substr(s2.find(pattern) + pattern.length()); 00240 } 00241 return s2; 00242 } 00243 00244 // string syntax functions 00245 00246 string Version::Syntax::extractTime(const string s) 00247 { 00248 // the build time is after the first comma 00249 string time = cutAt(s, ",", 1); 00250 // remove all after the time 00251 return time.substr(0, time.find(",")); 00252 } 00253 00254 string Version::Syntax::extractUser(const string s) 00255 { 00256 // the build user is after the second comma 00257 string user = cutAt(s, ",", 2); 00258 // remove all after the user 00259 return user.substr(0, user.find(",")); 00260 } 00261 00262 string Version::Syntax::extractHost(const string s) 00263 { 00264 // the build host is after the third comma 00265 string host = cutAt(s, ",", 3); 00266 return host.substr(0, host.find(",")); 00267 } 00268 00269 string Version::Syntax::extractFlags(const string s) 00270 { 00271 // the build flags are after the fourth comma 00272 string flags = cutAt(s, ",", 4); 00273 return flags.substr(0, flags.find(",")); 00274 } 00275 00276 string Version::Syntax::extractModificationTime(const string s) 00277 { 00278 // the modification time is are after the fifth comma 00279 string mtime = cutAt(s, ",", 5); 00280 return mtime.substr(0, mtime.find(",")); 00281 } 00282 00283 string Version::Syntax::extractModifiedFile(const string s) 00284 { 00285 // the modification time is are after the fifth comma 00286 return cutAt(s, ",", 6); 00287 } 00288 00289 string Version::Syntax::extractRelease(const string s) 00290 { 00291 // the release is before the first comma 00292 return s.substr(0, s.find(",")); 00293 } 00294 00295
1.5.5