The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SWVersion Class Reference

#include <swversion.h>

+ Collaboration diagram for SWVersion:

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 39 of file swversion.h.

Constructor & Destructor Documentation

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

The constructor.

Parameters
versionVersion string to be parsed.

Definition at line 41 of file swversion.cpp.

41  {
42  char *buf = new char[ strlen(version) + 1 ];
43  char *tok;
44  major = minor = minor2 = minor3 = -1;
45 
46  strcpy(buf, version);
47  tok = strtok(buf, ".");
48  if (tok)
49  major = atoi(tok);
50  tok = strtok(0, ".");
51  if (tok)
52  minor = atoi(tok);
53  tok = strtok(0, ".");
54  if (tok)
55  minor2 = atoi(tok);
56  tok = strtok(0, ".");
57  if (tok)
58  minor3 = atoi(tok);
59  delete [] buf;
60 }
int minor3
Definition: swversion.h:43
int minor
Definition: swversion.h:43
int major
Definition: swversion.h:43
int minor2
Definition: swversion.h:43

Member Function Documentation

int SWVersion::compare ( const SWVersion vi) const

Compare 2 Versions with each other.

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

Definition at line 73 of file swversion.cpp.

73  {
74  if (major == vi.major)
75  if (minor == vi.minor)
76  if (minor2 == vi.minor2)
77  if (minor3 == vi.minor3)
78  return 0;
79  else return minor3 - vi.minor3;
80  else return minor2 - vi.minor2;
81  else return minor - vi.minor;
82  else return major - vi.major;
83 }
int minor3
Definition: swversion.h:43
int minor
Definition: swversion.h:43
int major
Definition: swversion.h:43
int minor2
Definition: swversion.h:43
const char * SWVersion::getText ( ) const
Returns
The parsed version number text.

Definition at line 86 of file swversion.cpp.

86  {
87 
88  // 255 is safe because there is no way 4 integers (plus 3 '.'s) can have
89  // a string representation that will overrun this buffer
90  static char buf[255];
91 
92  if (minor > -1) {
93  if (minor2 > -1) {
94  if (minor3 > -1) {
95  sprintf(buf, "%d.%d.%d.%d", major, minor, minor2, minor3);
96  }
97  else sprintf(buf, "%d.%d.%d", major, minor, minor2);
98  }
99  else sprintf(buf, "%d.%d", major, minor);
100  }
101  else sprintf(buf, "%d", major);
102 
103  return buf;
104 }
int minor3
Definition: swversion.h:43
int minor
Definition: swversion.h:43
int major
Definition: swversion.h:43
int minor2
Definition: swversion.h:43
SWVersion::operator const char * ( ) const
inline
Returns
The parsed version number text.

Definition at line 58 of file swversion.h.

58 { return getText(); }
const char * getText() const
Definition: swversion.cpp:86
bool SWVersion::operator< ( const SWVersion vi) const
inline

Definition at line 60 of file swversion.h.

60 {return (compare(vi) < 0);}
int compare(const SWVersion &vi) const
Definition: swversion.cpp:73
bool SWVersion::operator<= ( const SWVersion vi) const
inline

Definition at line 62 of file swversion.h.

62 {return (compare(vi) <= 0);}
int compare(const SWVersion &vi) const
Definition: swversion.cpp:73
bool SWVersion::operator== ( const SWVersion vi) const
inline

Definition at line 63 of file swversion.h.

63 {return (compare(vi) == 0);}
int compare(const SWVersion &vi) const
Definition: swversion.cpp:73
bool SWVersion::operator> ( const SWVersion vi) const
inline

Definition at line 59 of file swversion.h.

59 {return (compare(vi) > 0);}
int compare(const SWVersion &vi) const
Definition: swversion.cpp:73
bool SWVersion::operator>= ( const SWVersion vi) const
inline

Definition at line 61 of file swversion.h.

61 {return (compare(vi) >= 0);}
int compare(const SWVersion &vi) const
Definition: swversion.cpp:73

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 69 of file swversion.h.

int SWVersion::major

The different version subnumbers.

Definition at line 43 of file swversion.h.

int SWVersion::minor

Definition at line 43 of file swversion.h.

int SWVersion::minor2

Definition at line 43 of file swversion.h.

int SWVersion::minor3

Definition at line 43 of file swversion.h.


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