DeviceAccessMode.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. //-----------------------------------------------------------------------------
  2. // Basler pylon SDK
  3. // Copyright (c) 2006-2021 Basler AG
  4. // http://www.baslerweb.com
  5. // Author: Hartmut Nebelung
  6. //-----------------------------------------------------------------------------
  7. /*!
  8. \file
  9. \brief Definition of Device Access Mode
  10. */
  11. #ifndef INCLUDED_DEVICEACCESSMODE_H_6600916
  12. #define INCLUDED_DEVICEACCESSMODE_H_6600916
  13. #include <pylon/PylonBase.h>
  14. #include <pylon/PylonVersionNumber.h>
  15. #ifdef _MSC_VER
  16. # pragma pack(push, PYLON_PACKING)
  17. #endif /* _MSC_VER */
  18. #include <string>
  19. #include <iomanip>
  20. namespace Pylon
  21. {
  22. // --------------------------------------------------------------------------
  23. // enum EDeviceAccessMode
  24. // --------------------------------------------------------------------------
  25. /// The available access modes when opening a camera object
  26. /*!
  27. \ingroup Pylon_TransportLayer
  28. */
  29. enum EDeviceAccessMode
  30. {
  31. Control = 0x1, //!< access the control and status registers
  32. Stream = 0x3, //!< access a streaming data channel
  33. Event = 0x4, //!< access the event data channel
  34. Exclusive = 0x5, //!< exclusive access to the device
  35. _NumModes
  36. };
  37. // --------------------------------------------------------------------------
  38. // class AccessModeSet
  39. // --------------------------------------------------------------------------
  40. /// Collection of access mode bits
  41. /*!
  42. Used for defining how a device is accessed.
  43. \par Low Level API:
  44. This set is used when a device is opened. The combination of
  45. different access modes specifies how the device is opened.
  46. Not all combinations may be allowed because the
  47. device implementations have certain restrictions.
  48. \code
  49. AccessModeSet a = Exclusive | Stream;
  50. if (a.test( Exclusive ))
  51. {
  52. // Exclusive implies Control access, so set it also
  53. a |= Control;
  54. }
  55. \endcode
  56. \sa The method of IDevice::Open() uses it to define a default value.
  57. \sa The global operator |( EDeviceAccessMode lhs, EDeviceAccessMode rhs ) allows to combine
  58. two modes to a set.
  59. \ingroup Pylon_TransportLayer
  60. */
  61. class PYLONBASE_API AccessModeSet
  62. {
  63. public:
  64. /// Default constructor creates an empty set.
  65. AccessModeSet( void );
  66. /// Converts an access mode into a set.
  67. AccessModeSet( EDeviceAccessMode am );
  68. /// Copy constructor
  69. AccessModeSet( const AccessModeSet& ams );
  70. ///
  71. explicit AccessModeSet( unsigned long l );
  72. // Destructor
  73. ~AccessModeSet();
  74. /*!
  75. \brief Sets the bit at position pos.
  76. \param pos Order position of the bit whose value is modified. Order positions are counted from the rightmost bit, which is order position 0.
  77. \ingroup Pylon_TransportLayer
  78. \return *this
  79. */
  80. AccessModeSet& set( size_t pos );
  81. /*!
  82. \brief Resets all bits to zero
  83. \return *this
  84. \ingroup Pylon_TransportLayer
  85. */
  86. AccessModeSet& reset();
  87. /*!
  88. \brief Returns whether any of the bits is set (i.e., whether at least one bit in the AccessModeSet is set to one).
  89. \returns true if any of the bits in the AccessModeSet is set (to one), and false otherwise.
  90. \ingroup Pylon_TransportLayer
  91. */
  92. bool any() const;
  93. /*!
  94. \brief Returns whether any of the bits is set (i.e., whether at least one bit in the AccessModeSet is set to one).
  95. \returns true if any of the bits in the AccessModeSet is set (to one), and false otherwise.
  96. \ingroup Pylon_TransportLayer
  97. */
  98. bool none() const;
  99. /*!
  100. \brief Returns whether the bit at position pos is set (i.e., whether it is one).
  101. \param pos Order position of the bit whose value is modified. Order positions are counted from the rightmost bit, which is order position 0.
  102. \returns true if the bit at position pos is set, and false if it is not set.
  103. \ingroup Pylon_TransportLayer
  104. */
  105. bool test( size_t pos ) const;
  106. /*!
  107. \brief Returns an unsigned long with the integer value that has the same bits set as the AccessModeSet.
  108. \returns Integer value with the same bit representation as the AccessModeSet object.
  109. \ingroup Pylon_TransportLayer
  110. */
  111. unsigned long to_ulong() const;
  112. private:
  113. unsigned long mBits;
  114. };
  115. // -------------------------------------------------------------------------
  116. // Access mode operators
  117. // -------------------------------------------------------------------------
  118. /*!
  119. \brief Creates a set containing lhs and rhs operands
  120. \param lhs left operand
  121. \param rhs right operand
  122. \return returns an AccessModeSet containing both operands
  123. \ingroup Pylon_TransportLayer
  124. */
  125. AccessModeSet PYLONBASE_API operator+( EDeviceAccessMode lhs, EDeviceAccessMode rhs );
  126. /*!
  127. \brief Creates a set containing lhs and rhs operands.
  128. \param lhs left operand
  129. \param rhs right operand
  130. \ingroup Pylon_TransportLayer
  131. */
  132. AccessModeSet PYLONBASE_API operator|( EDeviceAccessMode lhs, EDeviceAccessMode rhs );
  133. /*!
  134. \brief Adds the operand rhs to the set lhs
  135. \param lhs a set of bits.
  136. \param rhs the additional bit
  137. \ingroup Pylon_TransportLayer
  138. */
  139. AccessModeSet PYLONBASE_API operator+( const AccessModeSet& lhs, EDeviceAccessMode rhs );
  140. /*!
  141. \brief Adds the operand rhs to the set lhs
  142. \param lhs a set of bits.
  143. \param rhs the additional bit
  144. \ingroup Pylon_TransportLayer
  145. */
  146. AccessModeSet PYLONBASE_API operator|( const AccessModeSet& lhs, EDeviceAccessMode rhs );
  147. /*!
  148. \brief Check if the operand rhs is equal to lhs
  149. \param lhs a set of bits.
  150. \param rhs the additional set of bits.
  151. \ingroup Pylon_TransportLayer
  152. */
  153. bool PYLONBASE_API operator==( const AccessModeSet& lhs, const AccessModeSet& rhs );
  154. /*!
  155. \brief Check if the operand rhs is not equal to lhs
  156. \param lhs a set of bits.
  157. \param rhs the additional set of bits.
  158. \ingroup Pylon_TransportLayer
  159. */
  160. bool PYLONBASE_API operator!=( const AccessModeSet& lhs, const AccessModeSet& rhs );
  161. // -------------------------------------------------------------------------
  162. // STL output operators
  163. // -------------------------------------------------------------------------
  164. //! STL operator out
  165. //! \ingroup Pylon_TransportLayer
  166. inline std::ostream& operator <<( std::ostream& ostr, const Pylon::AccessModeSet& ams )
  167. {
  168. // use formatted output operator of std::string
  169. ostr << "0x"
  170. << std::setfill( '0' ) << std::setw( sizeof( unsigned long ) * 2 )
  171. << std::hex << ams.to_ulong();
  172. return ostr;
  173. }
  174. #ifdef _MSC_VER
  175. # pragma pack(pop)
  176. #endif /* _MSC_VER */
  177. }
  178. #endif /* INCLUDED_DEVICEACCESSMODE_H_6600916 */