<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>swversion.cpp Source File</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.2.15 --> <center> <a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Compound Members</a> </center> <hr><h1>swversion.cpp</h1><div class="fragment"><pre>00001 <font class="preprocessor">#include <swversion.h></font> 00002 <font class="preprocessor">#include <string.h></font> 00003 <font class="preprocessor">#include <stdio.h></font> 00004 <font class="preprocessor">#include <stdlib.h></font> 00005 00006 00007 SWVersion SWVersion::currentVersion(SWORDVER); 00008 00009 <font class="comment">/******************************************************************************</font> 00010 <font class="comment"> * SWVersion c-tor - Constructs a new SWVersion</font> 00011 <font class="comment"> *</font> 00012 <font class="comment"> * ENT: version - const version string</font> 00013 <font class="comment"> */</font> 00014 00015 SWVersion::SWVersion(<font class="keyword">const</font> <font class="keywordtype">char</font> *version) { 00016 <font class="keywordtype">char</font> *buf = <font class="keyword">new</font> <font class="keywordtype">char</font>[ strlen(version) + 1 ]; 00017 <font class="keywordtype">char</font> *tok; 00018 major = minor = minor2 = minor3 = -1; 00019 00020 strcpy(buf, version); 00021 tok = strtok(buf, <font class="stringliteral">"."</font>); 00022 <font class="keywordflow">if</font> (tok) 00023 major = atoi(tok); 00024 tok = strtok(0, <font class="stringliteral">"."</font>); 00025 <font class="keywordflow">if</font> (tok) 00026 minor = atoi(tok); 00027 tok = strtok(0, <font class="stringliteral">"."</font>); 00028 <font class="keywordflow">if</font> (tok) 00029 minor2 = atoi(tok); 00030 tok = strtok(0, <font class="stringliteral">"."</font>); 00031 <font class="keywordflow">if</font> (tok) 00032 minor3 = atoi(tok); 00033 <font class="keyword">delete</font> [] buf; 00034 } 00035 00036 00037 <font class="comment">/******************************************************************************</font> 00038 <font class="comment"> * compare - compares this version to another version</font> 00039 <font class="comment"> *</font> 00040 <font class="comment"> * ENT: vi - other version with which to compare</font> 00041 <font class="comment"> *</font> 00042 <font class="comment"> * RET: = 0 if equal;</font> 00043 <font class="comment"> * < 0 if this version is less than other version;</font> 00044 <font class="comment"> * > 0 if this version is greater than other version</font> 00045 <font class="comment"> */</font> 00046 00047 <font class="keywordtype">int</font> SWVersion::compare(<font class="keyword">const</font> SWVersion &vi)<font class="keyword"> const </font>{ 00048 <font class="keywordflow">if</font> (major == vi.major) 00049 <font class="keywordflow">if</font> (minor == vi.minor) 00050 <font class="keywordflow">if</font> (minor2 == vi.minor2) 00051 <font class="keywordflow">if</font> (minor3 == vi.minor3) 00052 <font class="keywordflow">return</font> 0; 00053 <font class="keywordflow">else</font> <font class="keywordflow">return</font> minor3 - vi.minor3; 00054 <font class="keywordflow">else</font> <font class="keywordflow">return</font> minor2 - vi.minor2; 00055 <font class="keywordflow">else</font> <font class="keywordflow">return</font> minor - vi.minor; 00056 <font class="keywordflow">else</font> <font class="keywordflow">return</font> major - vi.major; 00057 } 00058 00059 00060 SWVersion::operator const char *()<font class="keyword"> const </font>{ 00061 00062 <font class="comment">// 255 is safe because there is no way 4 integers (plus 3 '.'s) can have</font> 00063 <font class="comment">// a string representation that will overrun this buffer</font> 00064 <font class="keyword">static</font> <font class="keywordtype">char</font> buf[255]; 00065 00066 <font class="keywordflow">if</font> (minor > -1) { 00067 <font class="keywordflow">if</font> (minor2 > -1) { 00068 <font class="keywordflow">if</font> (minor3 > -1) { 00069 sprintf(buf, <font class="stringliteral">"%d.%d.%d.%d"</font>, major, minor, minor2, minor3); 00070 } 00071 <font class="keywordflow">else</font> sprintf(buf, <font class="stringliteral">"%d.%d.%d"</font>, major, minor, minor2); 00072 } 00073 <font class="keywordflow">else</font> sprintf(buf, <font class="stringliteral">"%d.%d"</font>, major, minor); 00074 } 00075 <font class="keywordflow">else</font> sprintf(buf, <font class="stringliteral">"%d"</font>, major); 00076 00077 <font class="keywordflow">return</font> buf; 00078 } </pre></div><hr><address align="right"><small>Generated on Thu Jun 20 22:13:00 2002 for The Sword Project by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border=0 width=110 height=53></a>1.2.15 </small></address> </body> </html>