SWVersion Class Reference

#include <swversion.h>

Collaboration diagram for SWVersion:
Collaboration graph
[legend]

List of all members.

Public Member Functions

int compare (const SWVersion &vi) const
const char * getText () const
 operator const char * () const
bool operator< (const SWVersion &vi) const
bool operator<= (const SWVersion &vi) const
bool operator== (const SWVersion &vi) const
bool operator> (const SWVersion &vi) const
bool operator>= (const SWVersion &vi) const
 SWVersion (const char *version="0.0")

Public Attributes

int major
int minor
int minor2
int minor3

Static Public Attributes

static SWVersion currentVersion

Detailed Description

A basic tool class to handle program version numbers.

Definition at line 30 of file swversion.h.


Constructor & Destructor Documentation

SWVersion::SWVersion ( const char *  version = "0.0"  ) 

The constructor.

Parameters:
version Version string to be parsed.

Definition at line 35 of file swversion.cpp.

00035                                         {
00036     char *buf = new char[ strlen(version) + 1 ];
00037     char *tok;
00038     major = minor = minor2 = minor3 = -1;
00039         
00040     strcpy(buf, version);
00041     tok = strtok(buf, ".");
00042     if (tok)
00043         major = atoi(tok);
00044     tok = strtok(0, ".");
00045     if (tok)
00046         minor = atoi(tok);
00047     tok = strtok(0, ".");
00048     if (tok)
00049         minor2 = atoi(tok);
00050     tok = strtok(0, ".");
00051     if (tok)
00052         minor3 = atoi(tok);
00053     delete [] buf;
00054 }


Member Function Documentation

int SWVersion::compare ( const SWVersion vi  )  const

Compare 2 Versions with each other.

Parameters:
vi Version number to compare with.
Returns:
>0:this>vi; 0:this==vi; <0:this<vi

Definition at line 67 of file swversion.cpp.

00067                                                 {
00068     if (major == vi.major)
00069         if (minor == vi.minor)
00070             if (minor2 == vi.minor2)
00071                 if (minor3 == vi.minor3)
00072                     return 0;
00073                 else return minor3 - vi.minor3;
00074             else    return minor2 - vi.minor2;
00075         else    return minor - vi.minor;
00076     else    return major - vi.major;
00077 }

const char * SWVersion::getText (  )  const
Returns:
The parsed version number text.

Definition at line 80 of file swversion.cpp.

00080                                      {
00081 
00082     // 255 is safe because there is no way 4 integers (plus 3 '.'s) can have
00083     // a string representation that will overrun this buffer
00084     static char buf[255];
00085 
00086     if (minor > -1) {
00087         if (minor2 > -1) {
00088             if (minor3 > -1) {
00089                 sprintf(buf, "%d.%d.%d.%d", major, minor, minor2, minor3);
00090             }
00091             else    sprintf(buf, "%d.%d.%d", major, minor, minor2);
00092         }
00093         else    sprintf(buf, "%d.%d", major, minor);
00094     }
00095     else    sprintf(buf, "%d", major);
00096 
00097     return buf;
00098 }

SWVersion::operator const char * (  )  const [inline]
Returns:
The parsed version number text.

Definition at line 49 of file swversion.h.

00049 { return getText(); }

bool SWVersion::operator< ( const SWVersion vi  )  const [inline]

Definition at line 51 of file swversion.h.

00051 {return (compare(vi) < 0);}

bool SWVersion::operator<= ( const SWVersion vi  )  const [inline]

Definition at line 53 of file swversion.h.

00053 {return (compare(vi) <= 0);}

bool SWVersion::operator== ( const SWVersion vi  )  const [inline]

Definition at line 54 of file swversion.h.

00054 {return (compare(vi) == 0);}

bool SWVersion::operator> ( const SWVersion vi  )  const [inline]

Definition at line 50 of file swversion.h.

00050 {return (compare(vi) > 0);}

bool SWVersion::operator>= ( const SWVersion vi  )  const [inline]

Definition at line 52 of file swversion.h.

00052 {return (compare(vi) >= 0);}


Member Data Documentation

SWORD_NAMESPACE_START SWVersion SWVersion::currentVersion [static]

Current sword library version. Use this to check (e.g. at compile time) if the version of the sword lib is recent enough for your program.

Definition at line 60 of file swversion.h.

The different version subnumbers.

Definition at line 34 of file swversion.h.

Definition at line 34 of file swversion.h.

Definition at line 34 of file swversion.h.

Definition at line 34 of file swversion.h.


The documentation for this class was generated from the following files:

Generated on 18 Mar 2013 for The SWORD Project by  doxygen 1.6.1