IntegerT.h
Go to the documentation of this file.
00001 //-----------------------------------------------------------------------------
00002 //  (c) 2006 by Basler Vision Technologies
00003 //  Section: Vision Components
00004 //  Project: GenApi
00005 //  Author:  Alexander Happe
00006 //  $Header$
00007 //
00008 //  License: This file is published under the license of the EMVA GenICam  Standard Group.
00009 //  A text file describing the legal terms is included in  your installation as 'GenICam_license.pdf'.
00010 //  If for some reason you are missing  this file please contact the EMVA or visit the website
00011 //  (http://www.genicam.org) for a full copy.
00012 //
00013 //  THIS SOFTWARE IS PROVIDED BY THE EMVA GENICAM STANDARD GROUP "AS IS"
00014 //  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
00015 //  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00016 //  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE EMVA GENICAM STANDARD  GROUP
00017 //  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,  SPECIAL,
00018 //  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT  LIMITED TO,
00019 //  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,  DATA, OR PROFITS;
00020 //  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY  THEORY OF LIABILITY,
00021 //  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE)
00022 //  ARISING IN ANY WAY OUT OF THE USE  OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00023 //  POSSIBILITY OF SUCH DAMAGE.
00024 //-----------------------------------------------------------------------------
00031 #ifndef GENAPI_INTEGERT_H
00032 #define GENAPI_INTEGERT_H
00033 
00034 #include "../Compatibility.h"
00035 #include "../IInteger.h"
00036 #include "Exception.h"
00037 #include <algorithm>
00038 #include "GenApi/impl/Log.h"
00039 #include "AutovectorImpl.h"
00040 
00041 
00042 namespace GENAPI_NAMESPACE
00043 {
00044 
00048     template <class Base>
00049     class IntegerT
00050         : public Base
00051     {
00052     public:
00053 
00055         IntegerT< Base >() :
00056             m_ImposedMax( GC_INT64_MAX ),
00057             m_ImposedMin( GC_INT64_MIN )
00058         {
00059         }
00060 
00062         virtual void SetValue(int64_t Value, bool Verify = true)
00063         {                        
00064             // a list of callbacks to fire held outside(!) the autolock on the stack(!)
00065             std::list<CNodeCallback*> CallbacksToFire;
00066             {
00067                 AutoLock l(Base::GetLock());
00068                 typename Base::EntryMethodFinalizer E( this, meSetValue );
00069 
00070                 Base::m_ValueCacheValid = false;
00071 
00072                 GCLOGINFOPUSH( Base::m_pValueLog, "SetValue( %" FMT_I64 "d )...", Value );
00073 
00074                 if( Verify )
00075                 {
00076                     if( !IsWritable( this ) )
00077                         throw ACCESS_EXCEPTION_NODE("Node is not writable.");
00078 
00079                     CHECK_RANGE_I64_NODE( Value, Base::InternalGetMin(), Base::InternalGetMax(), Base::InternalGetInc() );
00080                 }
00081 
00082                 {
00083                     typename Base::PostSetValueFinalizer PostSetValueCaller(this, CallbacksToFire);  // dtor calls Base::PostSetValue
00084 
00085                     // invalidates all nodes if this is the first call in a chain of SetValue calls
00086                     Base::PreSetValue();
00087 
00088                     // sets the value
00089                     Base::InternalSetValue(Value, Verify);
00090 
00091                     if( Verify )
00092                         Base::InternalCheckError();
00093 
00094                     #if ! defined( DISABLE_VALUE_CACHING ) || (DISABLE_VALUE_CACHING == 0)
00095                         // Fill cache
00096                         if( WriteThrough == static_cast<INode *>(this)->GetCachingMode() )
00097                         {
00098                             m_ValueCache = Value;
00099                             Base::m_ValueCacheValid = true;
00100                             Base::m_DontDeleteThisCache = true;
00101                         }
00102                     #endif
00103 
00104                 }
00105 
00106                 GCLOGINFOPOP( Base::m_pValueLog, "...SetValue" );
00107 
00108                 // fire callbacks inside the lock
00109                 std::list<CNodeCallback*>::iterator ptrCallback;
00110                 for( ptrCallback = CallbacksToFire.begin(); ptrCallback != CallbacksToFire.end(); ptrCallback++ )
00111                 {
00112                     (*ptrCallback)->operator ()(cbPostInsideLock);
00113                 }
00114             }
00115 
00116             // fire callbacks outside the lock
00117             std::list<CNodeCallback*>::iterator ptrCallback;
00118             for( ptrCallback = CallbacksToFire.begin(); ptrCallback != CallbacksToFire.end(); ptrCallback++ )
00119             {
00120                 (*ptrCallback)->operator ()(cbPostOutsideLock);
00121             }
00122 
00123         }
00124 
00126         virtual IInteger& operator=(int64_t Value)
00127         {
00128             SetValue(Value);
00129             return *this;
00130         }
00131 
00132         void InternalFromString(const GENICAM_NAMESPACE::gcstring& ValueStr, bool Verify = true)
00133         {
00134             int64_t Value;
00135             if (!String2Value(ValueStr, &Value, Base::InternalGetRepresentation()))
00136                 throw INVALID_ARGUMENT_EXCEPTION_NODE("Node '%s' : cannot convert string '%s' to int.", Base::m_Name.c_str(),  ValueStr.c_str() );
00137 
00138             SetValue(Value, Verify);
00139         }
00140 
00142         virtual int64_t GetValue(bool Verify = false, bool IgnoreCache = false )
00143         {
00144             AutoLock l(Base::GetLock());
00145             typename Base::EntryMethodFinalizer E( this, meGetValue, IgnoreCache );
00146 
00147             // Note that readability is tested regardless of Verify
00148             if( !IsReadable( this ) )
00149                 throw ACCESS_EXCEPTION_NODE("Node is not readable.");
00150 
00151             #if ! defined( DISABLE_VALUE_CACHING ) || (DISABLE_VALUE_CACHING == 0)
00152                 // Use cache
00153                 if ( !IgnoreCache && Base::m_ValueCacheValid && !Verify)
00154                 {
00155                     GCLOGINFO( Base::m_pValueLog, "GetValue = %" FMT_I64 "d  (from cache)", m_ValueCache );
00156                     return m_ValueCache;
00157                 }
00158             #endif
00159 
00160             GCLOGINFOPUSH( Base::m_pValueLog, "GetValue...");
00161 
00162             const int64_t Value( Base::InternalGetValue( Verify, IgnoreCache ) );
00163 
00164             if( Verify )
00165             {
00166                 CHECK_RANGE_I64_NODE( Value, Base::InternalGetMin(), Base::InternalGetMax(), Base::InternalGetInc() );
00167                 Base::InternalCheckError();
00168             }
00169 
00170             #if ! defined( DISABLE_VALUE_CACHING ) || (DISABLE_VALUE_CACHING == 0)
00171                 // Fill cache
00172                 const ECachingMode
00173                     CachingMode(static_cast<INode *>(this)->GetCachingMode());
00174                 if(    WriteThrough == CachingMode
00175                     || WriteAround  == CachingMode  )
00176                 {
00177                     m_ValueCache = Value;
00178                     Base::m_ValueCacheValid = true;
00179                 }
00180             #endif
00181 
00182             GCLOGINFOPOP( Base::m_pValueLog, "...GetValue = %" FMT_I64 "d", Value );
00183 
00184             return Value;
00185         }
00186 
00188         virtual int64_t operator()()
00189         {
00190             return GetValue();
00191         }
00192 
00194         virtual int64_t operator*()
00195         {
00196             return GetValue();
00197         }
00198 
00199         GENICAM_NAMESPACE::gcstring InternalToString(bool Verify = false, bool IgnoreCache = false)
00200         {
00201             int64_t Value = GetValue(Verify, IgnoreCache);
00202 
00203             GENICAM_NAMESPACE::gcstring ValueStr;
00204             Value2String(Value, ValueStr, Base::InternalGetRepresentation() );
00205 
00206             return ValueStr;
00207         }
00208 
00210         virtual int64_t GetMin()
00211         {
00212             AutoLock l(Base::GetLock());
00213             typename Base::EntryMethodFinalizer( this, meGetMin );
00214 
00215             GCLOGINFOPUSH( Base::m_pRangeLog, "GetMin...");
00216 
00217             int64_t Minimum = Base::InternalGetMin();
00218             Minimum = (std::max)(Minimum, m_ImposedMin);
00219 
00220             GCLOGINFOPOP( Base::m_pRangeLog, "...GetMin = %" FMT_I64 "d", Minimum );
00221 
00222             return Minimum;
00223 
00224         }
00225 
00227         virtual int64_t GetMax()
00228         {
00229             AutoLock l(Base::GetLock());
00230             typename Base::EntryMethodFinalizer( this, meGetMax );
00231 
00232             GCLOGINFOPUSH( Base::m_pRangeLog, "GetMax...");
00233 
00234             int64_t Maximum = Base::InternalGetMax();
00235             Maximum = (std::min)( Maximum, m_ImposedMax );
00236 
00237             GCLOGINFOPOP( Base::m_pRangeLog, "...GetMax = %" FMT_I64 "d", Maximum );
00238 
00239             return Maximum;
00240         }
00242         virtual EIncMode GetIncMode()
00243         {
00244             AutoLock l(Base::GetLock());
00245             typename Base::EntryMethodFinalizer( this, meGetIncMode );
00246 
00247             GCLOGINFOPUSH( Base::m_pRangeLog, "GetIncMode...");
00248 
00249             if( ! Base::m_ListOfValidValuesCacheValid )
00250             {
00251                m_CurentValidValueSet = Base::InternalGetListOfValidValues();
00252                Base::m_ListOfValidValuesCacheValid = true;
00253             }
00254 
00255             EIncMode mode( (m_CurentValidValueSet.size())? listIncrement: fixedIncrement  );
00256 
00257             GCLOGINFOPOP( Base::m_pRangeLog, "...GetIncMode");
00258             return mode;
00259         }
00260 
00262         virtual int64_t GetInc()
00263         {
00264             AutoLock l(Base::GetLock());
00265             typename Base::EntryMethodFinalizer( this, meGetInc );
00266 
00267             GCLOGINFOPUSH( Base::m_pRangeLog, "GetInc...");
00268 
00269             const int64_t Increment(Base::InternalGetInc());
00270 
00271             GCLOGINFOPOP( Base::m_pRangeLog, "...GetInc = %" FMT_I64 "d", Increment );
00272 
00273             return Increment;
00274         }
00276         virtual int64_autovector_t GetListOfValidValues(bool bounded = true)
00277         {
00278             AutoLock l(Base::GetLock());
00279             typename Base::EntryMethodFinalizer( this, meGetListOfValidValues );
00280             GCLOGINFOPUSH( Base::m_pRangeLog, "GetListOfValidValues...");
00281 
00282             if( ! Base::m_ListOfValidValuesCacheValid )
00283             {
00284                m_CurentValidValueSet = Base::InternalGetListOfValidValues();
00285                Base::m_ListOfValidValuesCacheValid = true;
00286             }
00287 
00288             int64_autovector_t list( bounded? m_CurentValidValueSet.duplicate( Base::InternalGetMin(), Base::InternalGetMax()) : m_CurentValidValueSet);
00289 
00290             GCLOGINFOPOP( Base::m_pRangeLog, "...GetListOfValidValues");
00291 
00292             return list;
00293 
00294         }
00295 
00296 
00298         virtual  ERepresentation GetRepresentation()
00299         {
00300             AutoLock l(Base::GetLock());
00301 
00302             return Base::InternalGetRepresentation();
00303         }
00304 
00306         virtual GENICAM_NAMESPACE::gcstring GetUnit()
00307         {
00308             AutoLock l(Base::GetLock());
00309             return Base::InternalGetUnit();
00310         }
00311 
00313         virtual void ImposeMin(int64_t Value)
00314         {
00315             m_ImposedMin = Value;
00316             Base::SetInvalid(INodePrivate::simAll);
00317         }
00318 
00320         virtual void ImposeMax(int64_t Value)
00321         {
00322             m_ImposedMax = Value;
00323             Base::SetInvalid(INodePrivate::simAll);
00324 
00325         }
00326 
00327         protected:
00329             int64_t m_ValueCache;
00330 
00332             int64_t m_ImposedMax;
00333 
00335             int64_t m_ImposedMin;
00336 
00338             int64_autovector_impl m_CurentValidValueSet;
00339 
00340     };
00341 
00342 } // namespace GenApi
00343 
00344 #endif


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:05