IEnumerationT.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. //-----------------------------------------------------------------------------
  2. // (c) 2006 by Basler Vision Technologies
  3. // Section: Vision Components
  4. // Project: GenApi
  5. // Author: Fritz Dierks
  6. // $Header$
  7. //
  8. // License: This file is published under the license of the EMVA GenICam Standard Group.
  9. // A text file describing the legal terms is included in your installation as 'GenICam_license.pdf'.
  10. // If for some reason you are missing this file please contact the EMVA or visit the website
  11. // (http://www.genicam.org) for a full copy.
  12. //
  13. // THIS SOFTWARE IS PROVIDED BY THE EMVA GENICAM STANDARD GROUP "AS IS"
  14. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  15. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE EMVA GENICAM STANDARD GROUP
  17. // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18. // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19. // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  20. // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  21. // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  22. // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  23. // POSSIBILITY OF SUCH DAMAGE.
  24. //-----------------------------------------------------------------------------
  25. /*!
  26. \file
  27. \brief Definition of interface IEnumerationT
  28. \ingroup GenApi_PublicInterface
  29. */
  30. #ifndef GENAPI_IENUMERATIONT_H
  31. #define GENAPI_IENUMERATIONT_H
  32. #include <GenApi/GenApiDll.h>
  33. #include <GenApi/Types.h>
  34. #include <GenApi/Pointer.h>
  35. #include <GenApi/IEnumeration.h>
  36. #include <GenApi/Compatibility.h>
  37. #include <vector>
  38. namespace GENAPI_NAMESPACE
  39. {
  40. //*************************************************************
  41. // Enumeration template interface
  42. //*************************************************************
  43. /**
  44. \brief Interface for enumeration properties
  45. \ingroup GenApi_PublicInterface
  46. */
  47. template< typename EnumT >
  48. interface IEnumerationT : public IEnumeration
  49. {
  50. //! Set node value
  51. /*!
  52. \param Value The value to set
  53. \param Verify Enables AccessMode and Range verification (default = true)
  54. */
  55. virtual void SetValue(EnumT Value, bool Verify = true) = 0;
  56. //! Set node value
  57. virtual IEnumeration& operator=(EnumT Value) = 0;
  58. //! Get node value
  59. /*!
  60. \param Verify Enables Range verification (default = false). The AccessMode is always checked
  61. \param IgnoreCache If true the value is read ignoring any caches (default = false)
  62. \return The value read
  63. */
  64. virtual EnumT GetValue(bool Verify = false, bool IgnoreCache = false) = 0;
  65. //! Get node value
  66. virtual EnumT operator()() = 0;
  67. //! Set node value
  68. /*! Note : the operator= is not inherited thus the operator= versions
  69. from IEnumeration must be implemented again */
  70. virtual IEnumeration& operator=(const GENICAM_NAMESPACE::gcstring& ValueStr) = 0;
  71. //! returns the EnumEntry object belonging to the Value
  72. virtual IEnumEntry *GetEntry(const EnumT Value) = 0;
  73. //! Get the current entry
  74. virtual IEnumEntry *GetCurrentEntry(bool Verify = false, bool IgnoreCache = false) = 0;
  75. };
  76. //*************************************************************
  77. // CEnumerationTRef class
  78. //*************************************************************
  79. #ifndef DOXYGEN_IGNORE
  80. /**
  81. \internal
  82. \brief Reference to an IEnumerationT pointer
  83. \ingroup GenApi_PublicImpl
  84. */
  85. template< class EnumT >
  86. class CEnumerationTRef : public IEnumerationT< EnumT >, public IReference, public IEnumReference
  87. {
  88. public:
  89. // Constructor
  90. CEnumerationTRef() :
  91. m_Ptr(NULL)
  92. {}
  93. /*--------------------------------------------------------*/
  94. // IReference
  95. /*--------------------------------------------------------*/
  96. //! sets the implementation to the reference
  97. virtual void SetReference( IBase *ptr )
  98. {
  99. m_Ptr = dynamic_cast< IEnumeration *>( ptr );
  100. }
  101. /*--------------------------------------------------------*/
  102. // IEnumReference
  103. /*--------------------------------------------------------*/
  104. //! sets the number of enum values
  105. virtual void SetNumEnums( int NumEnums )
  106. {
  107. m_EnumExists.resize(NumEnums);
  108. m_EnumValues.resize(NumEnums);
  109. std::vector<bool>::iterator ptr;
  110. for(ptr = m_EnumExists.begin(); ptr != m_EnumExists.end(); ptr++)
  111. *ptr = false;
  112. }
  113. //! sets the Enum value corresponding to a value
  114. virtual void SetEnumReference( int Index, GENICAM_NAMESPACE::gcstring Name)
  115. {
  116. if ( m_Ptr )
  117. {
  118. CEnumEntryPtr ptrEnumEntry = GetEntryByName(Name);
  119. if( ptrEnumEntry.IsValid() )
  120. {
  121. m_EnumExists[Index] = true;
  122. m_EnumValues[Index] = ptrEnumEntry->GetValue();
  123. }
  124. }
  125. }
  126. /*--------------------------------------------------------*/
  127. // IBase
  128. /*--------------------------------------------------------*/
  129. //! Get the access mode of the node
  130. virtual EAccessMode GetAccessMode() const
  131. {
  132. if(m_Ptr)
  133. return m_Ptr->GetAccessMode();
  134. else
  135. return NI;
  136. }
  137. /*--------------------------------------------------------*/
  138. // IValue
  139. /*--------------------------------------------------------*/
  140. //! Get the INode interface of the node
  141. virtual INode* GetNode()
  142. {
  143. if(m_Ptr)
  144. return m_Ptr->GetNode();
  145. else
  146. throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
  147. }
  148. //! Get content of the node as string
  149. virtual GENICAM_NAMESPACE::gcstring ToString(bool Verify = false, bool IgnoreCache = false)
  150. {
  151. if(m_Ptr)
  152. return m_Ptr->ToString(Verify, IgnoreCache);
  153. else
  154. throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
  155. }
  156. //! Set content of the node as string
  157. virtual void FromString(const GENICAM_NAMESPACE::gcstring& ValueStr, bool Verify = true)
  158. {
  159. if(m_Ptr)
  160. return m_Ptr->FromString(ValueStr, Verify);
  161. else
  162. throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
  163. }
  164. //! Checks if the value comes from cache or is requested from another node
  165. bool IsValueCacheValid() const
  166. {
  167. if(m_Ptr)
  168. return m_Ptr->IsValueCacheValid();
  169. else
  170. throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
  171. }
  172. /*--------------------------------------------------------*/
  173. // IEnumeration
  174. /*--------------------------------------------------------*/
  175. //! Get list of symbolic Values
  176. virtual void GetSymbolics(StringList_t & Symbolics)
  177. {
  178. if(m_Ptr)
  179. return m_Ptr->GetSymbolics(Symbolics);
  180. else
  181. throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
  182. }
  183. //! Get list of entry nodes
  184. virtual void GetEntries(NodeList_t & Entries)
  185. {
  186. if(m_Ptr)
  187. return m_Ptr->GetEntries(Entries);
  188. else
  189. throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
  190. }
  191. //! Set node value
  192. virtual IEnumeration& operator=(const GENICAM_NAMESPACE::gcstring& ValueStr)
  193. {
  194. if(m_Ptr)
  195. return m_Ptr->operator=(ValueStr);
  196. else
  197. throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
  198. }
  199. //! Set node value
  200. virtual IEnumeration& operator=(const char *pValueStr)
  201. {
  202. if(m_Ptr)
  203. return m_Ptr->operator=(pValueStr);
  204. else
  205. throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
  206. }
  207. //! Set node value
  208. virtual void SetIntValue(int64_t Value, bool Verify = true)
  209. {
  210. if(m_Ptr)
  211. m_Ptr->SetIntValue(Value, Verify);
  212. else
  213. throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
  214. }
  215. //! Get node value
  216. virtual GENICAM_NAMESPACE::gcstring operator*()
  217. {
  218. if(m_Ptr)
  219. return m_Ptr->operator*();
  220. else
  221. throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
  222. }
  223. //! Get node value
  224. virtual int64_t GetIntValue(bool Verify = false, bool IgnoreCache = false)
  225. {
  226. if(m_Ptr)
  227. return m_Ptr->GetIntValue(Verify, IgnoreCache);
  228. else
  229. throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
  230. }
  231. //! Get an entry node by name
  232. virtual IEnumEntry *GetEntryByName(const GENICAM_NAMESPACE::gcstring& Symbolic)
  233. {
  234. if(m_Ptr)
  235. return m_Ptr->GetEntryByName(Symbolic);
  236. else
  237. throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
  238. }
  239. //! Get an entry node by its IntValue
  240. virtual IEnumEntry *GetEntry(const int64_t IntValue)
  241. {
  242. if(m_Ptr)
  243. return m_Ptr->GetEntry(IntValue);
  244. else
  245. throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
  246. }
  247. //! Get the current entry
  248. virtual IEnumEntry *GetCurrentEntry(bool Verify = false, bool IgnoreCache = false)
  249. {
  250. if(m_Ptr)
  251. return m_Ptr->GetCurrentEntry(Verify, IgnoreCache);
  252. else
  253. throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
  254. }
  255. /*--------------------------------------------------------*/
  256. // IEnumerationT
  257. /*--------------------------------------------------------*/
  258. //! Set node value
  259. virtual void SetValue(EnumT Value, bool Verify = true)
  260. {
  261. if(m_Ptr)
  262. {
  263. if( m_EnumExists[Value] )
  264. {
  265. int64_t EnumValue = m_EnumValues[Value];
  266. m_Ptr->SetIntValue(EnumValue, Verify);
  267. }
  268. else
  269. throw ACCESS_EXCEPTION("EnumEntry %d not present", Value);
  270. }
  271. else
  272. throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
  273. }
  274. //! Set node value
  275. virtual IEnumeration& operator=(EnumT Value)
  276. {
  277. SetValue(Value);
  278. return *this;
  279. }
  280. //! Get node value
  281. virtual EnumT GetValue(bool Verify = false, bool IgnoreCache = false)
  282. {
  283. if(m_Ptr)
  284. {
  285. int64_t IntValue = m_Ptr->GetIntValue(Verify, IgnoreCache);
  286. std::vector<int64_t>::iterator ptr;
  287. for ( unsigned int idx = 0; idx < m_EnumValues.size(); ++idx )
  288. {
  289. if( m_EnumExists[idx] && m_EnumValues[idx] == IntValue)
  290. return (EnumT) idx;
  291. }
  292. throw ACCESS_EXCEPTION("Unknown IntValue %" FMT_I64 "d", IntValue);
  293. }
  294. else
  295. throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
  296. }
  297. //! Get node value
  298. virtual EnumT operator()()
  299. {
  300. return GetValue();
  301. }
  302. //! returns the EnumEntry object belonging to the Value
  303. virtual IEnumEntry *GetEntry(const EnumT Value)
  304. {
  305. if(m_Ptr)
  306. {
  307. if( m_EnumExists[Value] )
  308. {
  309. int64_t EnumValue = m_EnumValues[Value];
  310. return m_Ptr->GetEntry(EnumValue);
  311. }
  312. else
  313. return NULL;
  314. }
  315. else
  316. throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
  317. }
  318. protected:
  319. //! Pointer to the implementation the reference references to
  320. IEnumeration *m_Ptr;
  321. //! The values for enums with a given index
  322. std::vector<int64_t > m_EnumValues;
  323. //! Indicates it an enum with a given index exists
  324. std::vector<bool > m_EnumExists;
  325. };
  326. #endif
  327. }
  328. #endif // ifndef GENAPI_IENUMERATIONT_H