Jpp  debug
the software that should make you happy
Public Types | Public Member Functions | Static Public Attributes | Protected Attributes | Friends | List of all members
JEEP::JVersion Struct Reference

Auxiliary data structure for general purpose version number. More...

#include <JVersion.hh>

Inheritance diagram for JEEP::JVersion:
JLANG::JComparable< JFirst_t, JSecond_t >

Public Types

typedef unsigned int version_type
 Type definition of [sub-]versions. More...
 

Public Member Functions

 JVersion ()
 Default constructor. More...
 
 JVersion (const version_type major, const version_type minor, const version_type patch)
 Constructor. More...
 
 JVersion (const std::string &version)
 Constructor. More...
 
version_type getMajorVersion () const
 Get major version. More...
 
version_type getMinorVersion () const
 Get minor version. More...
 
version_type getPatchVersion () const
 Get patch version. More...
 
bool less (const JVersion &version) const
 Compare version. More...
 
std::string toString () const
 Convert version to string. More...
 

Static Public Attributes

static const char SEPARATOR = '.'
 Separator between [sub-]versions. More...
 

Protected Attributes

version_type majorVersion
 major version More...
 
version_type minorVersion
 minor version More...
 
version_type patchVersion
 patch version More...
 

Friends

std::istream & operator>> (std::istream &in, JVersion &object)
 Read version from input stream. More...
 
std::ostream & operator<< (std::ostream &out, const JVersion &object)
 Write version to output stream. More...
 

Detailed Description

Auxiliary data structure for general purpose version number.

A version consists of a major, minor and patch number.
The I/O format is <major>.<minor>.<patch>.

Definition at line 28 of file Jeep/JVersion.hh.

Member Typedef Documentation

◆ version_type

typedef unsigned int JEEP::JVersion::version_type

Type definition of [sub-]versions.

Definition at line 34 of file Jeep/JVersion.hh.

Constructor & Destructor Documentation

◆ JVersion() [1/3]

JEEP::JVersion::JVersion ( )
inline

Default constructor.

Definition at line 46 of file Jeep/JVersion.hh.

46  :
47  majorVersion(0),
48  minorVersion(0),
49  patchVersion(0)
50  {}
version_type majorVersion
major version
version_type patchVersion
patch version
version_type minorVersion
minor version

◆ JVersion() [2/3]

JEEP::JVersion::JVersion ( const version_type  major,
const version_type  minor,
const version_type  patch 
)
inline

Constructor.

Parameters
majormajor version
minorminor version
patchpatch version

Definition at line 60 of file Jeep/JVersion.hh.

62  :
63  majorVersion(major),
64  minorVersion(minor),
65  patchVersion(patch)
66  {}

◆ JVersion() [3/3]

JEEP::JVersion::JVersion ( const std::string &  version)
inline

Constructor.

Parameters
versionversion

Definition at line 74 of file Jeep/JVersion.hh.

74  :
75  majorVersion(0),
76  minorVersion(0),
77  patchVersion(0)
78  {
79  std::istringstream is(version);
80 
81  is >> *this;
82  }

Member Function Documentation

◆ getMajorVersion()

version_type JEEP::JVersion::getMajorVersion ( ) const
inline

Get major version.

Returns
major version.

Definition at line 90 of file Jeep/JVersion.hh.

91  {
92  return majorVersion;
93  }

◆ getMinorVersion()

version_type JEEP::JVersion::getMinorVersion ( ) const
inline

Get minor version.

Returns
minor version.

Definition at line 101 of file Jeep/JVersion.hh.

102  {
103  return minorVersion;
104  }

◆ getPatchVersion()

version_type JEEP::JVersion::getPatchVersion ( ) const
inline

Get patch version.

Returns
patch version.

Definition at line 112 of file Jeep/JVersion.hh.

113  {
114  return patchVersion;
115  }

◆ less()

bool JEEP::JVersion::less ( const JVersion version) const
inline

Compare version.

Parameters
versionversion
Returns
true if this version is less than given version; else false

Definition at line 124 of file Jeep/JVersion.hh.

125  {
126  if (this->majorVersion == version.majorVersion) {
127 
128  if (this->minorVersion == version.minorVersion) {
129 
130  return this->patchVersion < version.patchVersion;
131 
132  } else {
133 
134  return this->minorVersion < version.minorVersion;
135  }
136 
137  } else {
138 
139  return this->majorVersion < version.majorVersion;
140  }
141  }

◆ toString()

std::string JEEP::JVersion::toString ( ) const
inline

Convert version to string.

Returns
string

Definition at line 149 of file Jeep/JVersion.hh.

150  {
151  std::ostringstream os;
152 
153  os << *this;
154 
155  return os.str();
156  }

Friends And Related Function Documentation

◆ operator>>

std::istream& operator>> ( std::istream &  in,
JVersion object 
)
friend

Read version from input stream.

Parameters
ininput stream
objectversion
Returns
input stream

Definition at line 166 of file Jeep/JVersion.hh.

167  {
168  using namespace std;
169 
170  version_type version;
171 
172  if (in >> version) {
173  object.majorVersion = version;
174  } else {
175  in.setstate(ios::failbit);
176  }
177 
178  if ((in.peek() == (int) JVersion::SEPARATOR) && (in.ignore() && in >> version)) {
179  object.minorVersion = version;
180  } else {
181  in.setstate(ios::failbit);
182  }
183 
184  if ((in.peek() == (int) JVersion::SEPARATOR) && (in.ignore() && in >> version)) {
185  object.patchVersion = version;
186  } else {
187  in.setstate(ios::failbit);
188  }
189 
190  return in;
191  }
Definition: JSTDTypes.hh:14
static const char SEPARATOR
Separator between [sub-]versions.
unsigned int version_type
Type definition of [sub-]versions.

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const JVersion object 
)
friend

Write version to output stream.

Parameters
outoutput stream
objectversion
Returns
output stream

Definition at line 201 of file Jeep/JVersion.hh.

202  {
203  return out <<
204  object.majorVersion << JVersion::SEPARATOR <<
205  object.minorVersion << JVersion::SEPARATOR <<
206  object.patchVersion;
207  }

Member Data Documentation

◆ SEPARATOR

const char JEEP::JVersion::SEPARATOR = '.'
static

Separator between [sub-]versions.

Definition at line 40 of file Jeep/JVersion.hh.

◆ majorVersion

version_type JEEP::JVersion::majorVersion
protected

major version

Definition at line 211 of file Jeep/JVersion.hh.

◆ minorVersion

version_type JEEP::JVersion::minorVersion
protected

minor version

Definition at line 212 of file Jeep/JVersion.hh.

◆ patchVersion

version_type JEEP::JVersion::patchVersion
protected

patch version

Definition at line 213 of file Jeep/JVersion.hh.


The documentation for this struct was generated from the following file: