Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

swversion.cpp

00001 #include <swversion.h>
00002 #include <string.h>
00003 #include <stdio.h>
00004 #include <stdlib.h>
00005 
00006 
00007 SWVersion SWVersion::currentVersion(SWORDVER);
00008 
00009 /******************************************************************************
00010  * SWVersion c-tor - Constructs a new SWVersion
00011  *
00012  * ENT: version - const version string
00013  */
00014 
00015 SWVersion::SWVersion(const char *version) {
00016         char *buf = new char[ strlen(version) + 1 ];
00017         char *tok;
00018         major = minor = minor2 = minor3 = -1;
00019                 
00020         strcpy(buf, version);
00021         tok = strtok(buf, ".");
00022         if (tok)
00023                 major = atoi(tok);
00024         tok = strtok(0, ".");
00025         if (tok)
00026                 minor = atoi(tok);
00027         tok = strtok(0, ".");
00028         if (tok)
00029                 minor2 = atoi(tok);
00030         tok = strtok(0, ".");
00031         if (tok)
00032                 minor3 = atoi(tok);
00033         delete [] buf;
00034 }
00035 
00036 
00037 /******************************************************************************
00038  * compare - compares this version to another version
00039  *
00040  * ENT: vi      - other version with which to compare
00041  *
00042  * RET: = 0 if equal;
00043  *              < 0 if this version is less than other version;
00044  *              > 0 if this version is greater than other version
00045  */
00046 
00047 int SWVersion::compare(const SWVersion &vi) const {
00048         if (major == vi.major)
00049                 if (minor == vi.minor)
00050                         if (minor2 == vi.minor2)
00051                                 if (minor3 == vi.minor3)
00052                                         return 0;
00053                                 else return minor3 - vi.minor3;
00054                         else    return minor2 - vi.minor2;
00055                 else    return minor - vi.minor;
00056         else    return major - vi.major;
00057 }
00058 
00059 
00060 SWVersion::operator const char *() const {
00061 
00062         // 255 is safe because there is no way 4 integers (plus 3 '.'s) can have
00063         // a string representation that will overrun this buffer
00064         static char buf[255];
00065 
00066         if (minor > -1) {
00067                 if (minor2 > -1) {
00068                         if (minor3 > -1) {
00069                                 sprintf(buf, "%d.%d.%d.%d", major, minor, minor2, minor3);
00070                         }
00071                         else    sprintf(buf, "%d.%d.%d", major, minor, minor2);
00072                 }
00073                 else    sprintf(buf, "%d.%d", major, minor);
00074         }
00075         else    sprintf(buf, "%d", major);
00076 
00077         return buf;
00078 }

Generated on Thu Jun 20 22:13:00 2002 for The Sword Project by doxygen1.2.15