00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
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);
00084
00085
00086 Base::PreSetValue();
00087
00088
00089 Base::InternalSetValue(Value, Verify);
00090
00091 if( Verify )
00092 Base::InternalCheckError();
00093
00094 #if ! defined( DISABLE_VALUE_CACHING ) || (DISABLE_VALUE_CACHING == 0)
00095
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
00109 std::list<CNodeCallback*>::iterator ptrCallback;
00110 for( ptrCallback = CallbacksToFire.begin(); ptrCallback != CallbacksToFire.end(); ptrCallback++ )
00111 {
00112 (*ptrCallback)->operator ()(cbPostInsideLock);
00113 }
00114 }
00115
00116
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
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
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
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
00216 if (!IsAvailable(this))
00217 throw ACCESS_EXCEPTION_NODE("Node is not available.");
00218
00219 GCLOGINFOPUSH( Base::m_pRangeLog, "GetMin...");
00220
00221 int64_t Minimum = Base::InternalGetMin();
00222 Minimum = (std::max)(Minimum, m_ImposedMin);
00223
00224 GCLOGINFOPOP( Base::m_pRangeLog, "...GetMin = %" FMT_I64 "d", Minimum );
00225
00226 return Minimum;
00227
00228 }
00229
00231 virtual int64_t GetMax()
00232 {
00233 AutoLock l(Base::GetLock());
00234 typename Base::EntryMethodFinalizer( this, meGetMax );
00235
00236
00237 if (!IsAvailable(this))
00238 throw ACCESS_EXCEPTION_NODE("Node is not available.");
00239
00240 GCLOGINFOPUSH( Base::m_pRangeLog, "GetMax...");
00241
00242 int64_t Maximum = Base::InternalGetMax();
00243 Maximum = (std::min)( Maximum, m_ImposedMax );
00244
00245 GCLOGINFOPOP( Base::m_pRangeLog, "...GetMax = %" FMT_I64 "d", Maximum );
00246
00247 return Maximum;
00248 }
00250 virtual EIncMode GetIncMode()
00251 {
00252 AutoLock l(Base::GetLock());
00253 typename Base::EntryMethodFinalizer( this, meGetIncMode );
00254
00255 GCLOGINFOPUSH( Base::m_pRangeLog, "GetIncMode...");
00256
00257 if( ! Base::m_ListOfValidValuesCacheValid )
00258 {
00259 m_CurentValidValueSet = Base::InternalGetListOfValidValues();
00260 Base::m_ListOfValidValuesCacheValid = true;
00261 }
00262
00263 EIncMode mode( (m_CurentValidValueSet.size())? listIncrement: fixedIncrement );
00264
00265 GCLOGINFOPOP( Base::m_pRangeLog, "...GetIncMode");
00266 return mode;
00267 }
00268
00270 virtual int64_t GetInc()
00271 {
00272 AutoLock l(Base::GetLock());
00273 typename Base::EntryMethodFinalizer( this, meGetInc );
00274
00275
00276 if( !IsAvailable(this))
00277 throw ACCESS_EXCEPTION_NODE("Node is not available.");
00278
00279 GCLOGINFOPUSH( Base::m_pRangeLog, "GetInc...");
00280
00281 const int64_t Increment(Base::InternalGetInc());
00282
00283 GCLOGINFOPOP( Base::m_pRangeLog, "...GetInc = %" FMT_I64 "d", Increment );
00284
00285 return Increment;
00286 }
00288 virtual int64_autovector_t GetListOfValidValues(bool bounded = true)
00289 {
00290 AutoLock l(Base::GetLock());
00291 typename Base::EntryMethodFinalizer( this, meGetListOfValidValues );
00292 GCLOGINFOPUSH( Base::m_pRangeLog, "GetListOfValidValues...");
00293
00294 if( ! Base::m_ListOfValidValuesCacheValid )
00295 {
00296 m_CurentValidValueSet = Base::InternalGetListOfValidValues();
00297 Base::m_ListOfValidValuesCacheValid = true;
00298 }
00299
00300 int64_autovector_t list( bounded? m_CurentValidValueSet.duplicate( Base::InternalGetMin(), Base::InternalGetMax()) : m_CurentValidValueSet);
00301
00302 GCLOGINFOPOP( Base::m_pRangeLog, "...GetListOfValidValues");
00303
00304 return list;
00305
00306 }
00307
00308
00310 virtual ERepresentation GetRepresentation()
00311 {
00312 AutoLock l(Base::GetLock());
00313
00314 return Base::InternalGetRepresentation();
00315 }
00316
00318 virtual GENICAM_NAMESPACE::gcstring GetUnit()
00319 {
00320 AutoLock l(Base::GetLock());
00321 return Base::InternalGetUnit();
00322 }
00323
00325 virtual void ImposeMin(int64_t Value)
00326 {
00327 m_ImposedMin = Value;
00328 Base::SetInvalid(INodePrivate::simAll);
00329 }
00330
00332 virtual void ImposeMax(int64_t Value)
00333 {
00334 m_ImposedMax = Value;
00335 Base::SetInvalid(INodePrivate::simAll);
00336
00337 }
00338
00339 protected:
00341 int64_t m_ValueCache;
00342
00344 int64_t m_ImposedMax;
00345
00347 int64_t m_ImposedMin;
00348
00350 int64_autovector_impl m_CurentValidValueSet;
00351
00352 };
00353
00354 }
00355
00356 #endif