PylonVersionInfo.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. //-----------------------------------------------------------------------------
  2. // Basler pylon SDK
  3. // Copyright (c) 2009-2021 Basler AG
  4. // http://www.baslerweb.com
  5. // Author: JS
  6. //-----------------------------------------------------------------------------
  7. /*!
  8. \file
  9. \brief Contains the VersionInfo class, which is a utility for comparing version numbers.
  10. */
  11. #ifndef INCLUDED_PYLONVERSIONINFO_H_3453485
  12. #define INCLUDED_PYLONVERSIONINFO_H_3453485
  13. #include <pylon/Platform.h>
  14. #ifdef _MSC_VER
  15. # pragma pack(push, PYLON_PACKING)
  16. #endif /* _MSC_VER */
  17. #include <pylon/PylonBase.h>
  18. namespace Pylon
  19. {
  20. /**
  21. \class VersionInfo
  22. \brief Holds a four-part version number consisting of major.minor.subminor.build
  23. This class stores a four-part version number and provides comparison operators.
  24. If you use the constructor with one parameter, the version info object will be
  25. initialized with pylon base version numbers.
  26. You can also call the static getVersionString() method to retrieve
  27. a string containing the complete version separated by dots.
  28. */
  29. class VersionInfo
  30. {
  31. public:
  32. /// Constructs a version info object using pylon base version numbers.
  33. /// If checkBuild is set to false, the build number will not be used in comparison operators.
  34. explicit VersionInfo( bool checkBuild = false )
  35. : m_major( 0 )
  36. , m_minor( 0 )
  37. , m_subminor( 0 )
  38. , m_build( 0 )
  39. , m_checkBuild( checkBuild )
  40. {
  41. Pylon::GetPylonVersion( &m_major, &m_minor, &m_subminor, &m_build );
  42. }
  43. /// Constructs a version info object using the version number parts passed.
  44. VersionInfo( unsigned int major,
  45. unsigned int minor,
  46. unsigned int subminor )
  47. : m_major( major )
  48. , m_minor( minor )
  49. , m_subminor( subminor )
  50. , m_build( 0 )
  51. , m_checkBuild( false )
  52. {
  53. }
  54. /// Constructs a version info object using the version number parts passed.
  55. VersionInfo( unsigned int major,
  56. unsigned int minor,
  57. unsigned int subminor,
  58. unsigned int build )
  59. : m_major( major )
  60. , m_minor( minor )
  61. , m_subminor( subminor )
  62. , m_build( build )
  63. , m_checkBuild( true )
  64. {
  65. }
  66. /// The VersionInfo destructor.
  67. ~VersionInfo( void )
  68. {
  69. }
  70. public:
  71. /// Returns the complete version number as a string.
  72. static const char* getVersionString()
  73. {
  74. return Pylon::GetPylonVersionString();
  75. }
  76. /// Returns the major version number.
  77. /// For version 2.1.3.1234 the value 2 would be returned.
  78. unsigned int getMajor() const
  79. {
  80. return m_major;
  81. }
  82. /// Returns the minor version number.
  83. /// For version 2.1.3.1234 the value 1 would be returned.
  84. unsigned int getMinor() const
  85. {
  86. return m_minor;
  87. }
  88. /// Returns the subminor version number.
  89. /// For version 2.1.3.1234 the value 3 would be returned.
  90. unsigned int getSubminor() const
  91. {
  92. return m_subminor;
  93. }
  94. /// Returns the build number.
  95. /// For version 2.1.3.1234 the value 1234 would be returned.
  96. unsigned int getBuild() const
  97. {
  98. return m_build;
  99. }
  100. public:
  101. /// Compares two version info objects.
  102. bool operator > ( const VersionInfo& rhs ) const
  103. {
  104. bool res = (m_major > rhs.m_major)
  105. || (m_major == rhs.m_major && m_minor > rhs.m_minor)
  106. || (m_major == rhs.m_major && m_minor == rhs.m_minor && m_subminor > rhs.m_subminor)
  107. || (m_major == rhs.m_major && m_minor == rhs.m_minor && m_subminor == rhs.m_subminor && m_checkBuild && m_build > rhs.m_build);
  108. return res;
  109. }
  110. /// Compares two version info objects.
  111. bool operator == ( const VersionInfo& rhs ) const
  112. {
  113. // use the reverse order to save some executiontime ;-)
  114. bool res( (m_checkBuild ? (m_build == rhs.m_build) : true)
  115. && (m_subminor == rhs.m_subminor)
  116. && (m_minor == rhs.m_minor)
  117. && (m_major == rhs.m_major) );
  118. return res;
  119. }
  120. /// Compares two version info objects.
  121. bool operator >= ( const VersionInfo& rhs ) const
  122. {
  123. bool res = (*this > rhs) || (*this == rhs);
  124. return res;
  125. }
  126. /// Compares two version info objects.
  127. bool operator < ( const VersionInfo& rhs ) const
  128. {
  129. bool res = !(*this >= rhs);
  130. return res;
  131. }
  132. /// Compares two version info objects.
  133. bool operator != ( const VersionInfo& rhs ) const
  134. {
  135. bool res = !(*this == rhs);
  136. return res;
  137. }
  138. /// compares two version info objects.
  139. bool operator <= ( const VersionInfo& rhs ) const
  140. {
  141. bool res = !(*this > rhs);
  142. return res;
  143. }
  144. protected:
  145. unsigned int m_major;
  146. unsigned int m_minor;
  147. unsigned int m_subminor;
  148. unsigned int m_build;
  149. bool m_checkBuild;
  150. };
  151. }
  152. #ifdef _MSC_VER
  153. # pragma pack(pop)
  154. #endif /* _MSC_VER */
  155. #endif /* INCLUDED_PYLONVERSIONINFO_H_3453485 */