Parameter.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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 CParameter used to simplify access to %GenApi parameters.
  9. */
  10. #ifndef INCLUDED_BASLER_PYLON_CPARAMETER_H
  11. #define INCLUDED_BASLER_PYLON_CPARAMETER_H
  12. #pragma once
  13. #include <pylon/PylonBase.h>
  14. #include <GenApi/IValue.h>
  15. #ifdef _MSC_VER
  16. # pragma pack(push, PYLON_PACKING)
  17. #endif /* _MSC_VER */
  18. #ifdef _MSC_VER
  19. # pragma warning( push )
  20. # pragma warning( disable : 4275 ) // Class needs to have a dll interface to be used by clients of the class.
  21. # pragma warning( disable : 4250 ) // warning C4250: 'Pylon::CXYZParameter': inherits 'Pylon::CParameter::Pylon::CParameter::ZYX' via dominance
  22. #endif
  23. namespace Pylon
  24. {
  25. /// Lists possible parameter info values.
  26. enum EParameterInfo
  27. {
  28. /// The identifier of a parameter. It can be used to access the node via a node map using GenApi::INodeMap::GetNode()
  29. /// or to access the value of an enumeration parameter using CEnumParameter::GetEntryByNameAsParameter().
  30. ParameterInfo_Name,
  31. /// The name of a parameter or an enumeration value that can be used for display in a user interface.
  32. ParameterInfo_DisplayName,
  33. /// The short description of a parameter or an enumeration value.
  34. ParameterInfo_ToolTip,
  35. /// The long description of a parameter or an enumeration value.
  36. ParameterInfo_Description
  37. };
  38. /*!
  39. \brief Extends the GenApi::IValue interface with convenience methods.
  40. */
  41. interface IValueEx : virtual public GenApi::IValue
  42. {
  43. /*!
  44. \brief Indicates whether the parameter is readable.
  45. \error
  46. Does not throw C++ exceptions.
  47. \return Returns true if the parameter is readable.
  48. */
  49. virtual bool IsReadable() const = 0;
  50. /*!
  51. \brief Indicates whether the parameter is writable.
  52. \error
  53. Does not throw C++ exceptions.
  54. \return Returns true if the parameter is writable.
  55. */
  56. virtual bool IsWritable() const = 0;
  57. /*!
  58. \brief Indicates whether a node is attached.
  59. \return Returns true if a node is attached.
  60. \error
  61. Does not throw C++ exceptions.
  62. */
  63. virtual bool IsValid() const = 0;
  64. /*!
  65. \brief Gets the parameter information.
  66. \param[in] info The type information to return.
  67. \return Returns the parameter information.
  68. \threading
  69. The method accesses the parameter multiple times. These accesses are not synchronized by a lock.
  70. \error
  71. Throws an exception if no node is attached.
  72. Can throw exceptions if the retrieval of the information fails.
  73. */
  74. virtual String_t GetInfo( EParameterInfo info ) = 0;
  75. /*!
  76. \brief Gets the parameter information if the parameter is attached to a node. See IsValid().
  77. \param[in] info The type information to return.
  78. \brief Otherwise returns the default information.
  79. This method is useful if you want to display parameter information and handle the case that some parameters are not available for a device.
  80. \return Returns the parameter information if the parameter is attached to a node. Otherwise returns the default information.
  81. \param[in] defaultInfo The default information returned if the parameter is not attached to a node.
  82. \threading
  83. The method accesses the parameter multiple times. These accesses are not synchronized by a lock.
  84. \error
  85. Can throw exceptions if the retrieval of the information fails.
  86. */
  87. virtual String_t GetInfoOrDefault( EParameterInfo info, const String_t defaultInfo ) = 0;
  88. /*!
  89. \brief Gets the parameter value as string if the parameter is readable.
  90. \brief Otherwise returns the default value.
  91. \return Returns the parameter value if the parameter is readable. Otherwise returns the default value.
  92. \param[in] defaultValue The default value returned if the parameter is not readable.
  93. \threading
  94. The method accesses the parameter multiple times. These accesses are not synchronized by a lock.
  95. \error
  96. Can throw exceptions if reading the value fails.
  97. */
  98. virtual String_t ToStringOrDefault( const String_t& defaultValue ) = 0;
  99. };
  100. /*!
  101. \brief CParameter class used to simplify access to %GenApi parameters.
  102. */
  103. class PYLONBASE_API CParameter : virtual public IValueEx
  104. {
  105. public:
  106. /*!
  107. \brief Creates an empty CParameter object.
  108. \error
  109. Does not throw C++ exceptions.
  110. */
  111. CParameter();
  112. /*!
  113. \brief Creates a CParameter object and attaches it to a node, typically retrieved for a nodemap calling GetNode().
  114. \param[in] pNode The node to attach.
  115. \post
  116. <ul>
  117. <li>If the passed node does not match the parameter type, the parameter will be empty, see IsValid().
  118. <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.
  119. <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.
  120. </ul>
  121. \error
  122. Does not throw C++ exceptions.
  123. */
  124. explicit CParameter( GenApi::INode* pNode );
  125. /*!
  126. \brief Creates a CParameter object and attaches it to a node of a matching type.
  127. \param[in] pValue The node to attach.
  128. \post
  129. The parameter object must not be used to access the node's functionality if the source of the attached \c pValue has been destroyed. In this case, call Release() or attach a new node.
  130. \error
  131. Does not throw C++ exceptions.
  132. */
  133. explicit CParameter( GenApi::IValue* pValue );
  134. /*!
  135. \brief Creates a CParameter object and attaches it to a node retrieved from the provided node map.
  136. \param[in] pNodeMap The node map. The source of the parameter.
  137. \param[in] pName The name of the parameter to attach.
  138. \post
  139. <ul>
  140. <li>If \c pNodeMap or \c name is NULL, the parameter will be empty, see IsValid().
  141. <li>If the node does not match the parameter type, the parameter will be empty, see IsValid().
  142. <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.
  143. <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.
  144. </ul>
  145. \error
  146. The call to GenApi::INodeMap::GetNode can throw C++ exceptions.
  147. */
  148. CParameter( GenApi::INodeMap* pNodeMap, const char* pName );
  149. /*!
  150. \brief Creates a CParameter object and attaches it to a node retrieved from the provided node map.
  151. \param[in] nodeMap The node map. The source of the parameter.
  152. \param[in] pName The name of the parameter to attach.
  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. CParameter( GenApi::INodeMap& nodeMap, const char* pName );
  164. /*!
  165. \brief Copies a CParameter object.
  166. \param[in] rhs The object to copy.
  167. \error
  168. Does not throw C++ exceptions.
  169. */
  170. CParameter( const CParameter& rhs );
  171. /*!
  172. \brief Destroys the CParameter object.
  173. Does not access the attached node.
  174. \error
  175. Does not throw C++ exceptions.
  176. */
  177. virtual ~CParameter();
  178. /*!
  179. \brief Attaches a node retrieved from the provided node map.
  180. \param[in] pNodeMap The node map. The source of the parameter.
  181. \param[in] pName The name of the parameter to attach.
  182. \return Returns true if the node has been attached.
  183. \post
  184. <ul>
  185. <li>If \c pNodeMap or \c name is NULL, the parameter will be empty, see IsValid().
  186. <li>If the node does not match the parameter type, the parameter will be empty, see IsValid().
  187. <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.
  188. <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.
  189. </ul>
  190. \error
  191. The call to GenApi::INodeMap::GetNode can throw C++ exceptions.
  192. */
  193. virtual bool Attach( GenApi::INodeMap* pNodeMap, const char* pName );
  194. /*!
  195. \brief Attaches a node retrieved from the provided node map.
  196. \param[in] nodeMap The node map. The source of the parameter.
  197. \param[in] pName The name of the parameter to attach.
  198. \return Returns true if the node has been attached.
  199. \post
  200. <ul>
  201. <li>If \c name is NULL the parameter will be empty, see IsValid().
  202. <li>If the node does not match the parameter type, the parameter will be empty, see IsValid().
  203. <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.
  204. <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.
  205. </ul>
  206. \error
  207. The call to GenApi::INodeMap::GetNode can throw C++ exceptions.
  208. */
  209. virtual bool Attach( GenApi::INodeMap& nodeMap, const char* pName );
  210. /*!
  211. \brief Attaches a node, typically retrieved for a nodemap calling GetNode().
  212. \param[in] pNode The node to assign.
  213. \return Returns true if the node has been attached.
  214. \post
  215. <ul>
  216. <li>If the node does not match the parameter type, the parameter will be empty, see IsValid().
  217. <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.
  218. <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.
  219. </ul>
  220. \error
  221. Does not throw C++ exceptions.
  222. */
  223. virtual bool Attach( GenApi::INode* pNode );
  224. /*!
  225. \brief Assigns a node of the same type to the parameter object.
  226. \param[in] pValue The node to assign.
  227. \return Returns true if the node has been attached.
  228. \error
  229. Does not throw C++ exceptions.
  230. */
  231. virtual bool Attach( GenApi::IValue* pValue );
  232. /*!
  233. \brief Assigns a CParameter object.
  234. \param[in] rhs The object to assign.
  235. \error
  236. Does not throw C++ exceptions.
  237. */
  238. CParameter& operator=( const CParameter& rhs );
  239. /*!
  240. \brief Returns true if the same nodes are attached or both parameters are empty.
  241. \param[in] rhs The object to compare to.
  242. \return Returns true if the same nodes are attached or both parameters are empty.
  243. \error
  244. Does not throw C++ exceptions.
  245. */
  246. virtual bool Equals( const CParameter& rhs ) const;
  247. /*!
  248. \brief Returns true if the attached node pointer is equal.
  249. \param[in] pNode The node to compare to.
  250. \return Returns true if the attached node pointer is equal.
  251. \error
  252. Does not throw C++ exceptions.
  253. */
  254. virtual bool Equals( const GenApi::INode* pNode ) const;
  255. /*!
  256. \brief Returns true if the attached node pointer is equal.
  257. \param[in] pValue The node to compare to.
  258. \return Returns true if the attached node pointer is equal.
  259. \error
  260. Does not throw C++ exceptions.
  261. */
  262. virtual bool Equals( const GenApi::IValue* pValue ) const;
  263. /*!
  264. \brief Releases the attached node.
  265. \error
  266. Does not throw C++ exceptions.
  267. */
  268. virtual void Release();
  269. // Implements GenApi::IBase
  270. virtual GenApi::EAccessMode GetAccessMode() const;
  271. // Implements GenApi::IValue
  272. virtual GenApi::INode* GetNode();
  273. // Implements GenApi::IValue
  274. virtual GenICam::gcstring ToString( bool verify = false, bool ignoreCache = false );
  275. // Implements GenApi::IValue
  276. virtual void FromString( const GenICam::gcstring& valueStr, bool verify = true );
  277. // Implements GenApi::IValue
  278. virtual bool IsValueCacheValid() const;
  279. // Implements IValueEx
  280. virtual bool IsReadable() const;
  281. // Implements IValueEx
  282. virtual bool IsWritable() const;
  283. // Implements IValueEx
  284. virtual bool IsValid() const;
  285. // Implements IValueEx
  286. virtual String_t GetInfo( EParameterInfo info );
  287. // Implements IValueEx
  288. virtual String_t GetInfoOrDefault( EParameterInfo info, const String_t defaultInfo );
  289. // Implements IValueEx
  290. virtual String_t ToStringOrDefault( const String_t& defaultValue );
  291. protected:
  292. GenApi::IValue* m_pValue;
  293. };
  294. }
  295. #ifdef _MSC_VER
  296. # pragma warning( pop )
  297. #endif
  298. #ifdef _MSC_VER
  299. # pragma pack(pop)
  300. #endif /* _MSC_VER */
  301. #endif /* INCLUDED_BASLER_PYLON_CPARAMETER_H */