GenApi  3.5.1
IEnumerationT.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 // (c) 2006 by Basler Vision Technologies
3 // Author: Fritz Dierks
4 //
5 // License: This file is published under the license of the EMVA GenICam Standard Group.
6 // A text file describing the legal terms is included in your installation as 'GenICam_license.pdf'.
7 // If for some reason you are missing this file please contact the EMVA or visit the website
8 // (http://www.genicam.org) for a full copy.
9 //
10 // THIS SOFTWARE IS PROVIDED BY THE EMVA GENICAM STANDARD GROUP "AS IS"
11 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
12 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
13 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE EMVA GENICAM STANDARD GROUP
14 // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
15 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
16 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
17 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
18 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
19 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
20 // POSSIBILITY OF SUCH DAMAGE.
21 //
22 //-----------------------------------------------------------------------------
29 #ifndef GENAPI_IENUMERATIONT_H
30 #define GENAPI_IENUMERATIONT_H
31 
32 #include <GenApi/GenApiDll.h>
33 #include <GenApi/Types.h>
34 #include <GenApi/Pointer.h>
35 #include <GenApi/IEnumeration.h>
36 #include <GenApi/Compatibility.h>
37 #include <vector>
38 
39 namespace GENAPI_NAMESPACE
40 {
41  //*************************************************************
42  // Enumeration template interface
43  //*************************************************************
44 
49  template< typename EnumT >
50  GENICAM_INTERFACE IEnumerationT : public IEnumeration
51  {
53 
57  virtual void SetValue(EnumT Value, bool Verify = true) = 0;
58 
60  virtual IEnumeration& operator=(EnumT Value) = 0;
61 
63 
68  virtual EnumT GetValue(bool Verify = false, bool IgnoreCache = false) = 0;
69 
71  virtual EnumT operator()() = 0;
72 
74 
76  virtual IEnumeration& operator=(const GENICAM_NAMESPACE::gcstring& ValueStr) = 0;
77 
79  virtual IEnumEntry *GetEntry(const EnumT Value) = 0;
80 
82  virtual IEnumEntry *GetCurrentEntry(bool Verify = false, bool IgnoreCache = false) = 0;
83 
84  };
85 
86  //*************************************************************
87  // CEnumerationTRef class
88  //*************************************************************
89 
90 #ifndef DOXYGEN_IGNORE
91 
97  template< class EnumT >
98  class CEnumerationTRef : public IEnumerationT< EnumT >, public IReference, public IEnumReference
99  {
100  public:
101  // Constructor
102  CEnumerationTRef() :
103  m_Ptr(NULL)
104  {}
105 
106  /*--------------------------------------------------------*/
107  // IReference
108  /*--------------------------------------------------------*/
109 
111  virtual void SetReference( IBase *ptr )
112  {
113  m_Ptr = dynamic_cast< IEnumeration *>( ptr );
114  }
115 
116  /*--------------------------------------------------------*/
117  // IEnumReference
118  /*--------------------------------------------------------*/
119 
121  virtual void SetNumEnums( int NumEnums )
122  {
123  m_EnumExists.resize(NumEnums);
124  m_EnumValues.resize(NumEnums);
125 
126  std::vector<bool>::iterator ptr;
127  for(ptr = m_EnumExists.begin(); ptr != m_EnumExists.end(); ptr++)
128  *ptr = false;
129 
130  }
131 
133  virtual void SetEnumReference( int Index, GENICAM_NAMESPACE::gcstring Name)
134  {
135  if ( m_Ptr )
136  {
137  CEnumEntryPtr ptrEnumEntry = GetEntryByName(Name);
138 
139  if( ptrEnumEntry.IsValid() )
140  {
141  m_EnumExists[Index] = true;
142  m_EnumValues[Index] = ptrEnumEntry->GetValue();
143  }
144  }
145  }
146 
147 
148  /*--------------------------------------------------------*/
149  // IBase
150  /*--------------------------------------------------------*/
151 
153  virtual EAccessMode GetAccessMode() const
154  {
155  if(m_Ptr)
156  return m_Ptr->GetAccessMode();
157  else
158  return NI;
159  }
160 
161  /*--------------------------------------------------------*/
162  // IValue
163  /*--------------------------------------------------------*/
164 
166  virtual INode* GetNode()
167  {
168  if(m_Ptr)
169  return m_Ptr->GetNode();
170  else
171  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
172  }
173 
175  virtual GENICAM_NAMESPACE::gcstring ToString(bool Verify = false, bool IgnoreCache = false)
176  {
177  if(m_Ptr)
178  return m_Ptr->ToString(Verify, IgnoreCache);
179  else
180  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
181  }
182 
184  virtual void FromString(const GENICAM_NAMESPACE::gcstring& ValueStr, bool Verify = true)
185  {
186  if(m_Ptr)
187  return m_Ptr->FromString(ValueStr, Verify);
188  else
189  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
190  }
191 
193  bool IsValueCacheValid() const
194  {
195  if(m_Ptr)
196  return m_Ptr->IsValueCacheValid();
197  else
198  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
199  }
200 
201  /*--------------------------------------------------------*/
202  // IEnumeration
203  /*--------------------------------------------------------*/
204 
206  virtual void GetSymbolics(StringList_t & Symbolics)
207  {
208  if(m_Ptr)
209  return m_Ptr->GetSymbolics(Symbolics);
210  else
211  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
212  }
213 
215  virtual void GetEntries(NodeList_t & Entries)
216  {
217  if(m_Ptr)
218  return m_Ptr->GetEntries(Entries);
219  else
220  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
221  }
222 
224  virtual IEnumeration& operator=(const GENICAM_NAMESPACE::gcstring& ValueStr)
225  {
226  if(m_Ptr)
227  return m_Ptr->operator=(ValueStr);
228  else
229  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
230  }
231 
233  virtual IEnumeration& operator=(const char *pValueStr)
234  {
235  if(m_Ptr)
236  return m_Ptr->operator=(pValueStr);
237  else
238  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
239  }
240 
242  virtual void SetIntValue(int64_t Value, bool Verify = true)
243  {
244  if(m_Ptr)
245  m_Ptr->SetIntValue(Value, Verify);
246  else
247  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
248  }
249 
252  {
253  if(m_Ptr)
254  return m_Ptr->operator*();
255  else
256  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
257  }
258 
260  virtual int64_t GetIntValue(bool Verify = false, bool IgnoreCache = false)
261  {
262  if(m_Ptr)
263  return m_Ptr->GetIntValue(Verify, IgnoreCache);
264  else
265  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
266  }
267 
269  virtual IEnumEntry *GetEntryByName(const GENICAM_NAMESPACE::gcstring& Symbolic)
270  {
271  if(m_Ptr)
272  return m_Ptr->GetEntryByName(Symbolic);
273  else
274  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
275  }
276 
277 
279  virtual IEnumEntry *GetEntry(const int64_t IntValue)
280  {
281  if(m_Ptr)
282  return m_Ptr->GetEntry(IntValue);
283  else
284  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
285  }
286 
288  virtual IEnumEntry *GetCurrentEntry(bool Verify = false, bool IgnoreCache = false)
289  {
290  if(m_Ptr)
291  return m_Ptr->GetCurrentEntry(Verify, IgnoreCache);
292  else
293  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
294  }
295 
296  /*--------------------------------------------------------*/
297  // IEnumerationT
298  /*--------------------------------------------------------*/
299 
301  virtual void SetValue(EnumT Value, bool Verify = true)
302  {
303  if(m_Ptr)
304  {
305  if( m_EnumExists[Value] )
306  {
307  int64_t EnumValue = m_EnumValues[Value];
308  m_Ptr->SetIntValue(EnumValue, Verify);
309  }
310  else
311  throw ACCESS_EXCEPTION("EnumEntry %d not present", Value);
312  }
313  else
314  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
315  }
316 
318  virtual IEnumeration& operator=(EnumT Value)
319  {
320  SetValue(Value);
321  return *this;
322  }
323 
325  virtual EnumT GetValue(bool Verify = false, bool IgnoreCache = false)
326  {
327  if(m_Ptr)
328  {
329  int64_t IntValue = m_Ptr->GetIntValue(Verify, IgnoreCache);
330  std::vector<int64_t>::iterator ptr;
331  for ( unsigned int idx = 0; idx < m_EnumValues.size(); ++idx )
332  {
333  if( m_EnumExists[idx] && m_EnumValues[idx] == IntValue)
334  return (EnumT) idx;
335  }
336  throw ACCESS_EXCEPTION("Unknown IntValue %" FMT_I64 "d", IntValue);
337  }
338  else
339  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
340  }
341 
343  virtual EnumT operator()()
344  {
345  return GetValue();
346  }
347 
349  virtual IEnumEntry *GetEntry(const EnumT Value)
350  {
351  if(m_Ptr)
352  {
353  if( m_EnumExists[Value] )
354  {
355  int64_t EnumValue = m_EnumValues[Value];
356  return m_Ptr->GetEntry(EnumValue);
357  }
358  else
359  return NULL;
360  }
361  else
362  throw ACCESS_EXCEPTION("Feature not present (reference not valid)");
363  }
364 
365  protected:
367  IEnumeration *m_Ptr;
368 
370  std::vector<int64_t > m_EnumValues;
371 
373  std::vector<bool > m_EnumExists;
374 
375  };
376 
377 #endif
378 
379 }
380 
381 #endif // ifndef GENAPI_IENUMERATIONT_H
virtual void SetNumEnums(int NumEnums)=0
sets the number of enum vallues
virtual int64_t GetIntValue(bool Verify=false, bool IgnoreCache=false)=0
Get integer node value.
Common types used in the public GenApi interface.
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IReference
Interface to construct a reference.
Definition: Reference.h:48
bool IsValid() const
true if the pointer is valid
Definition: Pointer.h:109
GENICAM_NAMESPACE::gcstring_vector StringList_t
Definition: Types.h:147
virtual void GetEntries(NodeList_t &Entries)=0
Get list of entry nodes.
virtual bool operator()() const
Get node value.
Definition: IBoolean.h:77
GENICAM_INTERFACE INode
Interface common to all nodes.
Definition: ICategory.h:49
GENICAM_INTERFACE IEnumerationT
Interface for enumeration properties.
Definition: IEnumerationT.h:57
virtual void FromString(const GENICAM_NAMESPACE::gcstring &ValueStr, bool Verify=true)=0
Set content of the node as string.
node_vector NodeList_t
a list of node references
Definition: INode.h:53
virtual GENICAM_NAMESPACE::gcstring operator*()=0
Get string node value.
enum GENAPI_NAMESPACE::_EAccessMode EAccessMode
virtual IBoolean & operator=(bool Value)
Set node value.
Definition: IBoolean.h:62
Encapsulates a GenApi pointer dealing with the dynamic_cast automatically.
Definition: Pointer.h:49
virtual IEnumEntry * GetEntryByName(const GENICAM_NAMESPACE::gcstring &Symbolic)=0
Get an entry node by name.
#define ACCESS_EXCEPTION
Fires a access exception, e.g. throw ACCESS_EXCEPTION("Not everybody")
Definition: GCException.h:252
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IEnumReference
Interface to construct an enum reference.
Definition: Reference.h:62
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IBase
Base interface common to all nodes.
Definition: IBase.h:53
virtual void SetIntValue(int64_t Value, bool Verify=true)=0
Set integer node value.
virtual IEnumEntry * GetCurrentEntry(bool Verify=false, bool IgnoreCache=false)=0
Get the current entry.
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IEnumeration
Interface for enumeration properties.
Definition: IEnumeration.h:58
virtual bool IsValueCacheValid() const =0
Checks if the value comes from cache or is requested from another node.
Definition of template CPointer.
A string class which is a clone of std::string.
Definition: GCString.h:50
virtual IEnumEntry * GetEntry(const int64_t IntValue)=0
Get an entry node by its IntValue.
virtual bool GetValue(bool Verify=false, bool IgnoreCache=false) const =0
Get node value.
declspec&#39;s to be used for GenApi Windows dll
Definition of interface IEnumeration.
Not implemented.
Definition: Types.h:54
Definition: ChunkAdapter.h:37
virtual INode * GetNode(const GENICAM_NAMESPACE::gcstring &Name) const =0
Retrieves the node from the central map by Name.
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IEnumEntry
Interface of single enum value.
Definition: IEnumEntry.h:58