Feature.hpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. /*=============================================================================
  2. Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
  3. Redistribution of this file, in original or modified form, without
  4. prior written consent of Allied Vision Technologies is prohibited.
  5. -------------------------------------------------------------------------------
  6. File: Feature.hpp
  7. Description: Inline wrapper functions for class AVT::VmbAPI::Feature.
  8. -------------------------------------------------------------------------------
  9. THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
  10. WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
  11. NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  12. DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
  13. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  14. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  15. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  16. AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  17. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  18. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19. =============================================================================*/
  20. #ifndef AVT_VMBAPI_FEATURE_HPP
  21. #define AVT_VMBAPI_FEATURE_HPP
  22. //
  23. // Inline wrapper functions that allocate memory for STL objects in the application's context
  24. // and to pass data across DLL boundaries using arrays
  25. //
  26. inline VmbErrorType Feature::GetValues( StringVector &rValues )
  27. {
  28. VmbErrorType res;
  29. VmbUint32_t nSize;
  30. res = GetValues( (const char **)NULL, nSize );
  31. if ( VmbErrorSuccess == res )
  32. {
  33. if ( 0 != nSize)
  34. {
  35. try
  36. {
  37. std::vector<const char*> data( nSize );
  38. res = GetValues( &data[0], nSize );
  39. if ( VmbErrorSuccess == res )
  40. {
  41. StringVector tmpValues( data.size() );
  42. std::copy( data.begin(), data.end(), tmpValues.begin() );
  43. rValues.swap( tmpValues);
  44. }
  45. }
  46. catch(...)
  47. {
  48. return VmbErrorResources;
  49. }
  50. }
  51. else
  52. {
  53. rValues.clear();
  54. }
  55. }
  56. return res;
  57. }
  58. inline VmbErrorType Feature::GetEntries( EnumEntryVector &rEntries )
  59. {
  60. VmbErrorType res;
  61. VmbUint32_t nSize;
  62. res = GetEntries( (EnumEntry*)NULL, nSize );
  63. if ( VmbErrorSuccess == res )
  64. {
  65. if( 0 != nSize )
  66. {
  67. try
  68. {
  69. EnumEntryVector tmpEntries( nSize );
  70. res = GetEntries( &tmpEntries[0], nSize );
  71. if( VmbErrorSuccess == res)
  72. {
  73. rEntries.swap( tmpEntries );
  74. }
  75. }
  76. catch(...)
  77. {
  78. return VmbErrorResources;
  79. }
  80. }
  81. else
  82. {
  83. rEntries.clear();
  84. }
  85. }
  86. return res;
  87. }
  88. inline VmbErrorType Feature::GetValues( Int64Vector &rValues )
  89. {
  90. VmbErrorType res;
  91. VmbUint32_t nSize;
  92. res = GetValues( (VmbInt64_t*)NULL, nSize );
  93. if ( VmbErrorSuccess == res )
  94. {
  95. if( 0 != nSize)
  96. {
  97. try
  98. {
  99. Int64Vector tmpValues( nSize );
  100. res = GetValues( &tmpValues[0], nSize );
  101. if( VmbErrorSuccess == res)
  102. {
  103. rValues.swap( tmpValues );
  104. }
  105. }
  106. catch(...)
  107. {
  108. return VmbErrorResources;
  109. }
  110. }
  111. else
  112. {
  113. rValues.clear();
  114. }
  115. }
  116. return res;
  117. }
  118. inline VmbErrorType Feature::GetValue( std::string &rStrValue ) const
  119. {
  120. VmbErrorType res;
  121. VmbUint32_t nLength;
  122. res = GetValue( (char * const)NULL, nLength );
  123. if ( VmbErrorSuccess == res )
  124. {
  125. if ( 0 != nLength )
  126. {
  127. try
  128. {
  129. std::vector<std::string::value_type> tmpValue( nLength + 1, '\0' );
  130. res = GetValue( &tmpValue[0], nLength );
  131. if ( VmbErrorSuccess == res )
  132. {
  133. rStrValue = &*tmpValue.begin();
  134. }
  135. }
  136. catch(...)
  137. {
  138. return VmbErrorResources;
  139. }
  140. }
  141. else
  142. {
  143. rStrValue.clear();
  144. }
  145. }
  146. return res;
  147. }
  148. inline VmbErrorType Feature::GetValue( UcharVector &rValue ) const
  149. {
  150. VmbUint32_t i;
  151. return GetValue( rValue, i );
  152. }
  153. inline VmbErrorType Feature::GetValue( UcharVector &rValue, VmbUint32_t &rnSizeFilled ) const
  154. {
  155. VmbErrorType res;
  156. VmbUint32_t nSize;
  157. res = GetValue( NULL, nSize, rnSizeFilled );
  158. if ( VmbErrorSuccess == res )
  159. {
  160. if( 0 != nSize)
  161. {
  162. try
  163. {
  164. UcharVector tmpValue( nSize );
  165. res = GetValue( &tmpValue[0], nSize, rnSizeFilled );
  166. if( VmbErrorSuccess == res )
  167. {
  168. rValue.swap( tmpValue);
  169. }
  170. }
  171. catch(...)
  172. {
  173. return VmbErrorResources;
  174. }
  175. }
  176. else
  177. {
  178. rValue.clear();
  179. }
  180. }
  181. return res;
  182. }
  183. inline VmbErrorType Feature::SetValue( const UcharVector &rValue )
  184. {
  185. if ( rValue.empty() )
  186. {
  187. return VmbErrorBadParameter;
  188. }
  189. return SetValue( &rValue[0], (VmbUint32_t)rValue.size() );
  190. }
  191. inline VmbErrorType Feature::GetName( std::string &rStrName ) const
  192. {
  193. VmbErrorType res;
  194. VmbUint32_t nLength;
  195. res = GetName( NULL, nLength );
  196. if ( VmbErrorSuccess == res )
  197. {
  198. if ( 0 != nLength )
  199. {
  200. try
  201. {
  202. std::vector<std::string::value_type> tmpName( nLength + 1, '\0' );
  203. res = GetName( &tmpName[0], nLength );
  204. if( VmbErrorSuccess == res)
  205. {
  206. rStrName = &*tmpName.begin();
  207. }
  208. }
  209. catch(...)
  210. {
  211. return VmbErrorResources;
  212. }
  213. }
  214. else
  215. {
  216. rStrName.clear();
  217. }
  218. }
  219. return res;
  220. }
  221. inline VmbErrorType Feature::GetDisplayName( std::string &rStrDisplayName ) const
  222. {
  223. VmbErrorType res;
  224. VmbUint32_t nLength;
  225. res = GetDisplayName( NULL, nLength );
  226. if ( VmbErrorSuccess == res )
  227. {
  228. if ( 0 != nLength )
  229. {
  230. try
  231. {
  232. std::vector<std::string::value_type> tmpDisplayName( nLength + 1, '\0' );
  233. res = GetDisplayName( &tmpDisplayName[0], nLength );
  234. if( VmbErrorSuccess == res )
  235. {
  236. rStrDisplayName = &*tmpDisplayName.begin();
  237. }
  238. }
  239. catch(...)
  240. {
  241. return VmbErrorResources;
  242. }
  243. }
  244. else
  245. {
  246. rStrDisplayName.clear();
  247. }
  248. }
  249. return res;
  250. }
  251. inline VmbErrorType Feature::GetCategory( std::string &rStrCategory ) const
  252. {
  253. VmbErrorType res;
  254. VmbUint32_t nLength;
  255. res = GetCategory( NULL, nLength );
  256. if ( VmbErrorSuccess == res )
  257. {
  258. if ( 0 != nLength )
  259. {
  260. try
  261. {
  262. std::vector<std::string::value_type> tmpCategory( nLength + 1, '\0' );
  263. res = GetCategory( &tmpCategory[0], nLength );
  264. if( VmbErrorSuccess == res )
  265. {
  266. rStrCategory = &*tmpCategory.begin();
  267. }
  268. }
  269. catch(...)
  270. {
  271. return VmbErrorResources;
  272. }
  273. }
  274. else
  275. {
  276. rStrCategory.clear();
  277. }
  278. }
  279. return res;
  280. }
  281. inline VmbErrorType Feature::GetUnit( std::string &rStrUnit ) const
  282. {
  283. VmbErrorType res;
  284. VmbUint32_t nLength;
  285. res = GetUnit( NULL, nLength );
  286. if ( VmbErrorSuccess == res )
  287. {
  288. if ( 0 != nLength )
  289. {
  290. try
  291. {
  292. std::vector<std::string::value_type> tmpUnit( nLength + 1, '\0' );
  293. res = GetUnit( &tmpUnit[0], nLength );
  294. if( VmbErrorSuccess == res )
  295. {
  296. rStrUnit = &*tmpUnit.begin();
  297. }
  298. }
  299. catch(...)
  300. {
  301. return VmbErrorResources;
  302. }
  303. }
  304. else
  305. {
  306. rStrUnit.clear();
  307. }
  308. }
  309. return res;
  310. }
  311. inline VmbErrorType Feature::GetRepresentation( std::string &rStrRepresentation ) const
  312. {
  313. VmbErrorType res;
  314. VmbUint32_t nLength;
  315. res = GetRepresentation( NULL, nLength );
  316. if ( VmbErrorSuccess == res )
  317. {
  318. if ( 0 != nLength )
  319. {
  320. try
  321. {
  322. std::vector<std::string::value_type> tmpRepresentation( nLength + 1, '\0' );
  323. res = GetRepresentation( &tmpRepresentation[0], nLength );
  324. if( VmbErrorSuccess == res )
  325. {
  326. rStrRepresentation = &*tmpRepresentation.begin();
  327. }
  328. }
  329. catch(...)
  330. {
  331. return VmbErrorResources;
  332. }
  333. }
  334. else
  335. {
  336. rStrRepresentation.clear();
  337. }
  338. }
  339. return res;
  340. }
  341. inline VmbErrorType Feature::GetToolTip( std::string &rStrToolTip ) const
  342. {
  343. VmbErrorType res;
  344. VmbUint32_t nLength;
  345. res = GetToolTip( NULL, nLength );
  346. if ( VmbErrorSuccess == res )
  347. {
  348. if ( 0 != nLength )
  349. {
  350. try
  351. {
  352. std::vector<std::string::value_type> tmpToolTip( nLength + 1, '\0');
  353. res = GetToolTip( &tmpToolTip[0], nLength );
  354. if( VmbErrorSuccess == res )
  355. {
  356. rStrToolTip = &*tmpToolTip.begin();
  357. }
  358. }
  359. catch(...)
  360. {
  361. return VmbErrorResources;
  362. }
  363. }
  364. else
  365. {
  366. rStrToolTip.clear();
  367. }
  368. }
  369. return res;
  370. }
  371. inline VmbErrorType Feature::GetDescription( std::string &rStrDescription ) const
  372. {
  373. VmbErrorType res;
  374. VmbUint32_t nLength;
  375. res = GetDescription( NULL, nLength );
  376. if ( VmbErrorSuccess == res )
  377. {
  378. if ( 0 != nLength )
  379. {
  380. try
  381. {
  382. std::vector<std::string::value_type> tmpDescription( nLength + 1, '\0');
  383. res = GetDescription( &tmpDescription[0], nLength );
  384. if( VmbErrorSuccess == res )
  385. {
  386. rStrDescription = &*tmpDescription.begin();
  387. }
  388. }
  389. catch(...)
  390. {
  391. return VmbErrorResources;
  392. }
  393. }
  394. else
  395. {
  396. rStrDescription.clear();
  397. }
  398. }
  399. return res;
  400. }
  401. inline VmbErrorType Feature::GetSFNCNamespace( std::string &rStrSFNCNamespace ) const
  402. {
  403. VmbErrorType res;
  404. VmbUint32_t nLength;
  405. res = GetSFNCNamespace( NULL, nLength );
  406. if ( VmbErrorSuccess == res )
  407. {
  408. if ( 0 != nLength )
  409. {
  410. try
  411. {
  412. std::vector<std::string::value_type> tmpSFNCNamespace( nLength + 1, '\0' );
  413. res = GetSFNCNamespace( &tmpSFNCNamespace[0], nLength );
  414. if( VmbErrorSuccess == res )
  415. {
  416. rStrSFNCNamespace = &*tmpSFNCNamespace.begin();
  417. }
  418. }
  419. catch(...)
  420. {
  421. return VmbErrorResources;
  422. }
  423. }
  424. else
  425. {
  426. rStrSFNCNamespace.clear();
  427. }
  428. }
  429. return res;
  430. }
  431. inline VmbErrorType Feature::GetAffectedFeatures( FeaturePtrVector &rAffectedFeatures )
  432. {
  433. VmbErrorType res;
  434. VmbUint32_t nSize;
  435. res = GetAffectedFeatures( NULL, nSize );
  436. if ( VmbErrorSuccess == res )
  437. {
  438. if( 0 != nSize)
  439. {
  440. try
  441. {
  442. FeaturePtrVector tmpAffectedFeatures( nSize );
  443. res = GetAffectedFeatures( &tmpAffectedFeatures[0], nSize );
  444. if( VmbErrorSuccess == res )
  445. {
  446. rAffectedFeatures.swap( tmpAffectedFeatures );
  447. }
  448. }
  449. catch(...)
  450. {
  451. return VmbErrorResources;
  452. }
  453. }
  454. else
  455. {
  456. rAffectedFeatures.clear();
  457. }
  458. }
  459. return res;
  460. }
  461. inline VmbErrorType Feature::GetSelectedFeatures( FeaturePtrVector &rSelectedFeatures )
  462. {
  463. VmbErrorType res;
  464. VmbUint32_t nSize;
  465. res = GetSelectedFeatures( NULL, nSize );
  466. if ( VmbErrorSuccess == res )
  467. {
  468. if( 0 != nSize )
  469. {
  470. try
  471. {
  472. FeaturePtrVector tmpSelectedFeatures( nSize );
  473. res = GetSelectedFeatures( &tmpSelectedFeatures[0], nSize );
  474. if( VmbErrorSuccess == res )
  475. {
  476. rSelectedFeatures.swap ( tmpSelectedFeatures );
  477. }
  478. }
  479. catch(...)
  480. {
  481. return VmbErrorResources;
  482. }
  483. }
  484. else
  485. {
  486. rSelectedFeatures.clear();
  487. }
  488. }
  489. return res;
  490. }
  491. #endif