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 
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 
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
VmbInt32_t VmbError_t
IMEXPORT VmbErrorType GetFeatureByName(const char *pName, FeaturePtr &pFeature)
#define SP_ISNULL(sp)
#define SP_ACCESS(sp)
VmbErrorType
std::map< std::string, FeaturePtr > FeaturePtrMap
Definition: Feature.h:49
void * VmbHandle_t
NetPointer< Feature, AVT::VmbAPINET::Feature > FeaturePtr
VmbErrorType GetFeatures(FeaturePtrVector &features)
IMEXPORTC VmbError_t VMB_CALL VmbFeatureInfoQuery(const VmbHandle_t handle, const char *name, VmbFeatureInfo_t *pFeatureInfo, VmbUint32_t sizeofFeatureInfo)
unsigned int VmbUint32_t
VmbFeatureVisibility_t visibility
Definition: VimbaC.h:218
FeatureContainer & operator=(const FeatureContainer &)
IMEXPORTC VmbError_t VMB_CALL VmbFeaturesList(const VmbHandle_t handle, VmbFeatureInfo_t *pFeatureInfoList, VmbUint32_t listLength, VmbUint32_t *pNumFound, VmbUint32_t sizeofFeatureInfo)
void SetHandle(const VmbHandle_t handle)


avt_vimba_camera
Author(s): Miquel Massot , Allied Vision Technologies
autogenerated on Mon Jun 10 2019 12:50:39