StringParameter.h 12 KB

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