FeatureContainer.cpp
Go to the documentation of this file.
00001 /*=============================================================================
00002   Copyright (C) 2012 Allied Vision Technologies.  All Rights Reserved.
00003 
00004   Redistribution of this file, in original or modified form, without
00005   prior written consent of Allied Vision Technologies is prohibited.
00006 
00007 -------------------------------------------------------------------------------
00008  
00009   File:        FeatureContainer.cpp
00010 
00011   Description: Implementation of class AVT::VmbAPI::FeatureContainer.
00012 
00013 -------------------------------------------------------------------------------
00014 
00015   THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
00016   WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
00017   NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR  PURPOSE ARE
00018   DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 
00019   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
00020   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00021   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED  
00022   AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 
00023   TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
00024   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00025 
00026 =============================================================================*/
00027 
00028 #include <string>
00029 
00030 #include <VimbaCPP/Include/FeatureContainer.h>
00031 
00032 #include <VimbaCPP/Include/VimbaSystem.h>
00033 
00034 namespace AVT {
00035 namespace VmbAPI {
00036 
00037 struct FeatureContainer::Impl
00038 {
00039     VmbHandle_t         m_handle;
00040 
00041     bool                m_bAllFeaturesFetched;
00042 
00043     FeaturePtrMap       m_features;
00044 };
00045 
00046 FeatureContainer::FeatureContainer()
00047     :   m_pImpl ( new Impl() )
00048 {
00049     m_pImpl->m_bAllFeaturesFetched = false;
00050     m_pImpl->m_handle = NULL;
00051 }
00052 
00053 FeatureContainer::FeatureContainer( const FeatureContainer& )
00054 {
00055     // No copy ctor
00056 }
00057 
00058 FeatureContainer& FeatureContainer::operator=( const FeatureContainer& )
00059 {
00060     // No assignment operator
00061     return *this;
00062 }
00063 
00064 FeatureContainer::~FeatureContainer()
00065 {
00066     Reset();
00067     RevokeHandle();
00068 
00069     delete m_pImpl;
00070 }
00071 
00072 VmbErrorType FeatureContainer::GetFeatureByName( const char *name, FeaturePtr &rFeature )
00073 {
00074     VmbError_t res;
00075 
00076     if ( NULL == name )
00077     {
00078         return VmbErrorBadParameter;
00079     }
00080 
00081     if ( NULL == m_pImpl->m_handle )
00082     {
00083         return VmbErrorDeviceNotOpen;
00084     }
00085 
00086     FeaturePtrMap::iterator iter = m_pImpl->m_features.find( name );
00087     if ( iter != m_pImpl->m_features.end() )
00088     {
00089         rFeature = iter->second;
00090         return VmbErrorSuccess;
00091     }
00092 
00093     VmbFeatureInfo_t featureInfo;
00094         
00095     res = VmbFeatureInfoQuery( m_pImpl->m_handle, name, &featureInfo, sizeof( VmbFeatureInfo_t ));
00096 
00097     if ( VmbErrorSuccess == res )
00098     {
00099         rFeature = FeaturePtr( new Feature( &featureInfo, this ));
00100         // Only add visible features to the feature list
00101         if ( VmbFeatureVisibilityInvisible != featureInfo.visibility )
00102         {
00103             m_pImpl->m_features[name] = rFeature;
00104         }
00105     }
00106 
00107     return (VmbErrorType)res;
00108 }
00109 
00110 VmbErrorType FeatureContainer::GetFeatures( FeaturePtr *pFeatures, VmbUint32_t &rnSize )
00111 {
00112     VmbError_t res;
00113 
00114     if ( NULL == m_pImpl->m_handle )
00115     {
00116         return VmbErrorDeviceNotOpen;
00117     }
00118 
00119     // Feature list is static and therefore needs to be fetched only once per lifetime
00120     if ( false == m_pImpl->m_bAllFeaturesFetched )
00121     {
00122         std::vector<VmbFeatureInfo_t> featureInfoList;
00123 
00124         res = VmbFeaturesList( m_pImpl->m_handle, NULL, 0, &rnSize, sizeof(VmbFeatureInfo_t) );
00125         if ( 0 == rnSize || VmbErrorSuccess != res )
00126         {
00127             return (VmbErrorType)res;
00128         }
00129 
00130         featureInfoList.resize( rnSize );
00131         res = VmbFeaturesList( m_pImpl->m_handle, &featureInfoList[0], rnSize, &rnSize, sizeof(VmbFeatureInfo_t) );
00132         if ( VmbErrorSuccess != res )
00133         {
00134             return (VmbErrorType)res;
00135         }
00136 
00137         for (   std::vector<VmbFeatureInfo_t>::iterator iter = featureInfoList.begin();
00138                 featureInfoList.end() != iter;
00139                 ++iter )
00140         {
00141             std::string strName = iter->name;
00142             if ( 0 != strName.length() )
00143             {
00144                 if ( SP_ISNULL( m_pImpl->m_features[strName] ))
00145                 {
00146                     m_pImpl->m_features[strName] = FeaturePtr( new Feature( &(*iter), this ));
00147                 }
00148             }
00149         }
00150 
00151         m_pImpl->m_bAllFeaturesFetched = true;
00152     }
00153     else // Features have been fetched before
00154     {
00155         res = VmbErrorSuccess;
00156     }
00157 
00158     if ( VmbErrorSuccess == res )
00159     {
00160         if ( NULL == pFeatures )
00161         {
00162             rnSize = (VmbUint32_t)m_pImpl->m_features.size();
00163             return VmbErrorSuccess;
00164         }
00165         else if ( m_pImpl->m_features.size() <= rnSize )
00166         {
00167             VmbUint32_t i = 0;
00168             for (   FeaturePtrMap::iterator iter = m_pImpl->m_features.begin();
00169                     m_pImpl->m_features.end() != iter;
00170                     ++iter, ++i )
00171             {
00172                 pFeatures[i] = iter->second;
00173             }
00174             rnSize = (VmbUint32_t)m_pImpl->m_features.size();
00175             return VmbErrorSuccess;
00176         }
00177         else
00178         {
00179             return VmbErrorMoreData;
00180         }
00181     }
00182     else
00183     {
00184         return (VmbErrorType)res;
00185     }
00186 }
00187 
00188 VmbHandle_t FeatureContainer::GetHandle() const
00189 {
00190     return m_pImpl->m_handle;
00191 }
00192 
00193 void FeatureContainer::SetHandle( const VmbHandle_t handle )
00194 {
00195     if ( NULL == handle )
00196     {
00197         Reset();
00198         RevokeHandle();
00199     }
00200     else
00201     {
00202         m_pImpl->m_handle = handle;
00203     }
00204 }
00205 
00206 // Sets the C handle to NULL
00207 void FeatureContainer::RevokeHandle()
00208 {
00209     m_pImpl->m_handle = NULL;
00210 }
00211 
00212 // Sets the back reference to feature container that each feature holds to NULL
00213 // and resets all known features
00214 void FeatureContainer::Reset()
00215 {
00216     for (   FeaturePtrMap::iterator iter = m_pImpl->m_features.begin();
00217             m_pImpl->m_features.end() != iter;
00218             ++iter)
00219     {
00220         SP_ACCESS( iter->second )->ResetFeatureContainer();
00221     }
00222 
00223     m_pImpl->m_features.clear();
00224     m_pImpl->m_bAllFeaturesFetched = false;
00225 }
00226 
00227 }} // namespace AVT::VmbAPI


avt_vimba_camera
Author(s): Miquel Massot , Allied Vision Technologies
autogenerated on Thu Jun 6 2019 18:23:39