BooleanParameter.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. //------------------------------------------------------------------------------
  2. // Basler pylon SDK
  3. // Copyright (c) 2018-2021 Basler AG
  4. // http://www.baslerweb.com
  5. //------------------------------------------------------------------------------
  6. /*!
  7. \file
  8. \brief Contains the class CBooleanParameter used to simplify access to %GenApi parameters.
  9. */
  10. #ifndef INCLUDED_BASLER_PYLON_CBOOLEANPARAMETER_H
  11. #define INCLUDED_BASLER_PYLON_CBOOLEANPARAMETER_H
  12. #pragma once
  13. #include <pylon/PylonBase.h>
  14. #include <GenApi/IBoolean.h>
  15. #include <pylon/Parameter.h>
  16. #ifdef _MSC_VER
  17. # pragma pack(push, PYLON_PACKING)
  18. #endif /* _MSC_VER */
  19. #ifdef _MSC_VER
  20. # pragma warning( push )
  21. # pragma warning( disable : 4275 ) // Class needs to have a dll interface to be used by clients of the class.
  22. # pragma warning( disable : 4250 ) // warning C4250: 'Pylon::CXYZParameter': inherits 'Pylon::CParameter::Pylon::CParameter::ZYX' via dominance
  23. #endif
  24. namespace Pylon
  25. {
  26. /*!
  27. \brief Extends the GenApi::IBoolean interface with convenience methods.
  28. */
  29. interface IBooleanEx : virtual public GenApi::IBoolean, virtual public IValueEx
  30. {
  31. using GenApi::IBoolean::operator=;
  32. /*!
  33. \brief Sets the Boolean value of the parameter if the parameter is writable.
  34. \return Returns false if the parameter is not writable.
  35. \param[in] value The Boolean value to set.
  36. \threading
  37. The method accesses the parameter multiple times. These accesses are not synchronized by a lock.
  38. \error
  39. Can throw exceptions if the preconditions are not met or if writing the value fails.
  40. */
  41. virtual bool TrySetValue( bool value ) = 0;
  42. /*!
  43. \brief Gets the Boolean value of the parameter if the parameter is readable.
  44. \brief Otherwise returns the default value.
  45. \return Returns the parameter value if the parameter is readable. Otherwise returns the default value.
  46. \param[in] defaultValue The default value returned if the parameter is not readable.
  47. \threading
  48. The method accesses the parameter multiple times. These accesses are not synchronized by a lock.
  49. \error
  50. Can throw exceptions if reading the value fails.
  51. */
  52. virtual bool GetValueOrDefault( bool defaultValue ) = 0;
  53. };
  54. /*!
  55. \brief CBooleanParameter class used to simplify access to %GenApi parameters.
  56. */
  57. class PYLONBASE_API CBooleanParameter : public IBooleanEx, public CParameter
  58. {
  59. public:
  60. /*!
  61. \brief Creates an empty CBooleanParameter object.
  62. \error
  63. Does not throw C++ exceptions.
  64. */
  65. CBooleanParameter();
  66. /*!
  67. \brief Creates a CBooleanParameter object and attaches it to a node, typically retrieved for a nodemap calling GetNode().
  68. \param[in] pNode The node to attach.
  69. \post
  70. <ul>
  71. <li>If the passed node does not match the parameter type, the parameter will be empty, see IsValid().
  72. <li>If the passed node does match the parameter type, it is attached and the parameter object can be used to access the node's functionality.
  73. <li>The parameter object must not be used to access the node's functionality if the source of the attached \c pNode has been destroyed. In this case, call Release() or attach a new node.
  74. </ul>
  75. \error
  76. Does not throw C++ exceptions.
  77. */
  78. explicit CBooleanParameter( GenApi::INode* pNode );
  79. /*!
  80. \brief Creates a CBooleanParameter object and attaches it to a node of a matching type.
  81. \param[in] pBoolean The node to attach.
  82. \post
  83. The parameter object must not be used to access the node's functionality if the source of the attached \c pBoolean has been destroyed. In this case, call Release() or attach a new node.
  84. \error
  85. Does not throw C++ exceptions.
  86. */
  87. explicit CBooleanParameter( GenApi::IBoolean* pBoolean );
  88. /*!
  89. \brief Creates a CBooleanParameter object and attaches it to a node retrieved from the provided node map.
  90. \param[in] pNodeMap The node map. The source of the parameter.
  91. \param[in] pName The name of the parameter to attach.
  92. \post
  93. <ul>
  94. <li>If \c pNodeMap or \c name is NULL, the parameter will be empty, see IsValid().
  95. <li>If the node does not match the parameter type, the parameter will be empty, see IsValid().
  96. <li>If the node does match the parameter type, it is attached and the parameter object can be used to access the node's functionality.
  97. <li>The parameter object must not be used to access the node's functionality if the provided node map has been destroyed. In this case, call Release() or attach a new node.
  98. </ul>
  99. \error
  100. The call to GenApi::INodeMap::GetNode can throw C++ exceptions.
  101. */
  102. CBooleanParameter( GenApi::INodeMap* pNodeMap, const char* pName );
  103. /*!
  104. \brief Creates a CBooleanParameter object and attaches it to a node retrieved from the provided node map.
  105. \param[in] nodeMap The node map. The source of the parameter.
  106. \param[in] pName The name of the parameter to attach.
  107. \post
  108. <ul>
  109. <li>If \c name is NULL, the parameter will be empty, see IsValid().
  110. <li>If the node does not match the parameter type, the parameter will be empty, see IsValid().
  111. <li>If the node does match the parameter type, it is attached and the parameter object can be used to access the node's functionality.
  112. <li>The parameter object must not be used to access the node's functionality if the provided node map has been destroyed. In this case, call Release() or attach a new node.
  113. </ul>
  114. \error
  115. The call to GenApi::INodeMap::GetNode can throw C++ exceptions.
  116. */
  117. CBooleanParameter( GenApi::INodeMap& nodeMap, const char* pName );
  118. /*!
  119. \brief Copies a CBooleanParameter object.
  120. \param[in] rhs The object to copy.
  121. \error
  122. Does not throw C++ exceptions.
  123. */
  124. CBooleanParameter( const CBooleanParameter& rhs );
  125. /*!
  126. \brief Destroys the CBooleanParameter object.
  127. Does not access the attached node.
  128. \error
  129. Does not throw C++ exceptions.
  130. */
  131. virtual ~CBooleanParameter();
  132. /*!
  133. \brief Attaches a node retrieved from the provided node map.
  134. \param[in] pNodeMap The node map. The source of the parameter.
  135. \param[in] pName The name of the parameter to attach.
  136. \return Returns true if the node has been attached.
  137. \post
  138. <ul>
  139. <li>If \c pNodeMap or \c name is NULL, the parameter will be empty, see IsValid().
  140. <li>If the node does not match the parameter type, the parameter will be empty, see IsValid().
  141. <li>If the node does match the parameter type, it is attached and the parameter object can be used to access the node's functionality.
  142. <li>The parameter object must not be used to access the node's functionality if the provided node map has been destroyed. In this case, call Release() or attach a new node.
  143. </ul>
  144. \error
  145. The call to GenApi::INodeMap::GetNode can throw C++ exceptions.
  146. */
  147. virtual bool Attach( GenApi::INodeMap* pNodeMap, const char* pName );
  148. /*!
  149. \brief Attaches a node retrieved from the provided node map.
  150. \param[in] nodeMap The node map. The source of the parameter.
  151. \param[in] pName The name of the parameter to attach.
  152. \return Returns true if the node has been attached.
  153. \post
  154. <ul>
  155. <li>If \c name is NULL the parameter will be empty, see IsValid().
  156. <li>If the node does not match the parameter type, the parameter will be empty, see IsValid().
  157. <li>If the node does match the parameter type, it is attached and the parameter object can be used to access the node's functionality.
  158. <li>The parameter object must not be used to access the node's functionality if the provided node map has been destroyed. In this case, call Release() or attach a new node.
  159. </ul>
  160. \error
  161. The call to GenApi::INodeMap::GetNode can throw C++ exceptions.
  162. */
  163. virtual bool Attach( GenApi::INodeMap& nodeMap, const char* pName );
  164. /*!
  165. \brief Attaches a node, typically retrieved for a nodemap calling GetNode().
  166. \param[in] pNode The node to assign.
  167. \return Returns true if the node has been attached.
  168. \post
  169. <ul>
  170. <li>If the node does not match the parameter type, the parameter will be empty, see IsValid().
  171. <li>If the node does match the parameter type, it is attached and the parameter object can be used to access the node's functionality.
  172. <li>The parameter object must not be used to access the node's functionality if the source of the attached \c pNode has been destroyed. In this case, call Release() or attach a new node.
  173. </ul>
  174. \error
  175. Does not throw C++ exceptions.
  176. */
  177. virtual bool Attach( GenApi::INode* pNode );
  178. /*!
  179. \brief Assigns a node of the same type to the parameter object.
  180. \param[in] pBoolean The node to assign.
  181. \return Returns true if the node has been attached.
  182. \error
  183. Does not throw C++ exceptions.
  184. */
  185. virtual bool Attach( GenApi::IBoolean* pBoolean );
  186. /*!
  187. \brief Assigns a CBooleanParameter object.
  188. \param[in] rhs The object to assign.
  189. \error
  190. Does not throw C++ exceptions.
  191. */
  192. CBooleanParameter& operator=( const CBooleanParameter& rhs );
  193. /*!
  194. \brief Returns true if the same nodes are attached or both parameters are empty.
  195. \param[in] rhs The object to compare to.
  196. \return Returns true if the same nodes are attached or both parameters are empty.
  197. \error
  198. Does not throw C++ exceptions.
  199. */
  200. virtual bool Equals( const CBooleanParameter& rhs ) const;
  201. /*!
  202. \brief Returns true if the attached node pointer is equal.
  203. \param[in] pNode The node to compare to.
  204. \return Returns true if the attached node pointer is equal.
  205. \error
  206. Does not throw C++ exceptions.
  207. */
  208. virtual bool Equals( const GenApi::INode* pNode ) const;
  209. /*!
  210. \brief Returns true if the attached node pointer is equal.
  211. \param[in] pBoolean The node to compare to.
  212. \return Returns true if the attached node pointer is equal.
  213. \error
  214. Does not throw C++ exceptions.
  215. */
  216. virtual bool Equals( const GenApi::IBoolean* pBoolean ) const;
  217. /*!
  218. \brief Releases the attached node.
  219. \error
  220. Does not throw C++ exceptions.
  221. */
  222. virtual void Release();
  223. // Implements IValueEx
  224. virtual bool IsValid() const;
  225. // Implements GenApi::IBoolean
  226. virtual void SetValue( bool value, bool verify = true );
  227. // Implements GenApi::IBoolean
  228. virtual void operator=( bool value );
  229. // Implements GenApi::IBoolean
  230. virtual bool GetValue( bool verify = false, bool ignoreCache = false ) const;
  231. // Implements GenApi::IBoolean
  232. virtual bool operator()() const;
  233. // Implements IBooleanEx
  234. virtual bool TrySetValue( bool value );
  235. // Implements IEnumerationEx
  236. virtual bool GetValueOrDefault( bool defaultValue );
  237. protected:
  238. GenApi::IBoolean* m_pFeature;
  239. };
  240. }
  241. #ifdef _MSC_VER
  242. # pragma warning( pop )
  243. #endif
  244. #ifdef _MSC_VER
  245. # pragma pack(pop)
  246. #endif /* _MSC_VER */
  247. #endif /* INCLUDED_BASLER_PYLON_CBOOLEANPARAMETER_H */