All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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, Base::IsStreamable());
69 
70  Base::m_ValueCacheValid = false;
71 
72  GCLOGINFOPUSH( Base::m_pValueLog, "SetValue( %" FMT_I64 "d )...", Value );
73 
74  if (!Base::CanBeWritten( Verify ))
75  {
76  throw ACCESS_EXCEPTION_NODE( "Node is not writable." );
77  }
78 
79  if (Verify || !Base::m_pNodeMap->EntryIsStremable())
80  {
81  CHECK_RANGE_I64_NODE( Value, Base::InternalGetMin(), Base::InternalGetMax(), Base::InternalGetInc() );
82  }
83 
84 
85  {
86  typename Base::PostSetValueFinalizer PostSetValueCaller(this, CallbacksToFire); // dtor calls Base::PostSetValue
87 
88  // invalidates all nodes if this is the first call in a chain of SetValue calls
89  Base::PreSetValue();
90 
91  // sets the value
92  Base::InternalSetValue(Value, Verify);
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  if (Verify)
107  Base::InternalCheckError();
108 
109  GCLOGINFOPOP( Base::m_pValueLog, "...SetValue" );
110 
111  // fire callbacks inside the lock
112  std::list<CNodeCallback*>::iterator ptrCallback;
113  for( ptrCallback = CallbacksToFire.begin(); ptrCallback != CallbacksToFire.end(); ptrCallback++ )
114  {
115  (*ptrCallback)->operator ()(cbPostInsideLock);
116  }
117  }
118 
119  // fire callbacks outside the lock
120  std::list<CNodeCallback*>::iterator ptrCallback;
121  for( ptrCallback = CallbacksToFire.begin(); ptrCallback != CallbacksToFire.end(); ptrCallback++ )
122  {
123  (*ptrCallback)->operator ()(cbPostOutsideLock);
124  }
125 
126  }
127 
129  virtual IInteger& operator=(int64_t Value)
130  {
131  SetValue(Value);
132  return *this;
133  }
134 
135  void InternalFromString(const GENICAM_NAMESPACE::gcstring& ValueStr, bool Verify = true)
136  {
137  int64_t Value;
138  if (!String2Value(ValueStr, &Value, Base::InternalGetRepresentation()))
139  throw INVALID_ARGUMENT_EXCEPTION_NODE("Node '%s' : cannot convert string '%s' to int.", Base::m_Name.c_str(), ValueStr.c_str() );
140 
141  SetValue(Value, Verify);
142  }
143 
145  virtual int64_t GetValue(bool Verify = false, bool IgnoreCache = false )
146  {
147  AutoLock l(Base::GetLock());
148  typename Base::EntryMethodFinalizer E(this, meGetValue, Base::IsStreamable(), IgnoreCache);
149 
150  // Note that readability is tested regardless of Verify
151  if( !IsReadable( this ) )
152  throw ACCESS_EXCEPTION_NODE("Node is not readable.");
153 
154  #if ! defined( DISABLE_VALUE_CACHING ) || (DISABLE_VALUE_CACHING == 0)
155  // Use cache
156  if ( !IgnoreCache && Base::m_ValueCacheValid && !Verify)
157  {
158  GCLOGINFO( Base::m_pValueLog, "GetValue = %" FMT_I64 "d (from cache)", m_ValueCache );
159  return m_ValueCache;
160  }
161  #endif
162 
163  GCLOGINFOPUSH( Base::m_pValueLog, "GetValue...");
164 
165  const int64_t Value( Base::InternalGetValue( Verify, IgnoreCache ) );
166 
167  if( Verify )
168  {
169  CHECK_RANGE_I64_NODE( Value, Base::InternalGetMin(), Base::InternalGetMax(), Base::InternalGetInc() );
170  Base::InternalCheckError();
171  }
172 
173  #if ! defined( DISABLE_VALUE_CACHING ) || (DISABLE_VALUE_CACHING == 0)
174  // Fill cache
175  const ECachingMode
176  CachingMode(static_cast<INode *>(this)->GetCachingMode());
177  if( WriteThrough == CachingMode
178  || WriteAround == CachingMode )
179  {
180  m_ValueCache = Value;
181  Base::m_ValueCacheValid = true;
182  }
183  #endif
184 
185  GCLOGINFOPOP( Base::m_pValueLog, "...GetValue = %" FMT_I64 "d", Value );
186 
187  return Value;
188  }
189 
191  virtual int64_t operator()()
192  {
193  return GetValue();
194  }
195 
197  virtual int64_t operator*()
198  {
199  return GetValue();
200  }
201 
202  GENICAM_NAMESPACE::gcstring InternalToString(bool Verify = false, bool IgnoreCache = false)
203  {
204  int64_t Value = GetValue(Verify, IgnoreCache);
205 
207  Value2String(Value, ValueStr, Base::InternalGetRepresentation() );
208 
209  return ValueStr;
210  }
211 
213  virtual int64_t GetMin()
214  {
215  AutoLock l(Base::GetLock());
216  typename Base::EntryMethodFinalizer( this, meGetMin );
217 
218  // only allowed for available nodes
219  if (!IsAvailable(this))
220  throw ACCESS_EXCEPTION_NODE("Node is not available.");
221 
222  GCLOGINFOPUSH( Base::m_pRangeLog, "GetMin...");
223 
224  int64_t Minimum = Base::InternalGetMin();
225  Minimum = (std::max)(Minimum, m_ImposedMin);
226 
227  GCLOGINFOPOP( Base::m_pRangeLog, "...GetMin = %" FMT_I64 "d", Minimum );
228 
229  return Minimum;
230 
231  }
232 
234  virtual int64_t GetMax()
235  {
236  AutoLock l(Base::GetLock());
237  typename Base::EntryMethodFinalizer( this, meGetMax );
238 
239  // only allowed for available nodes
240  if (!IsAvailable(this))
241  throw ACCESS_EXCEPTION_NODE("Node is not available.");
242 
243  GCLOGINFOPUSH( Base::m_pRangeLog, "GetMax...");
244 
245  int64_t Maximum = Base::InternalGetMax();
246  Maximum = (std::min)( Maximum, m_ImposedMax );
247 
248  GCLOGINFOPOP( Base::m_pRangeLog, "...GetMax = %" FMT_I64 "d", Maximum );
249 
250  return Maximum;
251  }
254  {
255  AutoLock l(Base::GetLock());
256  typename Base::EntryMethodFinalizer( this, meGetIncMode );
257 
258  GCLOGINFOPUSH( Base::m_pRangeLog, "GetIncMode...");
259 
260  if( ! Base::m_ListOfValidValuesCacheValid )
261  {
262  m_CurentValidValueSet = Base::InternalGetListOfValidValues();
263  Base::m_ListOfValidValuesCacheValid = true;
264  }
265 
267 
268  GCLOGINFOPOP( Base::m_pRangeLog, "...GetIncMode");
269  return mode;
270  }
271 
273  virtual int64_t GetInc()
274  {
275  AutoLock l(Base::GetLock());
276  typename Base::EntryMethodFinalizer( this, meGetInc );
277 
278  // only allowed for available nodes
279  if( !IsAvailable(this))
280  throw ACCESS_EXCEPTION_NODE("Node is not available.");
281 
282  GCLOGINFOPUSH( Base::m_pRangeLog, "GetInc...");
283 
284  const int64_t Increment(Base::InternalGetInc());
285 
286  GCLOGINFOPOP( Base::m_pRangeLog, "...GetInc = %" FMT_I64 "d", Increment );
287 
288  return Increment;
289  }
291  virtual int64_autovector_t GetListOfValidValues(bool bounded = true)
292  {
293  AutoLock l(Base::GetLock());
294  typename Base::EntryMethodFinalizer(this, meGetListOfValidValues, Base::IsStreamable());
295  GCLOGINFOPUSH( Base::m_pRangeLog, "GetListOfValidValues...");
296 
297  if( ! Base::m_ListOfValidValuesCacheValid )
298  {
299  m_CurentValidValueSet = Base::InternalGetListOfValidValues();
300  Base::m_ListOfValidValuesCacheValid = true;
301  }
302 
303  int64_autovector_t list( bounded? m_CurentValidValueSet.duplicate( Base::InternalGetMin(), Base::InternalGetMax()) : m_CurentValidValueSet);
304 
305  GCLOGINFOPOP( Base::m_pRangeLog, "...GetListOfValidValues");
306 
307  return list;
308 
309  }
310 
311 
314  {
315  AutoLock l(Base::GetLock());
316 
317  return Base::InternalGetRepresentation();
318  }
319 
322  {
323  AutoLock l(Base::GetLock());
324  return Base::InternalGetUnit();
325  }
326 
328  virtual void ImposeMin(int64_t Value)
329  {
330  m_ImposedMin = Value;
332  }
333 
335  virtual void ImposeMax(int64_t Value)
336  {
337  m_ImposedMax = Value;
339 
340  }
341 
342  protected:
345 
348 
351 
354 
355  };
356 
357 } // namespace GenApi
358 
359 #endif
GENAPI_NAMESPACE::IInteger
GENICAM_INTERFACE IInteger
Interface for integer properties.
Definition: IFloat.h:114
GENAPI_NAMESPACE
Lexical analyzer for CIntSwissKnife.
Definition: Destructible.h:30
GENAPI_NAMESPACE::meGetInc
@ meGetInc
Definition: Exception.h:50
GENAPI_NAMESPACE::meGetValue
@ meGetValue
Definition: Exception.h:46
GENAPI_NAMESPACE::cbPostOutsideLock
@ cbPostOutsideLock
callback is fired on leaving the tree inside the lock-guarded area
Definition: NodeCallback.h:48
GENAPI_NAMESPACE::IntegerT::GetIncMode
virtual EIncMode GetIncMode()
Implementation of IInteger::GetIncMode.
Definition: IntegerT.h:253
GC_INT64_MIN
#define GC_INT64_MIN
Definition: GCTypes.h:162
GENAPI_NAMESPACE::GetCachingMode
virtual ECachingMode GetCachingMode() const =0
Get Caching Mode.
GENAPI_NAMESPACE::IntegerT::GetUnit
virtual GENICAM_NAMESPACE::gcstring GetUnit()
Implementation of IInteger::GetUnit()
Definition: IntegerT.h:321
GENAPI_NAMESPACE::WriteThrough
@ WriteThrough
Write to cache and register.
Definition: Types.h:81
CHECK_RANGE_I64_NODE
#define CHECK_RANGE_I64_NODE(_Value, _Min, _Max, _Inc)
Range check for int64.
Definition: Exception.h:188
GENAPI_NAMESPACE::IntegerT::GetListOfValidValues
virtual int64_autovector_t GetListOfValidValues(bool bounded=true)
Implementation of IInteger::GetListOfValidValues.
Definition: IntegerT.h:291
GENICAM_NAMESPACE::gcstring
A string class which is a clone of std::string.
Definition: GCString.h:52
GENAPI_NAMESPACE::_autovector_impl::duplicate
const _autovector_impl duplicate(T min, T max)
Definition: AutovectorImpl.h:112
GENAPI_NAMESPACE::Value2String
void Value2String(T Value, GENICAM_NAMESPACE::gcstring &ValueStr)
Converts an T property to a string.
Definition: Value2String.h:62
GENAPI_NAMESPACE::meGetListOfValidValues
@ meGetListOfValidValues
Definition: Exception.h:58
GENAPI_NAMESPACE::IntegerT::operator=
virtual IInteger & operator=(int64_t Value)
Implementation of IInteger::operator=()
Definition: IntegerT.h:129
GENAPI_NAMESPACE::IntegerT::GetRepresentation
virtual ERepresentation GetRepresentation()
Implementation of IInteger::GetRepresentation.
Definition: IntegerT.h:313
GENAPI_NAMESPACE::GetLock
virtual CLock & GetLock() const =0
Returns the lock which guards the node map.
INVALID_ARGUMENT_EXCEPTION_NODE
#define INVALID_ARGUMENT_EXCEPTION_NODE
Fires an invalid argument exception, e.g. throw INVALID_ARGUMENT("%ld too large", Value);.
Definition: Exception.h:164
GENAPI_NAMESPACE::EIncMode
enum GENAPI_NAMESPACE::_EIncMode EIncMode
typedef for increment mode
GENAPI_NAMESPACE::EntryIsStremable
virtual bool EntryIsStremable()=0
GENAPI_NAMESPACE::ERepresentation
enum GENAPI_NAMESPACE::_ERepresentation ERepresentation
recommended representation of a node value
GENAPI_NAMESPACE::Verify
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT bool Verify
Definition: IBoolean.h:61
GCLOGINFOPOP
#define GCLOGINFOPOP(cat,...)
Definition: CLog.h:134
GENAPI_NAMESPACE::fixedIncrement
@ fixedIncrement
Definition: Types.h:224
Exception.h
GENAPI_NAMESPACE::IntegerT::operator*
virtual int64_t operator*()
Implementation of IInteger::operator*()
Definition: IntegerT.h:197
GC_INT64_MAX
#define GC_INT64_MAX
Definition: GCTypes.h:154
GENAPI_NAMESPACE::meGetIncMode
@ meGetIncMode
Definition: Exception.h:57
GENAPI_NAMESPACE::IntegerT::InternalToString
GENICAM_NAMESPACE::gcstring InternalToString(bool Verify=false, bool IgnoreCache=false)
Definition: IntegerT.h:202
GENAPI_NAMESPACE::_autovector_impl::size
size_t size() const
Definition: AutovectorImpl.h:124
GENAPI_NAMESPACE::IsAvailable
bool IsAvailable(EAccessMode AccessMode)
Tests if available.
Definition: INode.h:232
GENAPI_NAMESPACE::IntegerT::GetValue
virtual int64_t GetValue(bool Verify=false, bool IgnoreCache=false)
Implementation of IInteger::GetValue()
Definition: IntegerT.h:145
GENAPI_NAMESPACE::IntegerT::SetValue
virtual void SetValue(int64_t Value, bool Verify=true)
Implementation of IInteger::SetValue.
Definition: IntegerT.h:62
GENAPI_NAMESPACE::CanBeWritten
virtual bool CanBeWritten(bool Verify)=0
ACCESS_EXCEPTION_NODE
#define ACCESS_EXCEPTION_NODE
Fires a access error exception, e.g. throw ACCESS_ERROR_EXCEPTION("Not everybody")
Definition: Exception.h:179
GENAPI_NAMESPACE::IsReadable
bool IsReadable(EAccessMode AccessMode)
Tests if readable.
Definition: INode.h:178
GENAPI_NAMESPACE::IntegerT::m_ValueCache
int64_t m_ValueCache
The cache for the integer value.
Definition: IntegerT.h:344
GENAPI_NAMESPACE::AutoLock
Definition: Synch.h:139
GENAPI_NAMESPACE::IntegerT::ImposeMax
virtual void ImposeMax(int64_t Value)
Restrict maximum value.
Definition: IntegerT.h:335
GENAPI_NAMESPACE::INode
GENICAM_INTERFACE INode
Interface common to all nodes.
Definition: ICategory.h:51
GENAPI_NAMESPACE::IntegerT::m_CurentValidValueSet
int64_autovector_impl m_CurentValidValueSet
The cached list of valie value for the integer.
Definition: IntegerT.h:353
GENAPI_NAMESPACE::String2Value
bool String2Value(const GENICAM_NAMESPACE::gcstring &ValueStr, T *Value)
Converts a string to an T property.
Definition: Value2String.h:72
GENAPI_NAMESPACE::IntegerT::m_ImposedMin
int64_t m_ImposedMin
a Value imposed to the minimum
Definition: IntegerT.h:350
int64_t
__int64 int64_t
Definition: config-win32.h:21
GENAPI_NAMESPACE::listIncrement
@ listIncrement
Definition: Types.h:225
GENAPI_NAMESPACE::IsStreamable
virtual bool IsStreamable() const =0
True if the node is streamable.
GENICAM_NAMESPACE::gcstring::c_str
virtual const char * c_str(void) const
GENAPI_NAMESPACE::meSetValue
@ meSetValue
Definition: Exception.h:47
AutovectorImpl.h
This file contains the internal implementation of the autovector.
GENAPI_NAMESPACE::IntegerT::GetMin
virtual int64_t GetMin()
Implementation of IInteger::GetMin()
Definition: IntegerT.h:213
GENAPI_NAMESPACE::ECachingMode
enum GENAPI_NAMESPACE::_ECachingMode ECachingMode
caching mode of a register
GENAPI_NAMESPACE::IntegerT::ImposeMin
virtual void ImposeMin(int64_t Value)
Restrict minimum value.
Definition: IntegerT.h:328
GENAPI_NAMESPACE::simAll
@ simAll
Invalidate the node and all of its dependents.
Definition: INodePrivate.h:94
GENAPI_NAMESPACE::cbPostInsideLock
@ cbPostInsideLock
Definition: NodeCallback.h:47
GCLOGINFO
#define GCLOGINFO(cat,...)
Definition: CLog.h:129
GENAPI_NAMESPACE::IntegerT::InternalFromString
void InternalFromString(const GENICAM_NAMESPACE::gcstring &ValueStr, bool Verify=true)
Definition: IntegerT.h:135
GENAPI_NAMESPACE::WriteAround
@ WriteAround
Write to register, write to cache on read.
Definition: Types.h:82
GENAPI_NAMESPACE::int64_autovector_t
Vector of integers with reference counting.
Definition: Autovector.h:54
GENAPI_NAMESPACE::IntegerT::m_ImposedMax
int64_t m_ImposedMax
a Value imposed to the maximum
Definition: IntegerT.h:347
GENAPI_NAMESPACE::IntegerT::operator()
virtual int64_t operator()()
Implementation of IInteger::operator()()
Definition: IntegerT.h:191
GCLOGINFOPUSH
#define GCLOGINFOPUSH(cat,...)
Definition: CLog.h:130
FMT_I64
#define FMT_I64
Definition: GCCompatibility.h:35
GENAPI_NAMESPACE::meGetMin
@ meGetMin
Definition: Exception.h:48
GENAPI_NAMESPACE::SetInvalid
virtual void SetInvalid(ESetInvalidMode simMode)=0
Invalidate the node resp. the node and all of its dependents.
GENAPI_NAMESPACE::IntegerT
Implementation of the IInteger Interface.
Definition: IntegerT.h:49
GENAPI_NAMESPACE::IntegerT::GetInc
virtual int64_t GetInc()
Implementation of IInteger::GetInc()
Definition: IntegerT.h:273
GENAPI_NAMESPACE::_autovector_impl< int64_t, int64_autovector_t >
GENAPI_NAMESPACE::IntegerT::GetMax
virtual int64_t GetMax()
Implementation of IInteger::GetMax()
Definition: IntegerT.h:234
GENAPI_NAMESPACE::meGetMax
@ meGetMax
Definition: Exception.h:49


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Wed Dec 4 2024 03:10:11