IntegerT.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 // (c) 2006 by Basler Vision Technologies
3 // Section: Vision Components
4 // Project: GenApi
5 // Author: Alexander Happe
6 // $Header$
7 //
8 // License: This file is published under the license of the EMVA GenICam Standard Group.
9 // A text file describing the legal terms is included in your installation as 'GenICam_license.pdf'.
10 // If for some reason you are missing this file please contact the EMVA or visit the website
11 // (http://www.genicam.org) for a full copy.
12 //
13 // THIS SOFTWARE IS PROVIDED BY THE EMVA GENICAM STANDARD GROUP "AS IS"
14 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE EMVA GENICAM STANDARD GROUP
17 // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23 // POSSIBILITY OF SUCH DAMAGE.
24 //-----------------------------------------------------------------------------
31 #ifndef GENAPI_INTEGERT_H
32 #define GENAPI_INTEGERT_H
33 
34 #include "../Compatibility.h"
35 #include "../IInteger.h"
36 #include "Exception.h"
37 #include <algorithm>
38 #include "GenApi/impl/Log.h"
39 #include "AutovectorImpl.h"
40 
41 
42 namespace GENAPI_NAMESPACE
43 {
44 
48  template <class Base>
49  class IntegerT
50  : public Base
51  {
52  public:
53 
58  {
59  }
60 
62  virtual void SetValue(int64_t Value, bool Verify = true)
63  {
64  // a list of callbacks to fire held outside(!) the autolock on the stack(!)
65  std::list<CNodeCallback*> CallbacksToFire;
66  {
68  typename Base::EntryMethodFinalizer E( this, meSetValue );
69 
70  Base::m_ValueCacheValid = false;
71 
72  GCLOGINFOPUSH( Base::m_pValueLog, "SetValue( %" FMT_I64 "d )...", Value );
73 
74  if( Verify )
75  {
76  if( !IsWritable( this ) )
77  throw ACCESS_EXCEPTION_NODE("Node is not writable.");
78 
79  CHECK_RANGE_I64_NODE( Value, Base::InternalGetMin(), Base::InternalGetMax(), Base::InternalGetInc() );
80  }
81 
82  {
83  typename Base::PostSetValueFinalizer PostSetValueCaller(this, CallbacksToFire); // dtor calls Base::PostSetValue
84 
85  // invalidates all nodes if this is the first call in a chain of SetValue calls
86  Base::PreSetValue();
87 
88  // sets the value
89  Base::InternalSetValue(Value, Verify);
90 
91  if( Verify )
92  Base::InternalCheckError();
93 
94  #if ! defined( DISABLE_VALUE_CACHING ) || (DISABLE_VALUE_CACHING == 0)
95  // Fill cache
96  if( WriteThrough == static_cast<INode *>(this)->GetCachingMode() )
97  {
98  m_ValueCache = Value;
99  Base::m_ValueCacheValid = true;
100  Base::m_DontDeleteThisCache = true;
101  }
102  #endif
103 
104  }
105 
106  GCLOGINFOPOP( Base::m_pValueLog, "...SetValue" );
107 
108  // fire callbacks inside the lock
109  std::list<CNodeCallback*>::iterator ptrCallback;
110  for( ptrCallback = CallbacksToFire.begin(); ptrCallback != CallbacksToFire.end(); ptrCallback++ )
111  {
112  (*ptrCallback)->operator ()(cbPostInsideLock);
113  }
114  }
115 
116  // fire callbacks outside the lock
117  std::list<CNodeCallback*>::iterator ptrCallback;
118  for( ptrCallback = CallbacksToFire.begin(); ptrCallback != CallbacksToFire.end(); ptrCallback++ )
119  {
120  (*ptrCallback)->operator ()(cbPostOutsideLock);
121  }
122 
123  }
124 
126  virtual IInteger& operator=(int64_t Value)
127  {
128  SetValue(Value);
129  return *this;
130  }
131 
132  void InternalFromString(const GENICAM_NAMESPACE::gcstring& ValueStr, bool Verify = true)
133  {
134  int64_t Value;
135  if (!String2Value(ValueStr, &Value, Base::InternalGetRepresentation()))
136  throw INVALID_ARGUMENT_EXCEPTION_NODE("Node '%s' : cannot convert string '%s' to int.", Base::m_Name.c_str(), ValueStr.c_str() );
137 
138  SetValue(Value, Verify);
139  }
140 
142  virtual int64_t GetValue(bool Verify = false, bool IgnoreCache = false )
143  {
144  AutoLock l(Base::GetLock());
145  typename Base::EntryMethodFinalizer E( this, meGetValue, IgnoreCache );
146 
147  // Note that readability is tested regardless of Verify
148  if( !IsReadable( this ) )
149  throw ACCESS_EXCEPTION_NODE("Node is not readable.");
150 
151  #if ! defined( DISABLE_VALUE_CACHING ) || (DISABLE_VALUE_CACHING == 0)
152  // Use cache
153  if ( !IgnoreCache && Base::m_ValueCacheValid && !Verify)
154  {
155  GCLOGINFO( Base::m_pValueLog, "GetValue = %" FMT_I64 "d (from cache)", m_ValueCache );
156  return m_ValueCache;
157  }
158  #endif
159 
160  GCLOGINFOPUSH( Base::m_pValueLog, "GetValue...");
161 
162  const int64_t Value( Base::InternalGetValue( Verify, IgnoreCache ) );
163 
164  if( Verify )
165  {
166  CHECK_RANGE_I64_NODE( Value, Base::InternalGetMin(), Base::InternalGetMax(), Base::InternalGetInc() );
167  Base::InternalCheckError();
168  }
169 
170  #if ! defined( DISABLE_VALUE_CACHING ) || (DISABLE_VALUE_CACHING == 0)
171  // Fill cache
172  const ECachingMode
173  CachingMode(static_cast<INode *>(this)->GetCachingMode());
174  if( WriteThrough == CachingMode
175  || WriteAround == CachingMode )
176  {
177  m_ValueCache = Value;
178  Base::m_ValueCacheValid = true;
179  }
180  #endif
181 
182  GCLOGINFOPOP( Base::m_pValueLog, "...GetValue = %" FMT_I64 "d", Value );
183 
184  return Value;
185  }
186 
188  virtual int64_t operator()()
189  {
190  return GetValue();
191  }
192 
194  virtual int64_t operator*()
195  {
196  return GetValue();
197  }
198 
199  GENICAM_NAMESPACE::gcstring InternalToString(bool Verify = false, bool IgnoreCache = false)
200  {
201  int64_t Value = GetValue(Verify, IgnoreCache);
202 
204  Value2String(Value, ValueStr, Base::InternalGetRepresentation() );
205 
206  return ValueStr;
207  }
208 
210  virtual int64_t GetMin()
211  {
212  AutoLock l(Base::GetLock());
213  typename Base::EntryMethodFinalizer( this, meGetMin );
214 
215  // only allowed for available nodes
216  if (!IsAvailable(this))
217  throw ACCESS_EXCEPTION_NODE("Node is not available.");
218 
219  GCLOGINFOPUSH( Base::m_pRangeLog, "GetMin...");
220 
221  int64_t Minimum = Base::InternalGetMin();
222  Minimum = (std::max)(Minimum, m_ImposedMin);
223 
224  GCLOGINFOPOP( Base::m_pRangeLog, "...GetMin = %" FMT_I64 "d", Minimum );
225 
226  return Minimum;
227 
228  }
229 
231  virtual int64_t GetMax()
232  {
233  AutoLock l(Base::GetLock());
234  typename Base::EntryMethodFinalizer( this, meGetMax );
235 
236  // only allowed for available nodes
237  if (!IsAvailable(this))
238  throw ACCESS_EXCEPTION_NODE("Node is not available.");
239 
240  GCLOGINFOPUSH( Base::m_pRangeLog, "GetMax...");
241 
242  int64_t Maximum = Base::InternalGetMax();
243  Maximum = (std::min)( Maximum, m_ImposedMax );
244 
245  GCLOGINFOPOP( Base::m_pRangeLog, "...GetMax = %" FMT_I64 "d", Maximum );
246 
247  return Maximum;
248  }
251  {
252  AutoLock l(Base::GetLock());
253  typename Base::EntryMethodFinalizer( this, meGetIncMode );
254 
255  GCLOGINFOPUSH( Base::m_pRangeLog, "GetIncMode...");
256 
257  if( ! Base::m_ListOfValidValuesCacheValid )
258  {
259  m_CurentValidValueSet = Base::InternalGetListOfValidValues();
260  Base::m_ListOfValidValuesCacheValid = true;
261  }
262 
264 
265  GCLOGINFOPOP( Base::m_pRangeLog, "...GetIncMode");
266  return mode;
267  }
268 
270  virtual int64_t GetInc()
271  {
272  AutoLock l(Base::GetLock());
273  typename Base::EntryMethodFinalizer( this, meGetInc );
274 
275  // only allowed for available nodes
276  if( !IsAvailable(this))
277  throw ACCESS_EXCEPTION_NODE("Node is not available.");
278 
279  GCLOGINFOPUSH( Base::m_pRangeLog, "GetInc...");
280 
281  const int64_t Increment(Base::InternalGetInc());
282 
283  GCLOGINFOPOP( Base::m_pRangeLog, "...GetInc = %" FMT_I64 "d", Increment );
284 
285  return Increment;
286  }
288  virtual int64_autovector_t GetListOfValidValues(bool bounded = true)
289  {
290  AutoLock l(Base::GetLock());
291  typename Base::EntryMethodFinalizer( this, meGetListOfValidValues );
292  GCLOGINFOPUSH( Base::m_pRangeLog, "GetListOfValidValues...");
293 
294  if( ! Base::m_ListOfValidValuesCacheValid )
295  {
296  m_CurentValidValueSet = Base::InternalGetListOfValidValues();
297  Base::m_ListOfValidValuesCacheValid = true;
298  }
299 
300  int64_autovector_t list( bounded? m_CurentValidValueSet.duplicate( Base::InternalGetMin(), Base::InternalGetMax()) : m_CurentValidValueSet);
301 
302  GCLOGINFOPOP( Base::m_pRangeLog, "...GetListOfValidValues");
303 
304  return list;
305 
306  }
307 
308 
311  {
312  AutoLock l(Base::GetLock());
313 
314  return Base::InternalGetRepresentation();
315  }
316 
319  {
320  AutoLock l(Base::GetLock());
321  return Base::InternalGetUnit();
322  }
323 
325  virtual void ImposeMin(int64_t Value)
326  {
327  m_ImposedMin = Value;
329  }
330 
332  virtual void ImposeMax(int64_t Value)
333  {
334  m_ImposedMax = Value;
336 
337  }
338 
339  protected:
342 
345 
348 
351 
352  };
353 
354 } // namespace GenApi
355 
356 #endif
int64_t m_ImposedMax
a Value imposed to the maximum
Definition: IntegerT.h:344
const _autovector_impl duplicate(T min, T max)
#define GCLOGINFO(cat,...)
Definition: CLog.h:162
virtual int64_t GetInc()
Implementation of IInteger::GetInc()
Definition: IntegerT.h:270
virtual void ImposeMin(int64_t Value)
Restrict minimum value.
Definition: IntegerT.h:325
virtual int64_t GetMin()
Implementation of IInteger::GetMin()
Definition: IntegerT.h:210
virtual int64_t operator()()
Implementation of IInteger::operator()()
Definition: IntegerT.h:188
__int64 int64_t
Definition: config-win32.h:21
#define GC_INT64_MIN
Definition: GCTypes.h:162
GENICAM_NAMESPACE::gcstring InternalToString(bool Verify=false, bool IgnoreCache=false)
Definition: IntegerT.h:199
virtual int64_autovector_t GetListOfValidValues(bool bounded=true)
Implementation of IInteger::GetListOfValidValues.
Definition: IntegerT.h:288
virtual int64_t GetValue(bool Verify=false, bool IgnoreCache=false)
Implementation of IInteger::GetValue()
Definition: IntegerT.h:142
bool IsReadable(EAccessMode AccessMode)
Tests if readable.
Definition: INode.h:178
interface GENAPI_DECL_ABSTRACT IInteger
Interface for integer properties.
Definition: IInteger.h:61
virtual void ImposeMax(int64_t Value)
Restrict maximum value.
Definition: IntegerT.h:332
virtual EIncMode GetIncMode()
Implementation of IInteger::GetIncMode.
Definition: IntegerT.h:250
#define INVALID_ARGUMENT_EXCEPTION_NODE
Fires an invalid argument exception, e.g. throw INVALID_ARGUMENT("%ld too large", Value);...
Definition: Exception.h:157
virtual ERepresentation GetRepresentation()
Implementation of IInteger::GetRepresentation.
Definition: IntegerT.h:310
bool IsAvailable(EAccessMode AccessMode)
Tests if available.
Definition: INode.h:232
Write to cache and register.
Definition: Types.h:82
#define CHECK_RANGE_I64_NODE(_Value, _Min, _Max, _Inc)
Range check for int64.
Definition: Exception.h:181
enum GENAPI_NAMESPACE::_ERepresentation ERepresentation
recommended representation of a node value
int64_t m_ImposedMin
a Value imposed to the minimum
Definition: IntegerT.h:347
enum GENAPI_NAMESPACE::_ECachingMode ECachingMode
caching mode of a register
int64_autovector_impl m_CurentValidValueSet
The cached list of valie value for the integer.
Definition: IntegerT.h:350
Vector of integers with reference counting.
Definition: Autovector.h:54
virtual IInteger & operator=(int64_t Value)
Implementation of IInteger::operator=()
Definition: IntegerT.h:126
Write to register, write to cache on read.
Definition: Types.h:83
Implementation of the IInteger Interface.
Definition: IntegerT.h:49
#define ACCESS_EXCEPTION_NODE
Fires a access error exception, e.g. throw ACCESS_ERROR_EXCEPTION("Not everybody") ...
Definition: Exception.h:172
Invalidate the node and all of its dependents.
Definition: INodePrivate.h:94
virtual int64_t operator*()
Implementation of IInteger::operator*()
Definition: IntegerT.h:194
interface GENAPI_DECL_ABSTRACT bool Verify
Definition: IBoolean.h:61
#define GCLOGINFOPUSH(cat,...)
Definition: CLog.h:163
#define GC_INT64_MAX
Definition: GCTypes.h:154
virtual void SetValue(int64_t Value, bool Verify=true)
Implementation of IInteger::SetValue.
Definition: IntegerT.h:62
This file contains the internal implementation of the autovector.
virtual int64_t GetMax()
Implementation of IInteger::GetMax()
Definition: IntegerT.h:231
A string class which is a clone of std::string.
Definition: GCString.h:52
virtual GENICAM_NAMESPACE::gcstring GetUnit()
Implementation of IInteger::GetUnit()
Definition: IntegerT.h:318
int64_t m_ValueCache
The cache for the integer value.
Definition: IntegerT.h:341
virtual ECachingMode GetCachingMode() const =0
Get Caching Mode.
bool IsWritable(EAccessMode AccessMode)
Tests if writable.
Definition: INode.h:196
virtual void SetInvalid(ESetInvalidMode simMode)=0
Invalidate the node resp. the node and all of its dependents.
enum GENAPI_NAMESPACE::_EIncMode EIncMode
typedef for increment mode
#define GCLOGINFOPOP(cat,...)
Definition: CLog.h:164
#define FMT_I64
Definition: Compatibility.h:68
virtual const char * c_str(void) const
void Value2String(T Value, GENICAM_NAMESPACE::gcstring &ValueStr)
Converts an T property to a string.
Definition: Value2String.h:62
Part of the generic device API.
Definition: Autovector.h:48
callback is fired on leaving the tree inside the lock-guarded area
Definition: NodeCallback.h:48
void InternalFromString(const GENICAM_NAMESPACE::gcstring &ValueStr, bool Verify=true)
Definition: IntegerT.h:132
virtual CLock & GetLock() const =0
Returns the lock which guards the node map.
bool String2Value(const GENICAM_NAMESPACE::gcstring &ValueStr, T *Value)
Converts a string to an T property.
Definition: Value2String.h:72


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Thu Jun 6 2019 19:10:54