FeatureContainer.cpp
Go to the documentation of this file.
1 /*=============================================================================
2  Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
3 
4  Redistribution of this file, in original or modified form, without
5  prior written consent of Allied Vision Technologies is prohibited.
6 
7 -------------------------------------------------------------------------------
8 
9  File: FeatureContainer.cpp
10 
11  Description: Implementation of class AVT::VmbAPI::FeatureContainer.
12 
13 -------------------------------------------------------------------------------
14 
15  THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
16  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
17  NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
22  AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
23  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 =============================================================================*/
27 
28 #include <string>
29 
31 
33 
34 namespace AVT {
35 namespace VmbAPI {
36 
38 {
40 
42 
44 };
45 
47  : m_pImpl ( new Impl() )
48 {
50  m_pImpl->m_handle = NULL;
51 }
52 
54 {
55  // No copy ctor
56 }
57 
59 {
60  // No assignment operator
61  return *this;
62 }
63 
65 {
66  Reset();
67  RevokeHandle();
68 
69  delete m_pImpl;
70 }
71 
72 VmbErrorType FeatureContainer::GetFeatureByName( const char *name, FeaturePtr &rFeature )
73 {
74  VmbError_t res;
75 
76  if ( NULL == name )
77  {
78  return VmbErrorBadParameter;
79  }
80 
81  if ( NULL == m_pImpl->m_handle )
82  {
83  return VmbErrorDeviceNotOpen;
84  }
85 
86  FeaturePtrMap::iterator iter = m_pImpl->m_features.find( name );
87  if ( iter != m_pImpl->m_features.end() )
88  {
89  rFeature = iter->second;
90  return VmbErrorSuccess;
91  }
92 
93  VmbFeatureInfo_t featureInfo;
94 
95  res = VmbFeatureInfoQuery( m_pImpl->m_handle, name, &featureInfo, sizeof( VmbFeatureInfo_t ));
96 
97  if ( VmbErrorSuccess == res )
98  {
99  rFeature = FeaturePtr( new Feature( &featureInfo, this ));
100  // Only add visible features to the feature list
101  if ( VmbFeatureVisibilityInvisible != featureInfo.visibility )
102  {
103  m_pImpl->m_features[name] = rFeature;
104  }
105  }
106 
107  return (VmbErrorType)res;
108 }
109 
110 VmbErrorType FeatureContainer::GetFeatures( FeaturePtr *pFeatures, VmbUint32_t &rnSize )
111 {
112  VmbError_t res;
113 
114  if ( NULL == m_pImpl->m_handle )
115  {
116  return VmbErrorDeviceNotOpen;
117  }
118 
119  // Feature list is static and therefore needs to be fetched only once per lifetime
120  if ( false == m_pImpl->m_bAllFeaturesFetched )
121  {
122  std::vector<VmbFeatureInfo_t> featureInfoList;
123 
124  res = VmbFeaturesList( m_pImpl->m_handle, NULL, 0, &rnSize, sizeof(VmbFeatureInfo_t) );
125  if ( 0 == rnSize || VmbErrorSuccess != res )
126  {
127  return (VmbErrorType)res;
128  }
129 
130  featureInfoList.resize( rnSize );
131  res = VmbFeaturesList( m_pImpl->m_handle, &featureInfoList[0], rnSize, &rnSize, sizeof(VmbFeatureInfo_t) );
132  if ( VmbErrorSuccess != res )
133  {
134  return (VmbErrorType)res;
135  }
136 
137  for ( std::vector<VmbFeatureInfo_t>::iterator iter = featureInfoList.begin();
138  featureInfoList.end() != iter;
139  ++iter )
140  {
141  std::string strName = iter->name;
142  if ( 0 != strName.length() )
143  {
144  if ( SP_ISNULL( m_pImpl->m_features[strName] ))
145  {
146  m_pImpl->m_features[strName] = FeaturePtr( new Feature( &(*iter), this ));
147  }
148  }
149  }
150 
152  }
153  else // Features have been fetched before
154  {
155  res = VmbErrorSuccess;
156  }
157 
158  if ( VmbErrorSuccess == res )
159  {
160  if ( NULL == pFeatures )
161  {
162  rnSize = (VmbUint32_t)m_pImpl->m_features.size();
163  return VmbErrorSuccess;
164  }
165  else if ( m_pImpl->m_features.size() <= rnSize )
166  {
167  VmbUint32_t i = 0;
168  for ( FeaturePtrMap::iterator iter = m_pImpl->m_features.begin();
169  m_pImpl->m_features.end() != iter;
170  ++iter, ++i )
171  {
172  pFeatures[i] = iter->second;
173  }
174  rnSize = (VmbUint32_t)m_pImpl->m_features.size();
175  return VmbErrorSuccess;
176  }
177  else
178  {
179  return VmbErrorMoreData;
180  }
181  }
182  else
183  {
184  return (VmbErrorType)res;
185  }
186 }
187 
189 {
190  return m_pImpl->m_handle;
191 }
192 
194 {
195  if ( NULL == handle )
196  {
197  Reset();
198  RevokeHandle();
199  }
200  else
201  {
202  m_pImpl->m_handle = handle;
203  }
204 }
205 
206 // Sets the C handle to NULL
208 {
209  m_pImpl->m_handle = NULL;
210 }
211 
212 // Sets the back reference to feature container that each feature holds to NULL
213 // and resets all known features
215 {
216  for ( FeaturePtrMap::iterator iter = m_pImpl->m_features.begin();
217  m_pImpl->m_features.end() != iter;
218  ++iter)
219  {
220  SP_ACCESS( iter->second )->ResetFeatureContainer();
221  }
222 
223  m_pImpl->m_features.clear();
225 }
226 
227 }} // namespace AVT::VmbAPI
VmbErrorDeviceNotOpen
@ VmbErrorDeviceNotOpen
Definition: VmbCommonTypes.h:113
VmbFeatureInfo::visibility
VmbFeatureVisibility_t visibility
Definition: VimbaC.h:217
SP_ACCESS
#define SP_ACCESS(sp)
Definition: SharedPointerDefines.h:49
AVT::VmbAPI::FeatureContainer::Impl::m_handle
VmbHandle_t m_handle
Definition: FeatureContainer.cpp:39
VmbFeatureInfoQuery
IMEXPORTC VmbError_t VMB_CALL VmbFeatureInfoQuery(const VmbHandle_t handle, const char *name, VmbFeatureInfo_t *pFeatureInfo, VmbUint32_t sizeofFeatureInfo)
FeatureContainer.h
AVT::VmbAPI::FeatureContainer::RevokeHandle
void RevokeHandle()
Definition: FeatureContainer.cpp:207
AVT
Definition: AncillaryData.h:35
VmbErrorType
VmbErrorType
Definition: VmbCommonTypes.h:106
VimbaSystem.h
AVT::VmbAPI::FeatureContainer::GetHandle
VmbHandle_t GetHandle() const
Definition: FeatureContainer.cpp:188
VmbErrorMoreData
@ VmbErrorMoreData
Definition: VmbCommonTypes.h:117
VmbFeaturesList
IMEXPORTC VmbError_t VMB_CALL VmbFeaturesList(const VmbHandle_t handle, VmbFeatureInfo_t *pFeatureInfoList, VmbUint32_t listLength, VmbUint32_t *pNumFound, VmbUint32_t sizeofFeatureInfo)
AVT::VmbAPI::FeatureContainer::Impl
Definition: FeatureContainer.cpp:37
AVT::VmbAPI::FeaturePtrMap
std::map< std::string, FeaturePtr > FeaturePtrMap
Definition: Feature.h:49
VmbError_t
VmbInt32_t VmbError_t
Definition: VmbCommonTypes.h:130
AVT::VmbAPI::FeatureContainer::m_pImpl
Impl * m_pImpl
Definition: FeatureContainer.h:108
SP_ISNULL
#define SP_ISNULL(sp)
Definition: SharedPointerDefines.h:48
AVT::VmbAPI::FeatureContainer::operator=
FeatureContainer & operator=(const FeatureContainer &)
Definition: FeatureContainer.cpp:58
AVT::VmbAPI::FeatureContainer::GetFeatureByName
IMEXPORT VmbErrorType GetFeatureByName(const char *pName, FeaturePtr &pFeature)
Definition: FeatureContainer.cpp:72
VmbHandle_t
void * VmbHandle_t
Definition: VmbCommonTypes.h:82
VmbUint32_t
unsigned int VmbUint32_t
Definition: VmbCommonTypes.h:73
VmbErrorSuccess
@ VmbErrorSuccess
Definition: VmbCommonTypes.h:108
VmbFeatureVisibilityInvisible
@ VmbFeatureVisibilityInvisible
Definition: VimbaC.h:186
AVT::VmbAPI::FeatureContainer::SetHandle
void SetHandle(const VmbHandle_t handle)
Definition: FeatureContainer.cpp:193
AVT::VmbAPI::FeatureContainer::~FeatureContainer
IMEXPORT ~FeatureContainer()
Definition: FeatureContainer.cpp:64
AVT::VmbAPI::FeatureContainer::GetFeatures
VmbErrorType GetFeatures(FeaturePtrVector &features)
Definition: FeatureContainer.hpp:38
AVT::VmbAPI::FeatureContainer::Impl::m_bAllFeaturesFetched
bool m_bAllFeaturesFetched
Definition: FeatureContainer.cpp:41
AVT::VmbAPI::FeatureContainer::Reset
void Reset()
Definition: FeatureContainer.cpp:214
AVT::VmbAPI::FeatureContainer
Definition: FeatureContainer.h:40
AVT::VmbAPI::Feature
Definition: Feature.h:51
AVT::VmbAPI::FeatureContainer::FeatureContainer
IMEXPORT FeatureContainer()
Definition: FeatureContainer.cpp:46
VmbErrorBadParameter
@ VmbErrorBadParameter
Definition: VmbCommonTypes.h:115
VmbFeatureInfo
Definition: VimbaC.h:207
AVT::VmbAPI::FeatureContainer::Impl::m_features
FeaturePtrMap m_features
Definition: FeatureContainer.cpp:43


avt_vimba_camera
Author(s): Allied Vision Technologies, Miquel Massot
autogenerated on Sat Jun 3 2023 02:14:12