GrabResultPtr.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. //-----------------------------------------------------------------------------
  2. // Basler pylon SDK
  3. // Copyright (c) 2010-2021 Basler AG
  4. // http://www.baslerweb.com
  5. // Author: Andreas Gau
  6. //-----------------------------------------------------------------------------
  7. /*!
  8. \file
  9. \brief Contains a smart pointer that holds a reference to grab result data.
  10. */
  11. #ifndef INCLUDED_GRABRESULTPTR_H_4356898
  12. #define INCLUDED_GRABRESULTPTR_H_4356898
  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. #include <pylon/GrabResultData.h>
  19. #include <pylon/Image.h>
  20. namespace Pylon
  21. {
  22. namespace PylonPrivate
  23. {
  24. class CGrabResultDataConverter;
  25. }
  26. /** \addtogroup Pylon_InstantCameraApiGeneric
  27. * @{
  28. */
  29. /*!
  30. \class CGrabResultPtr
  31. \brief A smart pointer holding a reference to grab result data.
  32. This class is used for distributing the grab result data of a camera. It controls
  33. the reuse and lifetime of the referenced buffer. When all smart pointers referencing
  34. a buffer go out of scope the referenced buffer is reused or destroyed.
  35. The data and the held buffer are still valid after the camera object it originated from
  36. has been destroyed.
  37. \attention The grabbing will stop with an input queue underrun, when the grab results are
  38. never released, e.g. when put into a container.
  39. The CGrabResultPtr class provides a cast operator that allows passing the grab result directly to functions or methods
  40. that take an const IImage& as parameter, e.g. image saving functions or image format converter methods.
  41. \attention The returned reference to IImage is only valid as long the CGrabResultPtr object it came from is not destroyed.
  42. \threading Instances of CGrabResultPtr referencing the same grab result can be used from any thread context.
  43. */
  44. class PYLONBASE_API CGrabResultPtr
  45. {
  46. public:
  47. /*!
  48. \brief Creates a smart pointer.
  49. \post No grab result is referenced.
  50. */
  51. CGrabResultPtr();
  52. /*!
  53. \brief Creates a copy of a smart pointer.
  54. \param[in] rhs Another smart pointer, source of the result data to reference.
  55. The data itself is not copied.
  56. \post
  57. <ul>
  58. <li>Another reference to the grab result of the source is held if it references a grab result.
  59. <li>No grab result is referenced if the source does not reference a grab result.
  60. </ul>
  61. \error
  62. Still valid after error.
  63. */
  64. CGrabResultPtr( const CGrabResultPtr& rhs );
  65. /*!
  66. \brief Assignment of a smart pointer.
  67. \param[in] rhs Another smart pointer, source of the result data to reference.
  68. The data itself is not copied.
  69. \post
  70. <ul>
  71. <li>The currently referenced data is released.
  72. <li>Another reference to the grab result of the source is held if it references a grab result.
  73. <li>No grab result is referenced if the source does not reference a grab result.
  74. </ul>
  75. \error
  76. Still valid after error.
  77. */
  78. CGrabResultPtr& operator = ( const CGrabResultPtr& rhs );
  79. /*!
  80. \brief Destroys the smart pointer.
  81. \post The currently referenced data is released.
  82. \error
  83. Does not throw C++ exceptions.
  84. */
  85. ~CGrabResultPtr();
  86. /*!
  87. \brief Allows accessing the referenced data.
  88. \return The pointer to the grab result data.
  89. \pre The pointer must reference a grab result.
  90. IsValid() or the overloaded bool operator can be used to check whether data is referenced.
  91. \error
  92. Still valid after error. Throws an exception when no data is referenced.
  93. */
  94. CGrabResultData* operator->() const;
  95. /*!
  96. \brief Check whether data is referenced.
  97. \return True if data is referenced.
  98. \error
  99. Does not throw C++ exceptions.
  100. */
  101. bool IsValid() const;
  102. /*!
  103. \brief Check whether data is referenced.
  104. \return IsValid().
  105. The overloaded bool operator can be used to check whether data is referenced.
  106. Example:
  107. \code
  108. if ( grabResult)
  109. {
  110. grabResult->GetStatus();
  111. }
  112. \endcode
  113. \error
  114. Does not throw C++ exceptions.
  115. */
  116. operator bool() const;
  117. /*!
  118. \brief The currently referenced data is released.
  119. \post The currently referenced data is released.
  120. \error
  121. Still valid after error.
  122. */
  123. void Release();
  124. /*!
  125. \brief Provides an IImage interface to the grab result.
  126. This cast operator allows passing the grab result to saving functions or image format converter.
  127. The returned image is invalid if the grab was not successful, see CGrabResultData::GrabSucceeded().
  128. \attention The returned reference is only valid as long the grab result ptr is not destroyed.
  129. \error
  130. Still valid after error.
  131. */
  132. operator IImage& () const;
  133. /*!
  134. \brief Indicates that the held grab result data and buffer is only referenced by this grab result.
  135. \return Returns true if the held grab result data and buffer is only referenced by this grab result. Returns false if the grab result is invalid.
  136. \error
  137. Does not throw C++ exceptions.
  138. */
  139. bool IsUnique() const;
  140. /// Internal use only.
  141. class CGrabResultPtrImpl;
  142. CGrabResultPtr& operator = ( const CGrabResultPtrImpl& rhs );
  143. private:
  144. /// Internal use only.
  145. friend class PylonPrivate::CGrabResultDataConverter;
  146. CGrabResultData* GetPtr() const;
  147. mutable CGrabResultPtrImpl* m_pImpl;
  148. CGrabResultData* m_pGrabResultData;
  149. };
  150. /**
  151. * @}
  152. */
  153. }
  154. #ifdef _MSC_VER
  155. # pragma pack(pop)
  156. #endif /* _MSC_VER */
  157. #endif /* INCLUDED_GRABRESULTPTR_H_4356898 */